我正在尝试在 pine 中编写一个策略,我想在一些柱线之后关闭策略,但在柱线完成的持续时间内,我也想要止损。有什么办法可以做到这一点。
答案 0 :(得分:0)
使用带有 strategy.enty()
参数的 when
和带有 stategy.exit()
和 stop
参数的 loss
函数。
玩转这个脚本,进入图表上的第一根柱线(设置黄金符号,1D res):
//@version=4
strategy("My Strategy0", overlay=true, process_orders_on_close = 1)
//labels for bars
if (bar_index <= 15)
label.new(bar_index, 300, tostring(bar_index) )
strategy.entry("EN", strategy.long, when= bar_index == 0) // enter at bar #0
strategy.close("EN", when=bar_index == 15) // close at bar #15
strategy.exit("EN_EXIT", from_entry = "EN", stop = 312) // set stop and loss here
使用 https://kodify.net/tradingview/orders/strategy-entry/ https://kodify.net/tradingview/orders/percentage-stop/ 作为参考。