Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IsFirstTickOfBar bug

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

    IsFirstTickOfBar bug

    Hello NinjaTrader team, I noticed that when using Renko bars with isfirsttickofbar to check if a new bar has formed the if condition codes are exectued 3 times. if I switch to candle stick isfirsttickofbar works as expected; in that the codes are only called once.

    for example, when using Renko bar:
    protected override void OnBarUpdate()
    {
    if(IsFirstTickOfBar)
    Print("Hello");
    }


    >Hello
    >Hello
    >Hello

    for example, when using Candlestick bar:
    protected override void OnBarUpdate()
    {
    if(IsFirstTickOfBar)
    Print("Hello");
    }

    >Hello

    This is for a strategy using real data and calculate on each tick

    #2
    Hello kerlue,

    Welcome to the NinjaTrader forums!

    Thank you for reporting this behavior. I was able to reproduce and I've sent a report to our development.

    Once I have a tracking ID for this report I will post in this thread so you can keep an eye out for the fix in an upcoming release.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello kerlue,

      Thank you for your patience.

      This behavior is expected in the case of Bars Types that re-draw their open such as the Renko bars. These Bars Types use RemoveLastBar() to allow for re-drawing this function in turn calls OnBarUpdate() a second time.

      Any calcualtions based on the Open, High, Low, and Close of the bar would need to be re-calculated as well and thus the OnBarUpdate() function is called again, but let's say you do not wish to have another run of OnBarUpdate() for what you have already processed; you could then use CurrentBar and track the CurrentBar to ensure you do not re-process anything you don't want to in OnBarUpdate().

      For example:
      Code:
      private int MySavedCurrentBar = int.MinValue;
      
      protected override void OnBarUpdate()
      {
      if (CurrentBar == MySavedCurrentBar) return;
      MySavedCurrentBar == CurrentBar;
      }
      Please let me know if you have any questions.

      Comment


        #4
        Just a suggestion:

        Have a look at the code of the SMA. It also had to be recoded to comply with the new bar processing NinjaTrader 8 uses for Renko and Line Break bars.

        The code speaks for itself and tells you what you need to do to make indicators compatible with Renko and line break bars. Basically the bar processing for Renko bars in Calculate.OnEachTick is

        A - B - A - B - C - B - C - D - C - D - E - D - E - F etc.

        where conventional bar types are being processed

        A - B - C - D - E - F

        This means that each bar is visited three times and you may not pass on variables in IsFirstTickOfBar assuming that they have been processed by the prior bar. They may well have been processed by the consecutive bar....

        Well, have a look at the code of the SMA.

        Comment


          #5
          Thanks for the tip Harry,

          Going into some further detail on this suggestion, we can see that there are 2 code paths for BarsArray[0].BarsType.IsRemoveLastBarSupported and for when RemoveLastBar is not supported in the BarsType.

          When RemoveLastBar is supported in the BarsType, the original NT7 code is used since this code relies on relative data points.

          When RemoveLastBar is not supported, more efficient code is used that uses a temporary priorSum variable. This segment of code would be expected not to work with Renko bars because if the the bar is removed, priorSum would have an invalid value for the calculation.

          If there are any items withstanding that you would like further clarification on, please let us know.
          JimNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by GLFX005, Today, 03:23 AM
          0 responses
          1 view
          0 likes
          Last Post GLFX005
          by GLFX005
           
          Started by XXtrader, Yesterday, 11:30 PM
          2 responses
          11 views
          0 likes
          Last Post XXtrader  
          Started by Waxavi, Today, 02:10 AM
          0 responses
          6 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by TradeForge, Today, 02:09 AM
          0 responses
          14 views
          0 likes
          Last Post TradeForge  
          Started by Waxavi, Today, 02:00 AM
          0 responses
          3 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Working...
          X