Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Access data series end date within indicator

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

    Access data series end date within indicator

    Hello,

    Can you please advise how I can access the chart data series "end date" via script. When you double click on a chart data you have the option to set an end date and days to load. How can I access the current chart end date within an indicator script so that I can copy the "end date" day, month and year value to my indicator defaults? I tried ChartControl.PrimaryBars.Properties.To.Day to access the day data within State=SetDefaults but getting error "object reference not set to an instance of an object".

    Thanks

    #2
    Hello b16_aln,

    Thanks for your post.

    I would suggest checking Bars.ToDate. As this depends on the Bars object, this should be accessed no sooner than State.DataLoaded.

    Code:
    else if (State == State.DataLoaded)
    {
        Print(Bars.ToDate);
    }
    Please let us know if there is anything else we can do to help.

    Comment


      #3
      Thanks but what can I use within State=SetDefaults so that I can then Overide it on the UI settings tab if i wish.

      Comment


        #4
        Hello b16_aln,

        It would not be supported to override the data series ToDate from a script.

        If you absolutely need to access this value in State.SetDefaults, you could consider looping through all windows, find the owner chart, and then to access PrimaryBars once you have found the active ChartControl. I would not recommend this as SetDefaults gets called multiple times in the NinjaScripts life to populate the indicator on the Indicators dialog, fetch defaults when the indicator is selected, etc. If enough indicators are doing this in SetDefaults, we could start to see issues where several indicators will be looping through all windows, and this could get expensive.

        Code:
        foreach (var window in NinjaTrader.Core.Globals.AllWindows)
        {
            // check if the found window is a Chart window, if not continue looking
            if (!(window is NinjaTrader.Gui.Chart.Chart)) continue;
        
            window.Dispatcher.InvokeAsync(new Action(() =>
            {
                // try to cast as a Chart, if it fails it will be null
                var foundChart = window as NinjaTrader.Gui.Chart.Chart;
        
                // make sure we found a chart
                if (foundChart == null) return;
        
                // make sure the found chart is the owner window
                if (foundChart != this.Owner as NinjaTrader.Gui.Chart.Chart) return;
        
                // Print PrimaryBars ToDate
                Print(foundChart.ActiveChartControl.PrimaryBars.Bars.ToDate);                                         
             }));
        
         }
        Please let me know if you have any questions.

        Comment


          #5
          Thanks Jim, very helpful response

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          652 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          577 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X