here is a demonstration of the rare but still existing case where NT gets confused and does not either cancel or fill an order during backtesting with managed positions.
This happens when reversing a position and stop/profit takers are set that will also result in a fill.
It doesn't make or break a system but it's still a bug.
In my example I am using 10000 vol bars on CL starting from 01/Jan/2020 non merged and 10 fast 259 slow(times are in EST). If it helps I can supply as many bar/parameter combinations as necessary for reproduction with exact dates.
public class SampleMABracket : Strategy {
private SMA smaFast;
private SMA smaSlow;
protected override void OnStateChange() {
if (State == State.SetDefaults) {
Description = "Sample MA Bracket";
Name = "SampleMABracket";
Fast = 10;
Slow = 25;
// This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = false;
} else if (State == State.DataLoaded) {
smaFast = SMA(Fast);
smaSlow = SMA(Slow);
}
}
protected override void OnBarUpdate() {
if (CurrentBar < BarsRequiredToTrade)
return;
if (CrossAbove(smaFast, smaSlow, 1)) {
if (Position.MarketPosition != MarketPosition.Long) {
SetStopLoss(CalculationMode.Ticks, 30);
SetProfitTarget(CalculationMode.Ticks, 30);
EnterLong();
}
} else if (CrossBelow(smaFast, smaSlow, 1)) {
if (Position.MarketPosition != MarketPosition.Short) {
SetStopLoss(CalculationMode.Ticks, 30);
SetProfitTarget(CalculationMode.Ticks, 30);
EnterShort();
}
}
}
#region Properties
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "Fast", GroupName = "NinjaScriptStrategyParameters", Order = 0)]
public int Fast { get; set; }
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "Slow", GroupName = "NinjaScriptStrategyParameters", Order = 1)]
public int Slow { get; set; }
#endregion
}

Comment