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

Get Future bar's value from previous bars

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

    Get Future bar's value from previous bars

    I want to compare current bar's price with the last bar's price.

    in indicator, I want somehting like this:

    Code:
    OnBarUpdate(){
        ...
        Print([COLOR="Red"]LastBarOfChart_CLOSE[/COLOR]  - CLOSE[0]);
        .....
    }
    I think I understand what i want to say. I want to know in advance, the last loaded bar's value.

    As Chart is displayed only after State is DataLoaded, it means, that NT already knows all values of loaded bars on chart. So, there will be way to know all Bars' data in advance in OnBarUpdate().

    Can you help me?
    Last edited by ttodua; 02-23-2018, 03:11 PM.

    #2
    Hello TazoTodua,

    Thanks for opening the thread.

    Do you mean you want to compare the very first historical bar to the current bar that is iterating? This could easily be done by using CurrentBar as the index for the Price Series and compare it to the current index of the PriceSeries.

    For example: Print(Close[CurrentBar] - Close[0]);

    I am not sure what your goal is for you to look for bars data before it it iterates, but you could look into referencing the data from the Bars object itself with Bars.GetClose() Bars.Count and other methods/properties. These should be available after data loads.

    Bars object - https://ninjatrader.com/support/help...en-us/bars.htm

    Please let me know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      No. Lets say, on chart, here is 500 bars (and DataLoaded happened you know).
      so, in iteration (in OnBarUpdate), i want to compare current bar to the last bar on chart (i.e. 500th bar, which i most recent) price.

      i think i've said it clearly.

      in ThinkOrSwim it is possible to obtain next bar's values.
      Last edited by ttodua; 02-23-2018, 03:55 PM.

      Comment


        #4
        Hello TazoTodua,

        My example statement would accomplish that task.

        For your example, 500 bars loaded on a chart, Close[CurrentBar] would be that 500th bar (first bar on the chart, and Close[0] would be the last bar on the chart or the 0 bar.

        CurrentBar iterates with each new bar, so Close[CurrentBar] will always be that first bar on the chart.

        Please let me know if this is not what you are trying to do.
        JimNinjaTrader Customer Service

        Comment


          #5
          Are you looking for something like this?

          It will loop through the Close prices of every candle and subtract the Close price of the current candle from each one and print that value.

          Code:
          //  first wait for everything to load or else we get the wrong value for CurrentBar
          if (State == State.Realtime)
          {
             for (int idx = 0; idx < CurrentBar; idx++)
              {
                double valDiff = Bars.GetClose(idx) - Bars.GetClose(CurrentBar);
                Print(valDiff);
              }
          }
          this keeps the last candle out of the loop and prevents an unnecessary subtraction of a value from itself

          Comment


            #6
            Brilliant JIM! thanks!
            Thanks also gubbar924,

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Jon17, Today, 04:33 PM
            0 responses
            1 view
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            4 views
            0 likes
            Last Post Javierw.ok  
            Started by timmbbo, Today, 08:59 AM
            2 responses
            10 views
            0 likes
            Last Post bltdavid  
            Started by alifarahani, Today, 09:40 AM
            6 responses
            41 views
            0 likes
            Last Post alifarahani  
            Started by Waxavi, Today, 02:10 AM
            1 response
            20 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Working...
            X