![](/img/trans.png)
[英]Tradingview Strategy : can i use SL/TP and Trailing in one code?
[英]How Can I Set SL and TP?
我有入场策略,我的止损在蜡烛之前很低。 我的 tp 是根据止损设置的 R/R 3。
我写了代码,但它不起作用。
strategy.entry("Long Position",strategy.long,when = LongEntry)
strategy.exit("Exit Long" , from_entry = "Long Position" , stop = low[1] , profit = 3*low[1] )
什么是问题?
问题是,您将按照示例中的说明更新每根柱的止损和获利价格。 因为,每出现一个新柱,都会有一个新low
。 对于每一个新柱,都会调用你的strategy.exit()
function。
您可以做的是,在入场时存储low
并在您的strategy.exit()
调用中使用它。
var float low_at_entry = na
if (LongEntry)
low_at_entry := low
strategy.entry("Long Position",strategy.long,when = LongEntry)
if (strategy.position_size > 0)
strategy.exit("Exit Long" , from_entry = "Long Position" , stop = low_at_entry [1] , profit = 3*low_at_entry [1] )
注意:您需要确保您的LongEntry
在交易期间只为真一次。 否则low_at_entry
将在再次进入后更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.