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

Strategy OnBarUpdate misses first bars.

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

    Strategy OnBarUpdate misses first bars.

    Hello.

    Can you check this strategy code?


    Code:
    protected override void Initialize()
    {
        BarsRequired         =    0;
        CalculateOnBarClose =     false;
     }
    
     bool fr =false;
            
     protected override void OnBarUpdate()
     {
         if(!fr)
         {
            fr = true;
            Print(CurrentBars[0]);
          }
     }
    When I run it on 1 tick chart I'm expecting to see "0" in the output, but I see "42".


    Is it correct behavior?

    #2
    Hello blekdzhon,

    Thank you for your note.

    In the output window, the first print you are seeing is 0, what is the last print?j

    If you apply the strategy to a daily chart with 50 bars, do you see the same behavior?

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hi


      The last print depends on how much bars were loaded. It is correct.


      On daily chart with 50 bars it prints "0", and this is correct.

      Comment


        #4
        Hello blekdzhon,

        There is a limit how many values the output window will hold.

        In the scenario where you are seeing 42, what is the final number you are seeing?

        I look forward to your reply.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          I don't see any other values in the output except the first one.
          This is how my code works it shows only first bar index.


          Do you want me to change code and print all values?

          Comment


            #6
            Hello blekdzhon,

            Sure. Please export the full script in the format below and also include the version of NT7 you are on which you can find under Control Center>Help>About. Also include the instrument and the data provider you are testing on.

            To export a NinjaScript from NinjaTrader 7 do the following:
            From the Control Center window select File -> Utilities-> Export NinjaScript...
            Select the file in the left column then click “>”, then press export and name the file.
            Then attach that file you saved; under My Docs>NT7>Bin>Custom>Select the downloaded .zip file.

            I look forward to your reply.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              NinjaTrader 64-bit 7.0.1000.38.
              ES 09-18, 1 tick period.
              CQG Continuum.


              I attached strategy .zip file.


              When I changed code to print all bar indices the last value was "250920".
              Attached Files

              Comment


                #8
                Hello blekdzhon,

                I am unable to replicate.

                What is it you are trying to accomplish?

                I look forward to your reply.
                Alan P.NinjaTrader Customer Service

                Comment


                  #9
                  I need all tick bars from the begining to the end.
                  I want to use this data to create custom bars (for example 4 tick) equal to the standard bars.


                  If strategy doesn't process first bars in OnBarUpdate then my 4 tick bars would not be equal to NinjaTrader 4 tick chart with same time range.

                  Comment


                    #10
                    Hello blekdzhon,

                    If you reduce your days to load by 2, do you see 0 printed?

                    I look forward to your reply.
                    Alan P.NinjaTrader Customer Service

                    Comment


                      #11
                      I have 1 day on the chart.



                      Output shows "42".


                      If I reduce tick chart bars to 20 then it prints "0".
                      But if I set bars range to 21 then I have "3" in the ouput.

                      Comment


                        #12
                        Hello blekdzhon,

                        So I may best answer your question, would you please put together some pictures illustrating the issue please? The chart, the charts settings, the output window and the code beside it would be helpful.

                        To create screen shot,
                        Learn how to use Snipping Tool to capture a screenshot, or snip, of any object on your screen, and then annotate, save, or share the image.


                        I look forward to your reply.
                        Alan P.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by RubenCazorla, Today, 09:07 AM
                        2 responses
                        11 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by i019945nj, 12-14-2023, 06:41 AM
                        7 responses
                        81 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by timmbbo, 07-05-2023, 10:21 PM
                        4 responses
                        158 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by tkaboris, Today, 08:01 AM
                        1 response
                        7 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by Lumbeezl, 01-11-2022, 06:50 PM
                        31 responses
                        819 views
                        1 like
                        Last Post NinjaTrader_Adrian  
                        Working...
                        X