Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Issues with Multi-Time frame dataseries

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

    Issues with Multi-Time frame dataseries

    Hi, I've attached this indicator to a 1-minute chart (with 20 days of data) but I'm not able to see the plots in the chart.

    Code:
        public class Test Dataseries : Indicator
        {
            private SMA MA_1_20, MA_5_20, MA_60_20, MA_240_89;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Indicator here.";
                    Name                                        = "Test Dataseries";
                    Calculate                                    = Calculate.OnPriceChange;
                    IsOverlay                                    = true;
    
    
                    AddPlot(Brushes.Yellow, "SMA_1_20");     //[0]
                    AddPlot(Brushes.Orange, "SMA_5_20");     //[1]
                    AddPlot(Brushes.Blue, "SMA_60_20");    //[2]
                    AddPlot(Brushes.Cyan, "SMA_240_89");   //[3]
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Minute, 5);
                    AddDataSeries(Data.BarsPeriodType.Minute, 60);
                    AddDataSeries(Data.BarsPeriodType.Minute, 240);
                }
    
                else if (State == State.DataLoaded)
                {
                       MA_1_20 =   SMA(Close, 20);
                    MA_5_20 =   SMA(Closes[1], 20);
                    MA_60_20 =  SMA(Closes[2], 20);
                    MA_240_89 = SMA(Closes[3], 20);
                }
            }
    
            protected override void OnBarUpdate()
            {        
                if (BarsInProgress != 0)
                return;
    
                // Debug statement to check the status of each data series
                for (int i = 0; i <= 3; i++)
                {
                Print("Data Series [" + i + "]  CurrentBars: " + (CurrentBars.Length > i ? CurrentBars[i].ToString() : "Not Initialized"));
                }
    
                // Check if all data series have received at least one bar update
                if (CurrentBars[0] < 2 || CurrentBars[1] < 1 || CurrentBars[2] < 1 || CurrentBars[3] < 1)
                return;
    
                Values[0][0] = MA_1_20[0];
                Values[1][0] = MA_5_20[0];
                Values[2][0] = MA_60_20[0];
                Values[3][0] = MA_240_89[0];        
    
                Print ("    ");
    
            }
        }​
    Output:

    Data Series [0] CurrentBars: 20377
    Data Series [1] CurrentBars: -1
    Data Series [2] CurrentBars: -1
    Data Series [3] CurrentBars: -1

    Data Series [0] CurrentBars: 20377
    Data Series [1] CurrentBars: -1
    Data Series [2] CurrentBars: -1
    Data Series [3] CurrentBars: -1

    Data Series [0] CurrentBars: 20377
    Data Series [1] CurrentBars: -1
    Data Series [2] CurrentBars: -1
    Data Series [3] CurrentBars: -1​

    How can I fix it so, that all 4 plots are visible in the chart?

    Thank you!!!

    #2
    Hello xtremel,

    Thank you for your post.

    I tested your code out and was able to see all 4 plots on the chart (please see the attached screenshot, I increased the width of the plots from the properties menu for better visibility) once all the series have a bar. Have you waited to make sure all series have a bar?
    Attached Files
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Hi,

      This:

      Code:
      
                  // Check if all data series have received at least one bar update
                  if (CurrentBars[0] < 2 || CurrentBars[1] < 1 || CurrentBars[2] < 1 || CurrentBars[3] < 1)
                  return;
      
                  Values[0][0] = MA_1_20[0];
                  Values[1][0] = MA_5_20[0];
                  Values[2][0] = MA_60_20[0];
                  Values[3][0] = MA_240_89[0];        
      
      
              }​
      Give me this error:

      Indicator 'EntrySignals': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

      if I comment on this, I can see the yellow line, but otherwise doesn't work, I'm not able to see the other plots.

      Code:
        
      // Check if all data series have received at least one bar update
      //            if (CurrentBars[0] < 2 || CurrentBars[1] < 1 || CurrentBars[2] < 1 || CurrentBars[3] < 1)
      //            return;
      
                  Values[0][0] = MA_1_20[0];      //yellow line
      //            Values[1][0] = MA_5_20[0];
      //            Values[2][0] = MA_60_20[0];
      //            Values[3][0] = MA_240_89[0];        
      
                  Print ("    ");​
      I keep seeing also -1 for the other plot values:

      12/5/2023 10:12:00 AM Data Series [0] CurrentBars: 19727
      12/5/2023 10:12:00 AM Data Series [1] CurrentBars: -1
      12/5/2023 10:12:00 AM Data Series [2] CurrentBars: -1
      12/5/2023 10:12:00 AM Data Series [3] CurrentBars: -1
      12/5/2023 10:12:00 AM Data Series [0] CurrentBars: 19727
      12/5/2023 10:12:00 AM Data Series [1] CurrentBars: -1
      12/5/2023 10:12:00 AM Data Series [2] CurrentBars: -1
      12/5/2023 10:12:00 AM Data Series [3] CurrentBars: -1​​


      Another thing, I was trying to also test using the "Simulated Data Feed" and I keep getting this error message with ALL the instruments: "Error on requesting bars series: "Unknow instrument MESZ3"

      Comment


        #4
        Hello,

        What version of NinjaTrader are you using? You can check by going to the Control Center > Help > About.

        The latest version of NinjaTrader is 8.1.2.1 - if you have not already done so, please update to the latest version.

        Also, update your symbol mappings by going to Control Center > Tools > Database Management > Update Instruments > select 'Update symbol mappings' > click 'Update'.
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          Hi,

          Everything was working last week. I'm using version 8.1.2.1 64 64bit with Tradovate (Apex). None of my indicators that use multi-time frames are working. I created this very simple strategy using the strategy builder and keeps getting an error too.

          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.Indicators;
          using NinjaTrader.NinjaScript.DrawingTools;
          #endregion
          
          //This namespace holds Strategies in this folder and is required. Do not change it.
          namespace NinjaTrader.NinjaScript.Strategies
          {
              public class TestStrategy : Strategy
              {
                  private SMA SMA1;
          
          
                  protected override void OnStateChange()
                  {
                      if (State == State.SetDefaults)
                      {
                          Description                                    = @"Enter the description for your new custom Strategy here.";
                          Name                                        = "TestStrategy";
                          Calculate                                    = Calculate.OnEachTick;
                          EntriesPerDirection                            = 1;
                          EntryHandling                                = EntryHandling.AllEntries;
                          IsExitOnSessionCloseStrategy                = true;
                          ExitOnSessionCloseSeconds                    = 30;
                          IsFillLimitOnTouch                            = false;
                          MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                          OrderFillResolution                            = OrderFillResolution.Standard;
                          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;
                      }
                      else if (State == State.Configure)
                      {
                          AddDataSeries(Data.BarsPeriodType.Minute, 5);
                      }
                      else if (State == State.DataLoaded)
                      {                
                          SMA1                = SMA(Closes[1], 14);
                      }
                  }
          
                  protected override void OnBarUpdate()
                  {
                      if (BarsInProgress != 0)
                          return;
          
                      if (CurrentBars[0] < 1
                      || CurrentBars[1] < 1)
                          return;
          
                       // Set 1
                      if (Close[1] > SMA1[1])
                      {
                          BackBrush = Brushes.CornflowerBlue;
                      }
          
                  }
              }
          }​
          'TestStrategy' tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state. Attempted to load MNQZ3 Globex: 5 Minute

          Comment


            #6
            Hello,

            Did you try updating your symbol mappings as described?
            1. Disconnect from any active connections in the Control Center > Connections dropdown
            2. Go to the Control Center > Tools > Database Management window
            3. Under the “Update instruments” section, ensure the “General properties”, "Futures expiries" and “Symbol mappings” options are checked and then click 'Update'
            4. Restart NinjaTrader, and then test for this behavior again

            Does it still occur if you use numeric symbology? Such as MNQ 12-23.

            You may have to change this setting from the account portal by going to Settings > Preferences > Symbology Display Style > restart the platform.
            Gaby V.NinjaTrader Customer Service

            Comment


              #7
              THANK YOU!

              This fixed it, I was going nuts.

              "You may have to change this setting from the account portal by going to Settings > Preferences > Symbology Display Style > restart the platform"​

              Comment


                #8
                Hello,

                I'm glad to hear that worked.

                Did you also try updating the symbol mapping? Or did only updating the symbology resolve the error?

                So we are able to better assist clients, if you would be willing test by briefly changing the Symbology back to 'Exchange', restating the platform and go to Tools > Instruments > MNQ and 'Edit rollovers' - can you send a screenshot of your rollover list? After doing so, you can switch back to 'Numeric'.

                Thank you in advance if you are able to do so. I was unable to reproduce the error you were getting using 'Exchange' symbology, and would like to gather more info.
                Last edited by NinjaTrader_Gaby; 12-05-2023, 02:32 PM.
                Gaby V.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by fx.practic, 10-15-2013, 12:53 AM
                5 responses
                5,404 views
                0 likes
                Last Post Bidder
                by Bidder
                 
                Started by Shai Samuel, 07-02-2022, 02:46 PM
                4 responses
                95 views
                0 likes
                Last Post Bidder
                by Bidder
                 
                Started by DJ888, Yesterday, 10:57 PM
                0 responses
                8 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by MacDad, 02-25-2024, 11:48 PM
                7 responses
                159 views
                0 likes
                Last Post loganjarosz123  
                Started by Belfortbucks, Yesterday, 09:29 PM
                0 responses
                8 views
                0 likes
                Last Post Belfortbucks  
                Working...
                X