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

Combining two indicators - one compute on Tick by Tick another on bar close

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

    Combining two indicators - one compute on Tick by Tick another on bar close

    Hello Support,

    I need to combine two indicators into one. One necessarily compute on tick by tick basis. Another larger codes only need to compute on bar close. While it can be done, I do not want the bigger indicator to be processed tick by tick, as to avoid wasting so much CPU cycles. The issue is the variable FirstTickOfBar indicate a new bar is starting and another has just been closed, but at that point the BarsAgo index 0 is on the new bar which is just starting.
    If I do this using FirstTickOfBar on the larger codes, I would need to change all indexing +1 and take care non-existent yet bars. Which is going to be rather unwieldy, not to mention having two different branch of codes.

    Do you have another variable, perhaps called AfterCloseBeforeOpen ?
    What is your recommended way of doing it?

    Thanks.

    Regards.

    EdwardK.

    #2
    Edward, unfortunately the recommend way would be like you outlined : working in FirstTickOfBar with CalculateOnBarClose = false and referencing one bar back further then in this case.

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hello Bertrand,

      Looking ahead, would the approach be the same in NT7 ? Or Does NT7 have a better way?

      Thanks.

      EdwardK.

      Comment


        #4
        Hi Edward, the same approach would hold true for NT7.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Hello Support,

          Ok, this seems to work well.

          Now the next question is rather a strategy development.

          If the combined indicator (supposed to run tick by tick) is called within a Strategy that is also converted to run Tick by Tick, but the combined indicator is only called by the Strategy only FirstTickOfBar, would it work as expected ?
          If the answer is no, what would be the correct way and not wasting CPU cycles?

          (ie. The Strategy only produce orders at the close of bar, hence it only wants to know results of the indicator at the close of bar too, although the some code in the indicator will need to work tick by tick)

          Thanks.

          Regards.
          Edward K.

          Comment


            #6
            Hi Edward, the same approach would work in strategies as well, however if you reference / call indicators please ensure there's no CalculateOnBarClose hardcoded in the called script, this way the calling script can properly 'take control'.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Hello Bertrand,

              So you are saying although the Strategy called the Indicator only on FirstTickOfBar, that indicator is run tick by tick by NT, so long as the CalculateOnBarClose is false for that indicator instance.

              But where do I set this CalculateOnBarClose from the calling strategy? I do not see it on overload parameters set ?

              At the Indicator Initialize() function but not on the OnBarUpdate(), there is CalculateOnBarClose = true; is this considered HardCode?

              Thanks.

              Regards,

              EdwardK

              Comment


                #8
                Correct - you can set CalculateOnBarClose in the strategy's Initialize(), but you would need to remove it from the called indicator's Initialize() to avoid running into issues.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Hello Bertrand,

                  Further questions for confirmation:
                  1. So if an Indicator is to be run strictly OnBarClose, then at Indicator Initialize() should have CalculateOnBarClose = true; This way the indicator will still run OnBarClose basis although strategy sets CalculateOnBarClose = false; Correct ?

                  2. But for indicator that can be run Tick by Tick or OnBarClose, do not set CalculateOnBarClose() in Indicator Initialize().

                  3. For Indicator that strictly to be run Tick by Tick, one can set CalculateOnBarClose = false at Indicator Initialize().
                  Would this indicator still be run Tick by Tick if the strategy set CalculateOnBarClose = true?

                  Thanks.
                  Regards.
                  EdwardK.

                  Comment


                    #10
                    1. No. An indicator should not have any CalculateOnBarClose setting at all if it was going to be called and hosted in a strategy. Having this setting set will cause problems and result in incorrect values as called from the strategy.

                    If you want something strictly on the bar's close you would want to program it to be such. You can use if (FirstTickOfBar) then use indexes of [1] instead of [0] to get the close event. Remember, the opening of a bar is the exact same event as the closing of a bar.

                    2 and 3. Basically if your indicator is going to be hosted by the strategy, do not set any CalculateOnBarClose setting in the indicator ever. The setting will be taken from the strategy. If you want strategy on a bar close basis, but indicator on a tick by tick basis just set CalculateOnBarClose in the strategy to false and then program the strategy logic to use if (FirstTickOfBar) and [1] indexes.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello Josh,

                      This clarify the issue.

                      Thanks.

                      Regards.
                      EdwardK.

                      Comment


                        #12
                        Hello again,

                        From the modification I learnt that for my purpose my strategy can run OnBarClose with the rest of indicators called by it. The only place I need a few indicators to run TickByTick is for Visual purpose using the ADD feature.

                        I would think indicator initiated this way would be separate from the initiating Strategy, so it maybe possible to have it run TickByTick, while the rest strategy is on OnBarClose.
                        Is this possible ?
                        If so how do I set the OnBarClose property of the initiated Indicator plots?

                        Thanks.
                        Regards,

                        EdwardK

                        Comment


                          #13
                          EdwardK,

                          If the indicator is visualization only I *think* you can add the COBC settings into the indicator itself.

                          Otherwise you could maybe try something like this (no guarantees on this method either):
                          In Initialize():
                          Add(SMA(10));

                          In OnBarUpdate:
                          SMA(10).CalculateOnBarClose = false;
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            Hello Josh,

                            I did a simple test on the suggested second method with SMA.CalculateOnBarClose = false on the Strategy OnBarUpdate.
                            It works.

                            Thanks.

                            Regards.
                            EdwardK

                            Comment


                              #15
                              Hello Again,

                              Still on this subject, for the visual, I am wondering what is the recommended way to change bar color when we make decision on FirstTickOfBar for the BarsAgo == 1.

                              Thanks.

                              Regards.
                              EdwardK.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by geddyisodin, 04-25-2024, 05:20 AM
                              8 responses
                              60 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by jxs_xrj, 01-12-2020, 09:49 AM
                              4 responses
                              3,287 views
                              1 like
                              Last Post jgualdronc  
                              Started by Option Whisperer, Today, 09:55 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post Option Whisperer  
                              Started by halgo_boulder, 04-20-2024, 08:44 AM
                              2 responses
                              22 views
                              0 likes
                              Last Post halgo_boulder  
                              Started by mishhh, 05-25-2010, 08:54 AM
                              19 responses
                              6,189 views
                              0 likes
                              Last Post rene69851  
                              Working...
                              X