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 argusthome, 03-08-2026, 10:06 AM
      0 responses
      113 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      60 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      40 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      43 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      81 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X