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 mjairg, 07-20-2023, 11:57 PM
                    3 responses
                    213 views
                    1 like
                    Last Post PaulMohn  
                    Started by TheWhiteDragon, 01-21-2019, 12:44 PM
                    4 responses
                    544 views
                    0 likes
                    Last Post PaulMohn  
                    Started by GLFX005, Today, 03:23 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post GLFX005
                    by GLFX005
                     
                    Started by XXtrader, Yesterday, 11:30 PM
                    2 responses
                    12 views
                    0 likes
                    Last Post XXtrader  
                    Started by Waxavi, Today, 02:10 AM
                    0 responses
                    7 views
                    0 likes
                    Last Post Waxavi
                    by Waxavi
                     
                    Working...
                    X