我是松树脚本的新手。我想比较 2 个特定日期的价格。
但是我如何获得特定日期的 bar_index 呢?
提前致谢
pma = sma(maSource, periods)
entryLong = close * 1.10
longCondition = close >= pma
if longCondition
strategy.entry(id = "Long Entry", long = true, stop = entryLong)
Run Code Online (Sandbox Code Playgroud)
多个柱可以连续满足这个 long 条件,但我不希望后续柱覆盖前面的柱。理想情况下,我想添加一个检查来查看是否strategy.openentries == 0,但当然这样的变量在Tradingview中不存在。
想做这样的事情:
pma = sma(maSource, periods)
entryLong = close * 1.10
longCondition = close >= pma
if longCondition and strategy.openorders == 0
strategy.entry(id = "Long Entry", long = true, stop = entryLong)
if barssince(longCondition) = 3
strategy.cancel(id = "Long Entry")
Run Code Online (Sandbox Code Playgroud)