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
    Paul H.NinjaTrader Customer Service

    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, 08: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.
          Paul H.NinjaTrader Customer Service

          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
              Paul H.NinjaTrader Customer Service

              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
                  }
                  Paul H.NinjaTrader Customer Service

                  Comment


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

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by vantojo, Today, 06:46 AM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_Jim  
                    Started by sidlercom80, Today, 02:40 AM
                    1 response
                    14 views
                    0 likes
                    Last Post NinjaTrader_PaulH  
                    Started by b16_aln, Today, 01:52 AM
                    0 responses
                    14 views
                    0 likes
                    Last Post b16_aln
                    by b16_aln
                     
                    Started by junkone, Yesterday, 08:55 PM
                    2 responses
                    13 views
                    0 likes
                    Last Post junkone
                    by junkone
                     
                    Started by adaeiqendqw, 01-16-2021, 02:56 AM
                    1 response
                    17 views
                    0 likes
                    Last Post NinjaTrader_Jason  
                    Working...
                    X