如何翻转位置? strategy.close()和strategy.exit()

问题描述 投票:0回答:1

我有代码:

strategy(title="StackOverflowExample", overlay=true, slippage=200, commission_type=strategy.commission.percent, commission_value=0.2)
long=crossover(sma(close, 10), sma(close, 20))
close_condition=crossunder(sma(close, 10), sma(close, 20))
stl=strategy.position_avg_price *0.97
strategy.entry("long", true, 1, when = long) 
strategy.close("long" , when = close_condition) 
strategy.exit("exit", "long", stop=stl, trail_price=strategy.position_avg_price*1.04 ,trail_offset=close*0.03/syminfo.mintick)

在两种情况下如何翻转头寸? (strategy.close(),strategy.exit())

pine-script
1个回答
0
投票

奇怪的是,qty = 2解决了这些问题。退出永不翻转位置。对于翻转,您需要输入相反的内容:

strategy(title="StackOverflowExample", overlay=true, slippage=200, commission_type=strategy.commission.percent, commission_value=0.2)
long=crossover(sma(close, 10), sma(close, 20))
close_condition=crossunder(sma(close, 10), sma(close, 20))
stl=strategy.position_avg_price *0.97
strategy.entry("long", true, 1, when = long) 
strategy.entry("short", false, 1, when = close_condition) 
...
© www.soinside.com 2019 - 2024. All rights reserved.