Как перевернуть позицию? strategy.close () и strategy.exit () - PullRequest
0 голосов
/ 25 мая 2020

у меня есть код:

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 ())

1 Ответ

1 голос
/ 29 мая 2020

Странно, что 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) 
...
...