I recently added a piece of code in my strategy, and started getting this error when testing on the demo account.
Here is code
StopLossTicks = 40; ProfitTargetTicks = 160; BreakevenAfterTicks = 50;
// Resets the stop loss to the original value when all positions are closed if (Position.MarketPosition == MarketPosition.Flat) { SetStopLoss(CalculationMode.Ticks, StopLossTicks); } // If a long position is open, allow for stop loss modification to breakeven if (Position.MarketPosition == MarketPosition.Long) { // Once the price is greater than entry price+50 ticks, set stop loss to breakeven if (Close[0] > Position.AveragePrice + BreakevenAfterTicks * TickSize) { SetStopLoss(CalculationMode.Price, Position.AveragePrice); } } // If a short position is open, allow for stop loss modification to breakeven if (Position.MarketPosition == MarketPosition.Short) { // Once the price is greater than entry price-50 ticks, set stop loss to breakeven if (Close[0] < Position.AveragePrice - BreakevenAfterTicks * TickSize) { SetStopLoss(CalculationMode.Price, Position.AveragePrice); } }
Could you please let me know where i'm going wrong?
Thanks
M
Comment