Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using IDataSeries with Secondary Chart Series

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

    Using IDataSeries with Secondary Chart Series

    What is the correct way to use IDataSeries when accessing a Secondary Chart Series.

    This is the code I am using. All the indicator is doing is getting the Secondary Chart Series DoubbleStochasctics and Printing out the Bar Time and Indicator Value. Then it passes the dataseries to a method that prints the Time and Indicator Values for the three previous bars. What am I doing wrong? Is this not a correct use for IDataSeries? Is there another way of accomplishing the same thing?



    PHP Code:
            #region Variables
            // Wizard generated variables
                private int period = 10;
            
                private PeriodType     secondary_ChartType        = PeriodType.Minute;
                private int         secondary_ChartInterval = 5;                    
            
            
            // User defined variables (add any user defined variables below)
            
                private DataSeries SecondaryDoubleStochastics;
            
            #endregion
    
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
                Overlay                = true;
                
                Add(Secondary_ChartType, Secondary_ChartInterval);  //  Bars Array 1
                SecondaryDoubleStochastics = new DataSeries(this); 
                
            }
    
            private void PrintSecondarySeries(IDataSeries CurrentSeries)
            {
                Print("    Print From Method");
                
                //  Loop back to get the 3 most recent Time and Values
                for (int index = 0; index < 3; index++) 
                    Print(String.Format("    Time: {0}   SecondaryDoubleStochastics: {1}", Time[index], SecondaryDoubleStochastics[index]    ));
            }
            
            
            protected override void OnBarUpdate()
            {
                // Sync Secondary DataSeries
                if(SecondaryDoubleStochastics == null)
                    SecondaryDoubleStochastics = new DataSeries(SMA(BarsArray[1], 1));
                
                //  Secondary Series OnBarUpdate
                if(BarsInProgress == 1)
                {
                    //  Set SecondaryDoubleStochastics
                    SecondaryDoubleStochastics.Set(DoubleStochastics(Period)[0]);
                    //  Print the CurrentBar Time and Value
                    Print(String.Format("\r\nOnBarUpdate  New Bar {0}  SecondaryDoubleStochastics[0]: {1}", Time[0], SecondaryDoubleStochastics[0] )); 
                    
                    //    Call the Method and pass the DataSeries
                    if(CurrentBar > 3)
                        PrintSecondarySeries(SecondaryDoubleStochastics);
                }
            } 
    


    I am getting incorrect results as can be seem in the image.

    I have attached the indicator.

    Thanks for your help.
    Attached Files

    #2
    Hello,

    You'll want to remove the data series from being set in Initialize()

    SecondaryDoubleStochastics = new DataSeries(this);

    Currently your null check won't evaluate to true so it doesn't get synced with the secondary series

    Let me know if I can be of further assistance.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Thanks. As usual a prompt reply to an issue.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      581 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      338 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X