pine-script - 如何根据条件为真触发标签,但仅触发一次
问题描述
我是 Pine 脚本的新手,所以请耐心等待。我试图弄清楚当“多头”条件变为真时如何绘制买入标签,但只是第一次而不是每个柱条件都为真。所以基本上,“strategy.entry”和“strategy.close”打开和关闭单个头寸的方式相同。
if (longConditions)
strategy.entry("Long", true)
longLabel = label.new(
x=bar_index,
y=na,
text="Long",
xloc=xloc.bar_index,
yloc=yloc.belowbar,
color=color.green,
textcolor=color.white,
style=label.style_label_up,
size=size.normal)
if (closeLongConditions)
strategy.close("Long")
closeLongLabel = label.new(
x=bar_index,
y=na,
text="Close",
xloc=xloc.bar_index,
yloc=yloc.abovebar,
color=color.red,
textcolor=color.white,
style=label.style_label_down,
size=size.normal)
有没有办法让“strategy.entry”和“strategy.close”触发标签而不是我的“long”和“close”条件?
解决方案
这是解决方法
if (longConditions and strategy.position_size < 0)
strategy.entry("Long", true)
longLabel = label.new(
x=bar_index,
y=na,
text="Long",
xloc=xloc.bar_index,
yloc=yloc.belowbar,
color=color.green,
textcolor=color.white,
style=label.style_label_up,
size=size.normal)
if (closeLongConditions and strategy.position_size>0)
strategy.close("Long")
closeLongLabel = label.new(
x=bar_index,
y=na,
text="Close",
xloc=xloc.bar_index,
yloc=yloc.abovebar,
color=color.red,
textcolor=color.white,
style=label.style_label_down,
size=size.normal)
推荐阅读
- android - Gradle 构建失败,未找到 keystore.properties
- alexa - 如何获取 Alexa 技能的插槽值的数量(长度)
- h3 - 六边形内的相关 hexids
- mysql - 我正在尝试使用外键约束连接两个表
- python - os.path.exists 返回不正确的结果
- c# - FluentValidator 扩展方法来检查实体是否存在于数据库中
- android - 没有互联网时如何显示警报对话框?
- objective-c - macos10.15beta 上是否修改了 SecKeyRawSign/SecKeyRawVerify API 实现?
- android - 父活动工具栏隐藏在子片段中
- pyqt5 - 如何用鼠标点击父窗口的Qtablewidget中的某个单元格获取值,然后填充到子窗口的QlineEdit中?