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

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, 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.
          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 algospoke, Yesterday, 06:40 PM
                    2 responses
                    18 views
                    0 likes
                    Last Post algospoke  
                    Started by ghoul, Today, 06:02 PM
                    3 responses
                    14 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by jeronymite, 04-12-2024, 04:26 PM
                    3 responses
                    44 views
                    0 likes
                    Last Post jeronymite  
                    Started by Barry Milan, Yesterday, 10:35 PM
                    7 responses
                    20 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by AttiM, 02-14-2024, 05:20 PM
                    10 responses
                    180 views
                    0 likes
                    Last Post jeronymite  
                    Working...
                    X