Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question about CurrentBar

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

    Question about CurrentBar

    I just viewed the code example in CancelOrder(), and I feel confused about the use of barNumberOfOrder to remember CurrentBar at the time of order entry. Since the default max number of bars that Ninjatrader will remember is 256, after we load up the charts and start trading live, I would assume the chart is always full, and whenever a new incoming bar enters the DataSeries, the oldest one will be removed, therefore CurrentBar will always be 256 at that time. I think maybe a better way to do this is to use a DateTime to remember the time, and when enough time has passed, cancel the order. But how do we get the primary time frame's time per bar?

    private IOrder myEntryOrder = null;
    private int barNumberOfOrder = 0;

    protected override void OnBarUpdate()
    {
    // Submit an entry order at the low of a bar
    if (myEntryOrder == null)
    {
    myEntryOrder = EnterLongLimit(0, true, 1, Low[0], "Long Entry");
    barNumberOfOrder = CurrentBar;
    }

    // If more than 5 bars has elapsed, cancel the entry order
    if (CurrentBar > barNumberOfOrder + 5)
    CancelOrder(myEntryOrder);
    }

    #2
    Originally posted by zehua View Post
    I just viewed the code example in CancelOrder(), and I feel confused about the use of barNumberOfOrder to remember CurrentBar at the time of order entry. Since the default max number of bars that Ninjatrader will remember is 256, after we load up the charts and start trading live, I would assume the chart is always full, and whenever a new incoming bar enters the DataSeries, the oldest one will be removed, therefore CurrentBar will always be 256 at that time. I think maybe a better way to do this is to use a DateTime to remember the time, and when enough time has passed, cancel the order. But how do we get the primary time frame's time per bar?

    private IOrder myEntryOrder = null;
    private int barNumberOfOrder = 0;

    protected override void OnBarUpdate()
    {
    // Submit an entry order at the low of a bar
    if (myEntryOrder == null)
    {
    myEntryOrder = EnterLongLimit(0, true, 1, Low[0], "Long Entry");
    barNumberOfOrder = CurrentBar;
    }

    // If more than 5 bars has elapsed, cancel the entry order
    if (CurrentBar > barNumberOfOrder + 5)
    CancelOrder(myEntryOrder);
    }
    That is misunderstood. NT holds (by default), 256 values for any DataSeries, not for the chart's BarSeries, or for Plots: those hold all values.

    Comment


      #3
      Ok. But this doesn't address my question. My question is that we know the DataSeries holds 256 values, so that means CurrentBar value will always be 255?

      Comment


        #4
        Originally posted by zehua View Post
        Ok. But this doesn't address my question. My question is that we know the DataSeries holds 256 values, so that means CurrentBar value will always be 255?
        No. CurrentBar is part of the BarSeries, not a DataSeries. That was the answer to the question.

        Comment


          #5
          Well, according to this definition:
          A number representing the current bar in a Bars object that the OnBarUpdate() method in an indicator or strategy is currently processing. For example, if a chart has 100 bars of data, the very first bar of the chart (left most bar) will be number 0 (zero) and each subsequent bar from left to right is incremented by 1.

          CurrentBar is just an index of an array. Therefore when the chart is full with 256 bars, CurrentBar will always be 255? That is my question.

          Comment


            #6
            Originally posted by zehua View Post
            Well, according to this definition:
            A number representing the current bar in a Bars object that the OnBarUpdate() method in an indicator or strategy is currently processing. For example, if a chart has 100 bars of data, the very first bar of the chart (left most bar) will be number 0 (zero) and each subsequent bar from left to right is incremented by 1.

            CurrentBar is just an index of an array. Therefore when the chart is full with 256 bars, CurrentBar will always be 255? That is my question.
            I do not know how else to put it. A Bars object is NOT a DataSeries, so no limits that apply to a DataSeries necessarily apply to a Bars object. The 2 are independent entities.

            Comment


              #7
              A simple test would would answer this.

              Do you need help coding it?



              Originally posted by zehua View Post
              Well, according to this definition:
              A number representing the current bar in a Bars object that the OnBarUpdate() method in an indicator or strategy is currently processing. For example, if a chart has 100 bars of data, the very first bar of the chart (left most bar) will be number 0 (zero) and each subsequent bar from left to right is incremented by 1.

              CurrentBar is just an index of an array. Therefore when the chart is full with 256 bars, CurrentBar will always be 255? That is my question.

              Comment


                #8
                Thanks! I can code it myself.

                Comment


                  #9
                  Originally posted by koganam View Post
                  I do not know how else to put it. A Bars object is NOT a DataSeries, so no limits that apply to a DataSeries necessarily apply to a Bars object. The 2 are independent entities.
                  Got you. Thanks!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Aviram Y, Today, 05:29 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post Aviram Y  
                  Started by quantismo, 04-17-2024, 05:13 PM
                  3 responses
                  25 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by ScottWalsh, 04-16-2024, 04:29 PM
                  7 responses
                  34 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by cls71, Today, 04:45 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post cls71
                  by cls71
                   
                  Started by mjairg, 07-20-2023, 11:57 PM
                  3 responses
                  216 views
                  1 like
                  Last Post PaulMohn  
                  Working...
                  X