Hey
I like to do it as follows:
When there is a need to go Long , i mark
isLong as true and for short
isShort as true.
Also i mark
takeProfitBuy as true on meeting certain conditions and
takeProfitSell as true when certain other conditions meet for short. You can set these to be set at 1:1 profit or any other condition.
I than have the following code in sequence.
Code: Select all
strategy.entry("LONG", strategy.long, when=isLong)
strategy.entry("SHORT", strategy.short, when=isShort)
strategy.entry("LongHalfClose", strategy.short, math.abs(strategy.position_size/2), when = takeProfitBuy and strategy.position_size > 0)
strategy.entry("ShortHalfClose", strategy.long, math.abs(strategy.position_size/2), when = takeProfitSell and strategy.position_size < 0)