I'm working on a strategy that uses two time frames: 1 minute bar to enter orders and 1 tick bar to exit orders (trailing stops, etc..)
As a start, I've modified the SampleMACrossOver strategy to include another timeframe, but I'm getting wrong orders and the strategy gets disabled.
This is the modified code:
/// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { SMA(Fast).Plots[0].Pen.Color = Color.Orange; SMA(Slow).Plots[0].Pen.Color = Color.Green; Add(SMA(Fast)); Add(SMA(Slow)); Add(PeriodType.Tick, 1); //New time frame to handle exits. CalculateOnBarClose = true; } /// <summary> /// Called on each bar update event (incoming tick). /// </summary> protected override void OnBarUpdate() { // Check which Bars object is calling the OnBarUpdate() method if (BarsInProgress == 0) { // Do something within the context of the 1 minute Bars here if (CrossAbove(SMA(Fast), SMA(Slow), 1)) EnterLong(); else if (CrossBelow(SMA(Fast), SMA(Slow), 1)) EnterShort(); Print("BarsInProgress: "+BarsInProgress+" "+Time[0]+" Close[0]:"+Close[0]); } else if (BarsInProgress == 1) { // Do something within the context of the 1 tick Bars Print("BarsInProgress: "+BarsInProgress+" "+Time[0]+" Close[0]:"+Close[0]); } }
Thanks!
Comment