Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Secondary Day Series Not Firing on Live Strategy Startup

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Secondary Day Series Not Firing on Live Strategy Startup

    I'm experiencing a problem with a multi-timeseries strategy whereby the secondary series (PeriodType.Day, 1) is not firing OnBarUpdate events when running against live data. It does fire when run in the Strategy Analyzer.

    It's a simple gap fading strategy that is meant to run on 1 minute data. A second data series is added to determine the official settlement (close) price. There's a Print statement for each BarsInProgress value - 0 for minute bars and 1 for day bars. When enabled in the Strategies tab, the minute Print statements appear in the Output window however the day Print statements do not (i.e. OnBarUpdate never fires for BarsInProgress == 1).

    Here is the code:

    Code:
     
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Simple gap fade strategy for testing purposes.
    /// </summary>
    [Description("Simple gap fade strategy for testing purposes.")]
    public class GapTest : Strategy
    {
    #region Variables
    // Wizard generated variables
    // User defined variables (add any user defined variables below)
    #endregion
    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    Add(PeriodType.Day, 1);
    CalculateOnBarClose = true;
    }
    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 0)
    {
    if (!Bars.BarsType.IsIntraday)
    {
    DrawTextFixed("error msg", "Gap strategy only works on intraday intervals", TextPosition.BottomRight);
    return;
    }
    Print(String.Format("GAP TEST:\t{0}\t{1}\tprice = {2}\tgap price = {3}", 
    Time[0].ToLongDateString(), 
    Time[0].ToLongTimeString(), 
    Close[0].ToString(),
    GapPrice.ToString()));
     
    string signalName = "Gap Fade";
    if (!GapFilled)
    {
    if (Close[0] > GapPrice && GapPrice > 0)
    {
    EnterShort(signalName);
    ExitShortLimit(GapPrice, signalName);
    }
    else if (Close[0] < GapPrice)
    {
    EnterLong(signalName);
    ExitLongLimit(GapPrice, signalName);
    }
    }
    }
    else if (BarsInProgress == 1)
    {
    Print("____________________________________________________________________________");
    Print(String.Format("GAP TEST:\t{0}\t{1}\tDaily close = {2}", Time[0].ToLongDateString(), Time[0].ToLongTimeString(), Close[0].ToString()));
    Print("____________________________________________________________________________");
    }
    }
     
    #region GapPrice
    /// <summary>
    /// The previos session's close.
    /// </summary>
    protected double GapPrice
    {
    get
    {
    double gapPrice = double.MinValue;
    if (CurrentBars[1] > 0)
    {
    gapPrice = Closes[1][0];
    }
    return gapPrice;
    }
    }
    #endregion
     
    #region GapFilled
    /// <summary>
    /// Indicates whether or not the gap has filled during the current session.
    /// </summary>
    /// <returns></returns>
    protected bool GapFilled
    {
    get { return GapPrice <= CurrentDayOHL().CurrentHigh[0] && GapPrice >= CurrentDayOHL().CurrentLow[0]; }
    }
    #endregion
    #region Properties
    #endregion
    }
    }

    #2
    Hi infin8loop,

    Thanks for the post. To confirm - you're checking for historical day updates here? These would not show up until the minimum bars required has been met for the daily series. Check into both the Days to load setting and Minimum bars required to make sure you have enough bars for all series.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ah, yes, I had assumed the minimum bars required applied to the primary data series only. Ensuring that the minimum bars required vs. days to load made sense for the secondary (day) series resolved the problem. Thanks for the suggestion - this was a RTFM issue. So, the minimum bars required should be set according to the largest time frame that the strategy uses (i.e. if I require 5 days for an ATR and 200 minutes for a moving average, I would use a minimum bars required of 5).

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, Yesterday, 10:06 AM
      0 responses
      22 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      19 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      14 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      10 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      41 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X