I´m having problems with the stops of a strategy.
Some times it stops entering the market when the conditions for entering are meet an only resumes when a new day starts..
Here is the code:
double stop; if (CurrentBar < Math.Max(PeriodStd, highWindow)) return; if (Bars.IsFirstBarOfSession) entriesPerWindowLeft = maxEntriesPerWindow; if (Position.MarketPosition == MarketPosition.Flat) SetStopLoss(CalculationMode.Currency, stopInCurrency); std0 = StdDev(PeriodStd)[0]; stop = std0< priceStopPoints ? std0* instrumentPointValue : priceStopPoints; double pullback = (Close[0] - MAX(highWindow)[0]) / std0; if (entriesPerWindowLeft > 0 && pullback >= DipBuy) { EnterLong(PositionLots); SetStopLoss(CalculationMode.Currency, stop); entriesPerWindowLeft--; } else if (pullback < DipBuy) { ExitLong(); entriesPerWindowLeft = maxEntriesPerWindow; }
If a run a different version of the strategy, using the same stop value the situation does not occur
if (CurrentBar<Math.Max(PeriodStd, highWindow)) return; if (Bars.IsFirstBarOfSession) entriesPerWindowLeft = maxEntriesPerWindow; if(Position.MarketPosition==MarketPosition.Flat) SetStopLoss(CalculationMode.Currency, stopInCurrency); double std0 = StdDev(PeriodStd)[0]; double pullback = (Close[0] - MAX(highWindow)[0]) / std0; if (entriesPerWindowLeft > 0 && pullback >= DipBuy) { EnterLong(PositionLots); entriesPerWindowLeft--; SetStopLoss(CalculationMode.Currency, stopInCurrency); } else if (pullback<DipBuy) { ExitLong(); entriesPerWindowLeft = maxEntriesPerWindow; }
In attach is a print screen demonstrating the situation, the red and green vertical zones were trades should have taken place but at some point stop occurring. The two above blocks should (in my best judgment) yield the same numbers of trades, but that did not happened.
Regards,
Vava
Comment