繁体   English   中英

Pinescript 多策略. 一次退出

[英]Pinescript multiple strategy.exit for one entry

我尝试为一个条目创建两个不同的 strategy.exit function(其中一个用于限制,另一个用于停止)。 因为我想从这两个出口 function 获得不同的意见。

相关代码片段:

strategy.entry("Longi" , direction = strategy.long, limit = close + 5)
strategy.exit("LongKapa" , from_entry = "Longi" , limit = xxx)
strategy.exit("LongKapa" , from_entry = "Longi" , stop = xxx)

但是策略测试员忽略了第二个。 那么如何在 if 块中不使用 strategy.order 来获得两个不同的评论呢?

你应该给它唯一的 id,否则你将modify而不是create一个新的。

strategy.entry("Longi" , direction = strategy.long, limit = close + 5, qty=2)
strategy.exit("LongKapa-1" , from_entry = "Longi" , limit = xxx, qty=1)
strategy.exit("LongKapa-2" , from_entry = "Longi" , stop = xxx, qty=1)

https://www.tradingview.com/pine-script-reference/v5/#fun_strategy{dot}退出

使用逻辑or 适用于boolean个表达式。

longCondition = ta.crossunder(ta.sma(close, 20), ta.sma(close, 50))
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)


exitCondition = ta.crossunder(ta.sma(close, 10), ta.sma(close, 20)) or ta.crossunder(ta.sma(close, 10), ta.sma(close, 50))
if (exitCondition)
    strategy.exit("exit", "My Long Entry Id", profit = 10, loss = 5)

暂无
暂无

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

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