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
    Chris L.NinjaTrader Customer Service

    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 FishTrade, Today, 06:31 PM
      0 responses
      3 views
      0 likes
      Last Post FishTrade  
      Started by Perr0Grande, Today, 07:09 AM
      4 responses
      34 views
      0 likes
      Last Post Perr0Grande  
      Started by SheriDi, 04-25-2025, 02:24 PM
      3 responses
      49 views
      0 likes
      Last Post SheriDi
      by SheriDi
       
      Started by aligator, Today, 11:32 AM
      2 responses
      16 views
      0 likes
      Last Post aligator  
      Started by tradeologist, Today, 02:16 PM
      2 responses
      13 views
      0 likes
      Last Post tradeologist  
      Working...
      X