[英]Pinescript multiple strategy.exit for one entry
I try to create two different strategy.exit function for one entry(one of them is for limit, other one is for stop).我尝试为一个条目创建两个不同的 strategy.exit function(其中一个用于限制,另一个用于停止)。 Because I want to take different comments from these two exit function.因为我想从这两个出口 function 获得不同的意见。
Related code snippet:相关代码片段:
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)
But strategy tester neglect second one.但是策略测试员忽略了第二个。 So how can I get two different comments without using strategy.order in if block?那么如何在 if 块中不使用 strategy.order 来获得两个不同的评论呢?
You should give it unique id's otherwise you will modify
and not create
a new one.你应该给它唯一的 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}exit https://www.tradingview.com/pine-script-reference/v5/#fun_strategy{dot}退出
Use logical or
.使用逻辑or
。 Applicable to boolean expressions.适用于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.