I built a simple SMA Swing Strategy with NT8 Strategy Builder.
{ public class SwingSMA : Strategy { private SMA SMA1; private SMA SMA2; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Swing-Strategie auf Basis des SMA"; Name = "SwingSMA"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.High; OrderFillResolutionType = BarsPeriodType.Minute; OrderFillResolutionValue = 1; Slippage = 0; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Gtc; TraceOrders = false; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 20; // Disable this property for performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = true; Stragiebeginn = DateTime.Parse("08:00"); Strategieende = DateTime.Parse("22:00"); Periode_schnell = 10; Periode_langsam = 50; SL_Ticks = 1; } else if (State == State.Configure) { SetTrailStop("", CalculationMode.Ticks, SL_Ticks, false); } else if (State == State.DataLoaded) { SMA1 = SMA(Close, Convert.ToInt32(Periode_schnell)); SMA1.Plots[0].Brush = Brushes.MediumSeaGreen; AddChartIndicator(SMA1); SMA2 = SMA(Close, Convert.ToInt32(Periode_langsam)); SMA2.Plots[0].Brush = Brushes.Maroon; AddChartIndicator(SMA2); } } protected override void OnBarUpdate() { if (CurrentBars[0] < 1) return; // set 1 if ((CrossAbove(SMA1, SMA2, 1)) && (Times[0][0].TimeOfDay >= Stragiebeginn.TimeOfDay) && (Times[0][0].TimeOfDay < Strategieende.TimeOfDay)) { EnterLong(Convert.ToInt32(DefaultQuantity), ""); } // set 2 if ((CrossBelow(SMA1, SMA2, 1)) && (Times[0][0].TimeOfDay >= Stragiebeginn.TimeOfDay) && (Times[0][0].TimeOfDay < Strategieende.TimeOfDay)) { EnterShort(Convert.ToInt32(DefaultQuantity), ""); } // set 3 if (Times[0][0].TimeOfDay > Strategieende.TimeOfDay) { ExitLong(Convert.ToInt32(DefaultQuantity), "", ""); ExitShort(Convert.ToInt32(DefaultQuantity), "", ""); } }
My strategy sended an order at 02:50 CST. At 02:51 CST the order was closed with the error message (I am trying to translate) „Change of order not possible. Strategy sended cancellation requests, trying to close the position and closed itself.“
Do you think it's set 3?
Kind regards
Comment