【问题标题】:PineScript / Trading View: How to check for openorders in strategyPine Script / Tradingview:如何在策略中检查未结订单
【发布时间】:2020-07-07 06:25:16
【问题描述】:
pma = sma(maSource, periods)
entryLong = close * 1.10
longCondition = close >= pma

if longCondition
   strategy.entry(id = "Long Entry", long = true, stop = entryLong)

有几个条可以连续满足这个longCondition,但我不希望后面的条覆盖前面的条。理想情况下,我想添加一个检查是否 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")

感谢您的建议!

【问题讨论】:

    标签: pine-script


    【解决方案1】:

    您可以检查上一个柱的条件是否为真,而忽略当前柱。所以连续出现的将被忽略。

    pma = sma(close, 10)
    entryLong = close * 1.10
    longCondition = close >= pma
    long = longCondition and not nz(longCondition[1])
    
    // debug
    bgcolor(longCondition ? color.green : na)
    bgcolor(long ? color.blue : na)
    

    您也可以使用内置的 strategy.position_size 函数。

    strategy.position_size > 0  // long is opened.
    strategy.position_size < 0  // short is opened.
    strategy.position_size == 0  // no opened positions
    

    【讨论】:

      猜你喜欢
      • 2020-01-28
      • 2021-09-22
      • 1970-01-01
      • 2022-11-30
      • 1970-01-01
      • 1970-01-01
      • 2019-01-16
      • 2023-02-06
      • 2018-08-19
      相关资源
      最近更新 更多