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

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_ChartTypeSecondary_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 0index 3index++) 
                    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 sidlercom80, 10-28-2023, 08:49 AM
      168 responses
      2,261 views
      0 likes
      Last Post sidlercom80  
      Started by Barry Milan, Yesterday, 10:35 PM
      3 responses
      10 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by WeyldFalcon, 12-10-2020, 06:48 PM
      14 responses
      1,428 views
      0 likes
      Last Post Handclap0241  
      Started by DJ888, 04-16-2024, 06:09 PM
      2 responses
      9 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      41 views
      0 likes
      Last Post jeronymite  
      Working...
      X