I have an automated trading strategy for ES and I am struggling with the following:
Let's say I just entered a long trade
- I want to set an initial stop loss of 12 ticks
- Once the trade goes in my favor by 8 ticks, I'd like to move stop loss to breakeven price
- After that once the strategy starts making 9 to 20 ticks of profit, I want to move the stop loss 4 ticks above my entry price (profit protection)
- And at last if the strategy starts making 21 to 40 ticks of profit, I want to move the stop loss 12 ticks above my entry price
I am not sure if I need to use SetStopLoss or SetTrailStop to achieve the above objectives.
Currently this is what I have in terms of script under 'OnBarUpdate', but I am not able to see the strategy behaving the way it needs to.
if (Position.MarketPosition == MarketPosition.Flat)
{
SetTrailStop(CalculationMode.Ticks, 12);
}
else if (Position.MarketPosition == MarketPosition.Long)
{
if (Close[0] >= (Position.AvgPrice + 8 * TickSize))
{
SetTrailStop(CalculationMode.Ticks, 0);
}
if (Close[0] >= (Position.AvgPrice + 9 * TickSize)
&& (Close[0] <= (Position.AvgPrice + 20 * TickSize)))
{
SetTrailStop(CalculationMode.Ticks, 4);
}
if (Close[0] >= (Position.AvgPrice + 21 * TickSize)
&& (Close[0] <= (Position.AvgPrice + 40 * TickSize)))
{
SetTrailStop(CalculationMode.Ticks, 12);
}
}
I am not sure what am I doing wrong? Can someone please help to achieve the objectives I described above? Should I be using SetStopLoss instead of SetTrailStop? Is there anything wrong with the code above?
Very much appreciate your help in advance.
Comment