I have a stop even set on my automated strategy. It measures if the close of the current bar exceeds a certain value and adjusts the stop loss.
My strategy makes position reversals more often than pure exits. I noticed that when a reversal occurs, the stop is not resetted to the standard one.
This causes the stop even to be triggered by the previous movement and adjust the stop loss for the one that follows after the reversal.
I am attaching a screenshot to show the example. In this case there were the following executions:
1. Short - which was not profitable
2. Long (reversed the short) - which was profitable and activated the stop even
3. Short - which was not profitable and stop even (which was activated from previous movement) was hit (0.3% from entry price). Normal Stop is 0.7%.
Currently the code has one reset on the stop even, which checks if 1 bar ago position was long and current bar position is short (and vice versa). When these conditions are met, the stop loss to be resetted....however I can't seem to find how to do that.
Any input will be very much appreciated.
And here is the code of the stopeven in my strategy.
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss("", CalculationMode.Percent, StopLoss, false);
}
else if (Position.MarketPosition == MarketPosition.Long)
{// Once the price is greater than entry price+ ticks, set stop loss to breakeven
if (Close[0] > Position.AvgPrice + StopEvenOffset * TickSize)
{
SetStopLoss(CalculationMode.Percent, StopEven);
}}
else if (Position.MarketPosition == MarketPosition.Short)
{// Once the price is greater than entry price- ticks, set stop loss to breakeven
if (Close[0] < Position.AvgPrice - StopEvenOffset * TickSize)
{
SetStopLoss(CalculationMode.Percent, StopEven);
}}
Comment