Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Request: rename CurrentBar -> to LastBarNumber

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

    #16
    [untested, but should work]

    Code:
    namespace NinjaTrader.Strategy
    {
          public static class Extensions
          {
                public static int ToBarsAgo(this int BarNum, Object Instance)
               {
                     Strategy s = Instance as Strategy;
                     return s.CurrentBar - BarNum;
               }
         }
    }
    Save your important bar number into some variable,

    Code:
    int SaveBar = CurrentBar;
    then later use the extension method to get the BarsAgo index,

    Code:
    Print("SaveBar occured " + SaveBar.ToBarsAgo(this) + " bars ago");
    very C# oop-ish looking ...

    Comment


      #17
      There is a slight danger to relying on the proposed methods to adjust bars ago. In the instances where the series was created with a maximum lookback of 256 bars, you'll get an exception if you try to look at a saved bar greater than that period. This would come into play if you are tracking a long trend for example.

      Comment


        #18
        Strongly agree with Brett. The CurrentBar is NOT the last bar.

        The last bar as far as I am concerned is the last bar on the chart, ie the one with bar number of LastBarIndexPainted, or ChartBars.ToIndex.

        When you scroll backwards on a chart the number of bars back that you are from the last bar is ChartBars.ToIndex minus CurrentBar. This is commonly needed for custom price markers. In this case how could you say that the CurrentBar is the last bar? The CurrentBar is the last bar showing in the chart panel but certainly not the last bar on the chart.
        Last edited by Ricam; 10-17-2015, 10:03 AM.

        Comment


          #19
          Hello Ricam,

          CurrentBar is the last bar of the bar series. This would be used for calculations where we need to find a bars ago index. CurrentBar minus saved bar number, this will return the bars ago value to be used for indexing.

          ChartBars.ToIndex is the last bar of the bar series that is visible on the chart.

          ChartBars.ToIndex is not going to work for finding the bars ago value of a saved bar number.
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by trilliantrader, 04-18-2024, 08:16 AM
          4 responses
          18 views
          0 likes
          Last Post trilliantrader  
          Started by mgco4you, Today, 09:46 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by wzgy0920, Today, 09:53 PM
          0 responses
          9 views
          0 likes
          Last Post wzgy0920  
          Started by Rapine Heihei, Today, 08:19 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by Rapine Heihei, Today, 08:25 PM
          0 responses
          10 views
          0 likes
          Last Post Rapine Heihei  
          Working...
          X