Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy error after contract Change

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

    Strategy error after contract Change

    I have an Inidicator in my Strategy that plots an hourly 20SMA on a lower time frame chart. When the contract changed yesterday it stopped working with this error:

    '20HrlySMAonTick' tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state. Attempted to load NQ MAR25 Globex: 60 Minute


    Here is the Indicator:

    PHP Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class 20HrlySMAonTick : Indicator
        {
            private SMA SMA1;
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Indicator here.";
                    Name                                        = "20HrlySMAonTick";
                    Calculate                                    = Calculate.OnBarClose;
                    IsOverlay                                    = true;
                    DisplayInDataBox                            = true;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                        = true;
                    DrawVerticalGridLines                        = true;
                    PaintPriceMarkers                            = true;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
                    AddPlot(Brushes.LightCoral, "SMAPlot");
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Minute, 60); //add our secondary 60 minute data series for calculating the SMA
                }
                else if (State == State.DataLoaded)
                {
                    SMA1 = SMA(BarsArray[1], 20);  //set SMA here so we make sure it's calculated on the secondary data series
                }
                
            }
    
            protected override void OnBarUpdate()
            {
                
                if (CurrentBars[0] < 1 || CurrentBars[1] < 20) 
                    return;
    
                if(BarsInProgress == 0)           // if OnBarUpdate was called from the primary bar series, then set the current value to the latest SMA1 value
                    Value[0] = SMA1[0];    
            }
    
            #region Properties
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> SMAPlot
            {
                get { return Values[0]; }
            }
            #endregion
    
        }
    }&#8203; 
    

    #2
    Hello nelslynn,

    In your strategy you likely have the additional series using a specific contract rather than the primary instrument. Please check in the strategies additional data tab that you have a secondary 60 minute series added with use primary instrument checked. If you do not have that option checked it is likely pointing to an older contract.

    Comment


      #3
      That was it, thanks.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      20 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      48 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      38 views
      0 likes
      Last Post CarlTrading  
      Working...
      X