简体   繁体   English

PineScript / 交易视图:如何在策略中检查未结订单

[英]PineScript / Trading View: How to check for openorders in strategy

pma = sma(maSource, periods)
entryLong = close * 1.10
longCondition = close >= pma

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

Several bars can meet this longCondition in a row, but I don't want subsequent bars to over-write the previous ones.有几个条可以连续满足这个longCondition,但我不希望后面的条覆盖前面的条。 Ideally I'd like to add a check to see if strategy.openentries == 0, but of course such a variable doesn't exist in Tradingview.理想情况下,我想添加一个检查以查看 strategy.openentries == 0,但在 Tradingview 中当然不存在这样的变量。

Would like to do something like this:想做这样的事情:

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")

Thanks for any advice!感谢您的任何建议!

You can check if the condition was true on previous bar and ignore the current one.您可以检查上一个柱上的条件是否为真并忽略当前柱。 So the consecutive occurrences would be ignored.因此,连续出现的事件将被忽略。

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)

You can also use the built-in strategy.position_size function.您也可以使用内置的 strategy.position_size function。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM