No announcement yet.

Partner 728x90


Is it possible to get the current forming candles OHLC

  • Filter
  • Time
  • Show
Clear All
new posts

    Is it possible to get the current forming candles OHLC

    From every script I've come across so far I do not see any way of accessing the current FORMING candle's OHLC & this is a MAJOR part of what I am trying to program,

    Very simple no further explanation

    Thank you in advance.

    You need to study the Calculate property.

    It is this setting that allows you to get the OHLC values of the
    current forming candle while that candle is forming.

    Calculate can be set by the programmer or by the user in the
    property grid.

    If set to Calculate.OnEachBar then OnBarUpdate is only called
    when the bar closes, and High[0] represents the high of the most
    recently closed bar.

    If set to Calculate.OnEachTick, then OnBarUpdate is called for
    each tick that is processed, and High[1] represents the high of
    the most recently closed bar while High[0] is the high of the active
    bar currently being built. Obviously, OnEachTick can be highly

    The index values I've highlighted in red are not array indexes,
    but instead are referred to as a 'BarsAgo' index.

    This 0-vs-1 shift in the BarsAgo index occurs based upon the
    Calculate setting. However, most indicators are specifically
    coded using BarsAgo index '0' and still produce correct results
    regardless of the Calculate setting.
    Last edited by bltdavid; Yesterday, 03:53 PM. Reason: fix typos


      Hello AlexsOptions,

      Thanks for your post and welcome to the NinjaTrader forums!

      Member bltdavid has provided a good explanation of the Calculate setting along with a link to that section of the Help Guide.

      Using Calculate.OnEachTick does provide you with the prices of the currently forming bar so keep in mind that the High, Low and Close prices can and will change until the bar closes. The Open price does not change. The Close price of Close[0] on live data is the current price. Close[1] is the close price of the just-closed bar.

      Running your strategy with Calculate.OnEachTick does mean that the OnBarUpdate() is called on every incoming tick regardless of the price of the tick. It often occurs that you will receive several ticks in a row that do not change the price. If your strategy and indicators it calls are working on price change, you may want to instead use the calculate setting of Calculate.OnPriceChange so that the OnBarUpdate() is only called when there is a change in price. This reduces the cycling of the script.

      It is possible to run parts of your code OnEachTick (Or OnPriceChange) and other parts once per bar by using the system bool IsFirstTickOfBar to segment the code. Here is a link to a reference example:

      Finally, please note that Calculate.OnEachTick or Calculate.OnPriceChange, are only functional on live (or playback with market replay) data. If you apply a script with Calculate.OnEachTick or Calculate.OnPriceChange) to historical data, the script will only process once per bar. You can get the functionality with historical data if you enable/use Tick Replay which requires tick data for the duration of the historical data. Reference:

      Last edited by NinjaTrader_PaulH; Yesterday, 07:01 AM.
      Paul H.NinjaTrader Customer Service


        Thanks to both of you! Didn't knows that changing the trigger would change the list of bars received. I think I understand it clearly now though.


        Latest Posts


        Topics Statistics Last Post
        Started by nutmame1, Today, 08:26 PM
        0 responses
        Last Post nutmame1  
        Started by dr0832, Today, 07:02 PM
        0 responses
        Last Post dr0832
        by dr0832
        Started by mlurskint8, Today, 05:27 PM
        3 responses
        Last Post NinjaTrader_ShawnB  
        Started by SteveTheCPA, Today, 04:54 PM
        0 responses
        Last Post SteveTheCPA  
        Started by Unsuitable, Today, 02:42 PM
        2 responses
        Last Post Unsuitable