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

Strategies process Bars object differently than Indicators

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

    Strategies process Bars object differently than Indicators

    I opened two identical ES 1 Minute chart windows and set them with the following parameters:

    Load data based on = Bars
    Bars to load = 500

    I then added an indicator to the first chart and a strategy to the second chart.

    Both indicator and strategy are merely adding two Bars objects (each).

    The indicator-loaded chart held all three Bars objects with 500 bars each, as expected, but for some reason, the strategy-loaded chart held three Bars objects with different numbers of bars for each Bars object.

    Also, at the strategy-based chart, the evaluation of OnBarUpdate() was arbitrary and did not occur at a certain order between all Bars objects and a lot of bars from the added Bars objects were not evaluated by it.

    Attached are two scripts, "A01" is an indicator and "A02" is a strategy.

    Please help me understand why wasn't the number of bars equal between Bars objects when using strategy and how to fix it and also how to avoid the situation where bars from added Bars objects are not being evaluated.

    Thank you very much for your time guys.
    Attached Files
    Last edited by savekad; 10-07-2012, 11:28 PM.

    #2
    I haven't looked at your code, but I imagine you have prints in there to compare.

    I bet you will see a 3rd "imaginary chart" that would match.

    Add a 3rd strategy to the Strategy Tab in control center, set the # of days to load as the same in the chart.

    I think this one will match your first indicator setup.




    Originally posted by savekad View Post
    I opened two identical ES 1 Minute chart windows and set them with the following parameters:

    Load data based on = Bars
    Bars to load = 500

    I then added an indicator to the first chart and a strategy to the second chart.

    Both indicator and strategy are merely adding two Bars objects (each).

    The indicator-loaded chart held all three Bars objects with 500 bars each, as expected but for some reason, the strategy-loaded chart help three Bars objects with different numbers of bars for each Bars object.

    Also, at the strategy-based chart, the evaluation of OnBarUpdate() was arbitrary and did not occur at a certain order between all Bars objects and a lot of bars from the added Bars objects were not evaluated by it.

    Attached are two scripts, "A01" is an indicator and "A02" is a strategy.

    Please help me understand why wasn't the number of bars equal between Bars objects when using strategy and how to fix it and also how to avoid the situation where bars from added Bars objects are not being evaluated.

    Thank you very much for your time guys.

    Comment


      #3
      Sorry, I didn't quite understand your suggestion. I would like to have two extra Bars objects loaded via the strategy. The thing is that their number of bars is critical. It should be controllable and if not, then it should at least be the same as the base chart.

      Comment


        #4
        Is that possible?

        Comment


          #5
          savekad,

          You cannot force X number of bars to load from a secondary series. Beginning at the first bar on your chart, in a multi-series script it will try to build the bars for all series and will be successful if you have the historical data for the multiple other series saved on your PC.

          There are some other things to keep in mind, such as it wouldnt usually occur to have 10 daily bars and 10 minute bars loaded since in 10 minutes 10 days have not yet passed.

          I would suggest reading this to understand how bars are used in multi-series scripts.

          Adam P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by savekad View Post
            I opened two identical ES 1 Minute chart windows and set them with the following parameters:

            Load data based on = Bars
            Bars to load = 500

            I then added an indicator to the first chart and a strategy to the second chart.

            Both indicator and strategy are merely adding two Bars objects (each).

            The indicator-loaded chart held all three Bars objects with 500 bars each, as expected, but for some reason, the strategy-loaded chart held three Bars objects with different numbers of bars for each Bars object.

            Also, at the strategy-based chart, the evaluation of OnBarUpdate() was arbitrary and did not occur at a certain order between all Bars objects and a lot of bars from the added Bars objects were not evaluated by it.

            Attached are two scripts, "A01" is an indicator and "A02" is a strategy.

            Please help me understand why wasn't the number of bars equal between Bars objects when using strategy and how to fix it and also how to avoid the situation where bars from added Bars objects are not being evaluated.

            Thank you very much for your time guys.
            This is what savekad is seeing.


            Code:
            A01 BarsArray holds 3 bars objects
            A01 BarsArray[0] holds 500 bars
            A01 BarsArray[1] holds 500 bars
            A01 BarsArray[2] holds 500 bars
             
            **NT** Disabling NinjaScript strategy 'A02/8f017deff1704b0b82f8d0f3ce775a58'
            **NT** Enabling NinjaScript strategy 'A02/8f017deff1704b0b82f8d0f3ce775a58' : On starting a real-time strategy - 
             
            
            A02 BarsArray holds 3 bars objects
            A02 BarsArray[0] holds 500 bars
            A02 BarsArray[1] holds 1381 bars
            A02 BarsArray[2] holds 693 bars

            Comment


              #7
              Hello,

              Thanks for clarifying, I'll check into this more.
              Adam P.NinjaTrader Customer Service

              Comment


                #8
                Adam, the thing is that when using an indicator the number of bars for each bars object is equal and the OBU() iterate each and every bar in each bars object. This is not the case when using an identical strategy code. OBU() missed a lot of bar evaluations of the added bars objects bars.

                Comment


                  #9
                  savekad,

                  I am not able to replicate this loading data based on days, I get the following :

                  Strategy :

                  BarsArray holds 3 bars objects
                  BarsArray[0] holds 89 bars
                  BarsArray[1] holds 1040 bars
                  BarsArray[2] holds 522 bars

                  Indicator :

                  BarsArray holds 3 bars objects
                  BarsArray[0] holds 89 bars
                  BarsArray[1] holds 1040 bars
                  BarsArray[2] holds 522 bars

                  However I have the chart set to load bars based on Days. For load data based on Bars here :

                  Strategy :

                  BarsArray holds 3 bars objects
                  BarsArray[0] holds 500 bars
                  BarsArray[1] holds 1041 bars
                  BarsArray[2] holds 522 bars

                  Indicator :

                  BarsArray holds 3 bars objects
                  BarsArray[0] holds 500 bars
                  BarsArray[1] holds 500 bars
                  BarsArray[2] holds 500 bars

                  It appears that this 'Load data based on bars' is forcing the indicator to load 500 of each. Note that expected behavior is you will NOT have the same number of bars in each series for multi-series scripts. This is because for example over a set range of time there may be 200 - 5 minute bars, but this is only 100 - 10 minute bars.

                  I will need to check with development on the "Load data based on bars" issue here, as this seems to change behavior.
                  Adam P.NinjaTrader Customer Service

                  Comment


                    #10
                    The behavior when using bars and not days, as well as using indicator and not strategy, is the result I am after. Basically I am after it just because I want OBU() of the strategy to iterate through all the bars of all added bars object and it didn't. That's the most important thing I need to troubleshoot.

                    Comment


                      #11
                      Attached is an example of a lot of missed OBU() calls for added bars objects.

                      Thank you for your help. I will wait for your update.

                      ** This code was loaded on a chart where 'Load data based' on is set to 'Days' as you said.
                      Attached Files

                      Comment


                        #12
                        savekad,

                        It looks like this behavior is expected at this time. Development is working on ways to resolve.

                        For now I would suggest using "load data based on" set to "Days". I understand you have some specific requirements for NinjaTrader, however note that BarsArray was not designed to have the exact same number of bars for each added instrument or timeframe.
                        Adam P.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Adam and thanks for replying.

                          I will be able to live with data based on days if I will be able to resolve the issue where OBU() does not fully iterates the bars of added Bars object.

                          Please refer to the code I supplied for a brighter example.

                          Tell me what you think.

                          Comment


                            #14
                            Savekad,

                            The number of OnBarUpdate() calls will not match the number of elements stored in the BarsArray object. This is because the historical data is available in the BarsArray object, but the strategy is waiting for all the historical data requirements (such as min bars required) to be satisfied before it starts calling OnBarUpdate(). The historical data is available there, but the number OnBarUpdate() calls won't necessarily match.

                            You can sort of see what is going on here.

                            bars 0 94
                            bars 1 1831
                            bars 2 1099

                            calls 1
                            calls0 1
                            calls1 0
                            calls2 0

                            bars 0 94
                            bars 1 1831
                            bars 2 1099

                            calls 2
                            calls0 1
                            calls1 1
                            calls2 0

                            bars 0 94
                            bars 1 1831
                            bars 2 1099

                            calls 3
                            calls0 1
                            calls1 1
                            calls2 1
                            Notice the first OnBarUpdate is called on the primary series, then the secondary, then the third. You need to have 60 minutes of data to get the first OnBarUpdate() call for the first series (I am using a 60 minute chart with your code), but NinjaTrader also loads additional data for the second and third series into the past. The BarsArray has data further into the past available, but each OnBarUpdate() is guaranteed to cover the bars available on your chart from the time it starts these calls. What is happening is there is data that exists in these series from BEFORE the first OnBarUpdate() call.

                            In other words there are not any missing bars, its just that it's starting the on bar update call at a period of time after what is available initially in the BarsArray object.

                            If you need data beginning only at the first OnBarUpdate calls I would suggest using your own series to store this.
                            Last edited by NinjaTrader_AdamP; 10-09-2012, 07:04 AM.
                            Adam P.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi Adam. I understand your explanation.

                              You mentioned that there are certain requirements to meet before OBU starts to fire.

                              I have noticed that when I set Required Bars to '0', OBU evaluates all bars of the first BarsArray.

                              However, this is not the case with the second and the third objects.

                              Is it possible to include all bars of the other BarsArray objects in the OBU evaluation by setting a 'Required Bars = 0' to the other objects or by any other way?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by warpinator, 05-16-2024, 10:44 AM
                              7 responses
                              47 views
                              0 likes
                              Last Post ETFVoyageur  
                              Started by Skifree, Today, 11:47 AM
                              1 response
                              7 views
                              0 likes
                              Last Post Skifree
                              by Skifree
                               
                              Started by ETFVoyageur, Today, 10:34 AM
                              3 responses
                              12 views
                              0 likes
                              Last Post ETFVoyageur  
                              Started by StefanA, Today, 11:24 AM
                              2 responses
                              7 views
                              0 likes
                              Last Post StefanA
                              by StefanA
                               
                              Started by Austiner87, Today, 11:19 AM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X