Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Chart Data

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

    Chart Data

    Hi NT -

    Is there a way in NinjaScript to read only historical data? Or a way to populate the data series with historical data vs. real-time (live) data?

    For example, the way bar data is populated in Strategy Analyzer, is there a way to do this on a Chart or within Ninjascript?

    #2
    Hello bigsurftrader,

    Thanks for your post.

    You can check the State in the OnBarUpdate(). For example

    if (State == State.Historical)
    {
    // code here only executed when looking at historical bars
    }

    Reference: https://ninjatrader.com/support/help...-us/?state.htm

    Comment


      #3
      Excellent!! Thank you ;-)

      Comment


        #4
        So, if working with multiple data series, I'm assuming the following would work OnBarsUpdate


        if (State == State.Historical && BarsInProgress == 0)
        {
        // do something
        }

        if (State == State.Historical && BarsInProgress == 1)
        {
        // do something
        }
        Last edited by bigsurftrader; 09-28-2017, 09:07 AM.

        Comment


          #5
          Hello bigsurftrader,

          Yes, although the correct syntax is:

          if (State == State.Historical && BarsInProgress == 0)
          {
          // do something
          }

          if (State == State.Historical && BarsInProgress == 1)
          {
          // do something
          }

          Edit: Missed the correction BST.

          Comment


            #6
            Paul -- if using a 3M chart, any idea when "historical" data gets processed?

            Comment


              #7
              Hello bigsurftrader,

              Thanks for your post.

              Historical data would be processed when the chart data is first loaded and when for example an indicator (any ninjascript) is added (it will process on the historical bars in order).

              I may not have answered the question you were asking so here is a helpguide link to the OnStateChange() that provides definition of the states: https://ninjatrader.com/support/help...tatechange.htm

              Comment


                #8
                Hi Paul,

                Here's a code snippet.

                protected override void OnBarUpdate()
                {
                if (BarsInProgress == 0){
                Print("1 Minute");
                }

                if (BarsInProgress == 1){

                if (State == State.Historical){

                Print("3 Minutes Historical");
                Print("Time: " + TimeHelp.formatDate(Time[0]));

                }else{

                Print("3 Minutes");
                Print("Time: " + TimeHelp.formatDate(Time[0]));
                }
                }


                }

                I see that when BarsInProgress == 1, the "historical" condition only gets met.

                Ideally, I'd want ONLY BarsInProgress == 1 to read historical data. I'd want to model as close to Strategy Analyzer. It appears that SA uses "settled" or historical data that maybe more stable vs. what I see on "live" and "replay".

                Comment


                  #9
                  Hello bigsurftrader,

                  Thanks for your post.

                  I'm not entirely sure what you are trying to accomplish. The code you posted would print "1 minute" on every 1 minute bar both historical and live and 3 minute Historical when historical data or 3 minutes when live.

                  If you only want to process on the 3 minute bars historically then:

                  if (State == State.Historical)
                  {
                  if (BarsInProgress != 1) return; // Do not process unless BarInProgress = 1 && historical
                  // process the 3 minute data only here
                  }

                  Comment


                    #10
                    Thanks Paul, i'll test this out ;-)

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Yesterday, 05:17 AM
                    0 responses
                    59 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    134 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    75 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    45 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    50 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X