I took an example from the code I am working on to help explain. FYI I am using generic "custom indicator" instead of using the actual code for the indicator
So for instance, earlier in the strategy code, I have logic to get long and I get filled. The logic then proceeds to the code below. As the market moves up, past certain market levels, the target stays the same but the stop moves up.
My problem is in the "second stop move" below and the argument "&& Low[1]>custom indicator[1]". What can happen is Low[1] may move below the custom indicator, so instead of the stop for that logic staying at lower custom indicator[0]-1*TickSize, instead it goes back to the logic in the "first stop move" and moves to lower custom indicator[0]-2*TickSize
Essentially what needs to be happening is the stops below in the code should be in order, so as the market reaches the logic of the "third stop move", the placement of the stop for that logic ( Position.AveragePrice + 1*TickSize) needs to stay in place, no matter what the market does after that logic becomes true. (same with first and second stop move)
I am also doing the same thing for a short, just opposite.
Hopefully that all makes sense. Let me know any questions
//first stop move
if(Position.MarketPosition == MarketPosition.Long
&& Position.AveragePrice<lower custom indicator[1]
&& High[0]>=custom indicator[1])
{
SetProfitTarget("Long", CalculationMode.Price,higher custom indicator[0]-1*TickSize,true);
SetStopLoss("Long", CalculationMode.Price,lower custom indicator[0]-2*TickSize,true);
}
// second stop move
if(Position.MarketPosition == MarketPosition.Long
&& Position.AveragePrice<lower custom indicator[1]
&& Low[1]>custom indicator[1])
{
SetProfitTarget("Long", CalculationMode.Price,higher custom indicator[0]-1*TickSize,true);
SetStopLoss("Long", CalculationMode.Price,lower custom indicator[0]-1*TickSize,true);
}
//third stop move
if(Position.MarketPosition == MarketPosition.Long
&& Position.AveragePrice<custom indicator[1]
&& Low[1]>other custom indicator[1])
{
SetProfitTarget("Long", CalculationMode.Price,higher custom indicator[0]-1*TickSize,true);
SetStopLoss("Long", CalculationMode.Price,Position.AveragePrice + 1*TickSize,true);
}
Comment