Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Property to Reliably Determine Last Bar On Chart in NinjaTrader 8 (not NT 7)?

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

    Property to Reliably Determine Last Bar On Chart in NinjaTrader 8 (not NT 7)?

    Hello NinjaTrader support,

    Is there a property available to NinjaTrader 8 strategies, like LastBarOnChart, that returns true if a bar is the last bar of the chart from the perspective of the Strategy?

    If not, how can one determine this in a way that works in all NinjaTrader 8 applications and scenarios, including back-tests in the Strategy Analyzer, applying a strategy to a historical chart that is disconnected from market data, applying a strategy to a live chart with real-time ticks, and all other NinjaTrader 8 windows where the user can apply a strategy to market data, for all 3 choices for StrategyBase.Calculate, including Calculate.OnBarClose, Calculate.OnEachTick, and Calculate.OnPriceChange?

    I understand that in the Strategy Analyzer, the last bar from the perspective of the strategy is the second to the last bar that is visible at the far right edge of the chart, and that is OK. I'm not looking for the last visible bar, just the last bar from the perspective of the strategy during the back-test or in a real-time situation.

    I saw this post by NinjaTrader_Ray from back in 2007, but it was for NinjaTrader 7, so did not include an option for calculating this property when Calculate = Calculate.OnPriceChange, plus maybe the answer has changed for another reason related to something new in NinjaTrader 8.



    The function below is my best guess based on NinjaTrader_Ray's post above, but I am concerned that it won't work in every scenario in NinjaTrader 8 so was hoping for an official answer from NinjaTrader support, and hopefully an official property of StrategyBase like "LastBarOnChart":

    Code:
    public bool IsLastBarOnChart_MayNotWorkInEveryScenario()
    {
    return (Calculate == Calculate.OnBarClose && CurrentBar == Bars.Count - 2)
    || (Calculate != Calculate.OnBarClose && CurrentBar == Bars.Count - 1);
    }
    Thanks in advance!

    EquityTrader

    #2
    Hi, EquityTrader thanks for posting.

    The method from Ray and your method will both work to determine the last bar of the chart. The historical data is loaded before OnBarUpdate is called and will not change after it is loaded.

    Best regards,
    -ChrisL

    Comment


      #3
      Hi ChrisL,

      Thanks for the fast response.

      Since you did not mention a StrategyBase property like "LastBarOnChart" I will operate under the assumption that it does not exist, and since you said my method will work, I will assume that you mean that it will work in any back-testing or real-time context and in any NinjaTrader 8 window.

      If my stated assumptions are wrong, please correct me.

      Thanks again!

      EquityTrader

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      62 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      134 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      75 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X