问题
I am trying to use strategy.order
for shorts in order to have 3 take profit levels (level 1 lowest TP and Level 3 highest TP) and execute when my stop loss is reached to exit the remaining position.
if (strategy.position_size >= 0 and high[1] < close)
strategy.entry(id="EnterShort", long=false, qty = 1)
shortHighEntery := close
shortHighEnteryStoppLoss :=high +1
else
shortHighEntery := shortHighEntery[1]
shortHighEnteryStoppLoss :=shortHighEnteryStoppLoss[1]
exitShort = shortHighEntery *0.995
stop_level = shortHighEnteryStoppLoss
take_level1 = strategy.position_avg_price * (1 - 0.0075)
take_level2 = strategy.position_avg_price * (1 - 0.015)
take_level3 = strategy.position_avg_price * (1 - 0.045)
if (strategy.position_size < 0)
strategy.order("Stop Loss Short", qty= 1, long=true, stop=stop_level, oca_name='Short', oca_type=strategy.oca.reduce)
strategy.order("TP 1 Short", qty= 0.2, long=true, limit=take_level1, oca_name='Short', oca_type=strategy.oca.reduce)
strategy.order("TP 2 Short", qty= 0.6, long=true, limit=take_level2, oca_name='Short', oca_type=strategy.oca.reduce)
strategy.order("TP 3 Short", qty= 1, long=true, limit=take_level3, oca_name='Short', oca_type=strategy.oca.reduce)
It works at the begining, but unfortunately after a while it leads to a situation where my script longs which is never intended and then a mess starts. It seems like I don't understood the concept of either oca_type=strategy.oca.reduce
or long=yes
. But currently I have no clue on what I need to do.
来源:https://stackoverflow.com/questions/62683935/correct-usage-of-strategy-order