Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

FirstTickOfBar error?

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

    FirstTickOfBar error?

    I am using this code:

    if ( FirstTickOfBar )
    Print (CurrentBar+" FirstTickOfBar xxx "+Time[0] );

    and get the result shown in the screenshot attached.

    How can the first tick occur on the same bar more than once...and at two different times?

    Thanks.
    Attached Files

    #2
    Please provide all info required to reproduce he problem.

    Comment


      #3
      got your message re ticks...

      actually running on a 500 vol bar chart....meaning it switches bars during the trade so both closing bar and opening bar are on same tick

      makes sense....will need to adjust for that

      thanks

      Comment


        #4
        I assume you can not use FirstTickOfBar for volume charts, right?

        I need instead to check CurrentBar against 'activeBar' and if different, then that is the first tick of a new bar

        For instance, if you create a 250 volume chart and run a strategy that increases a barcounter variable using FirstTickOfBar...and on each first tick you print both the barcounter and CurrentBar, you will see that the barcounter increases faster than CurrentBar...therefore it is triggering at the start of each bar and also at the end of each bar in which the volume flows over to the new bar..i.e. counting twice

        Is this something that could be or should be fixed at NT's end rather me using an active bar variable as stated above?

        thanks.

        Comment


          #5
          Not sure I follow. Are you saying FirstTickOfBar does not work for volume bars?

          Comment


            #6
            yes... i am saying that...

            run the test per below and you will see that for vol bars that carry the vol over to the next new bar will trigger FirstTickOfBar on BOTH the close of the old bar and the start of the new bar

            i had to change the code as follows in all my indicators and strategies to check for CurrentBar change instead

            ..........in variables...............
            // workaround FirstTickOfBar issue
            private bool myFirstTickOfBar = false;
            private int activeBar = 0;

            .........first code run each tick
            protected override void OnBarUpdate() {
            if ( CurrentBar < 1 )
            return;
            if ( activeBar != CurrentBar ){
            activeBar = CurrentBar;
            myFirstTickOfBar = true;
            }

            ....last code run each tick
            myFirstTickOfBar = false;//end of first tick
            } // END OnBarUpdate

            Comment


              #7
              We'll look into.

              Comment


                #8
                Hi ATI user !

                This is a bug, which will be fixed with the next update.

                Thanks for reporting,
                Christian
                ChristianSenior Software Developer

                Comment


                  #9
                  Originally posted by NinjaTrader_Christian View Post
                  Hi ATI user !

                  This is a bug, which will be fixed with the next update.

                  Thanks for reporting,
                  Christian
                  Hi,

                  Is this the same bug? The following executes twice per bar:

                  if (FirstTickOfBar)
                  {

                  string line = Time[0].ToString();
                  Print(line);
                  }
                  Time is the same at each print. But the second time it prints, in a more complex version preceding bar-based calculations are set to zero.

                  Thanks.

                  Comment


                    #10
                    Could be or it also could be accurate. How do you know its the same bar?
                    RayNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by ntram, Yesterday, 05:39 PM
                    1 response
                    10 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by bmarovets, Yesterday, 06:33 PM
                    1 response
                    14 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by FishTrade, Yesterday, 03:42 PM
                    1 response
                    12 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by giulyko00, Yesterday, 11:49 AM
                    3 responses
                    23 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by ttrader23, Yesterday, 09:04 AM
                    3 responses
                    17 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Working...
                    X