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

OnMarketData & Multi-timeframe

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

    OnMarketData & Multi-timeframe

    Hello,

    I am loading two dataseries from same instrument with differente timeframes, and I need compute the delta (ask-bid) of the bars of each serie.

    But the OnMarketData method is executed twice for the same tick (one per timeframe).

    Is there any way to distinguish if a tick has been already processed ? (No property like BarsPeriod or similar is accessible. And BarsInProgress is not reliable outside OnBarUpdate).

    Thanks in advance

    #2
    Hello cls71,

    Thank you for your note.

    If you check the volume for the 2nd tick, does it return zero and thus allow you to filter these out by specifying a minimum volume?

    See OnMarketData,


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

    Comment


      #3
      Hello Alan,

      I am testing in historical (with TickReplay enabled) and in real time.

      The trades (object of type Last) always have volume. It does not matter if the tick has already been processed in another timeframe; it is repeated with all its properties correctly assigned including the volume. A trade with volume equal to zero is never received.

      In historical, it is impossible to know for sure if the same trade has already been processed in another timeframe.

      It seems that in real time you can do a check to compare if the object is the same as the previous one to eliminate repetitions. But in historical it does not work. I'm also not sure if it would work well in real time for more than two timeframes since this feature is not documented.

      If you want, you can try this simple script to test it. For example, load the indicator on a chart of ES 09-18 Range 2 with TickReplay activated. The indicator adds a second timeframe of Range 4.

      Thanks
      Attached Files

      Comment


        #4
        Hello cls71,

        If you were to add the following at the top of OnMarketData, you could restrict your OnMarketData logic from only updating on BIP 0, which would prevent any other bar series from running OnMarketData,

        if(BarsInProgress!= 0) return;

        Would the above solution work for you?

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

        Comment


          #5
          Hello Alan,

          According to the documentation, OBU is always executed before OMD, but I do not know if a conflict with the multi-thread may arise that causes the BIP value to be unreliable within OMD.

          For example, if I add three series for the same instrument and different timeframes: 0, 1 and 2. What would be the sequence of execution?

          1st - OBU-0
          2nd - OMD-0
          3rd - OBU-1
          4th - OMD-1
          5th - OBU-2
          6th - OMD-2


          Or, could the following happen?

          1st - OBU-0
          2nd - OBU-1
          3rd - OBU-2
          ************* <--- In this moment BIP would be worth 2 and would not serve to distinguish within the following OMDs.
          4th - OMD-0
          5th - OMD-1
          6th - OMD-2

          In this case, you could not use BIP within the OMD to know which series the event comes from.

          Comment


            #6
            Hello cls71,

            Could you provide more information on why the following would not be sufficient to filter out all updates but BIP0? What issue would you have writing your delta formula after if(BarsInProgress!= 0) return?

            To test you could change the 2nd and 3rd series added to the script to another series and see it only prints the primary series.

            protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
            {

            if( marketDataUpdate.MarketDataType != MarketDataType.Last ) return;

            if(BarsInProgress!= 0) return;

            Print("BIP"+marketDataUpdate.Last.ToString());


            }

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

            Comment


              #7
              Hello Alan,

              I want to calculate the delta of the bars in 3 different Timeframes.

              Therefore, I need to know the timeframe to which the tick belongs to compute it in the correct serie.

              If the following scenario were possible:
              1st - OBU-0 (TF-0)
              2nd - OBU-1 (TF-1)
              3rd - OBU-2 (TF-2)
              ************* <--- In this moment BIP would be worth 2 and would not serve to distinguish within the following OMDs.
              4th - OMD-0
              5th - OMD-1
              6th - OMD-2

              Then the first two OMD events (OMD-0 and OMD-1) would be wrongly computed in the same bar of the TF-2.

              Thanks.

              Comment


                #8
                Hello cls71,

                Would you be able to provide a sample which demonstrates why specifying the BarsInProgress for either OBU or OMD would not work? Would each three series of the same instrument not just return the exact same information 3 times in OMD?

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

                Comment


                  #9
                  Hello Allan,

                  I'll be careful if I detect any case to post it.

                  I think the whole problem can be summarized in one question:
                  In a multithreaded environment with multiple dataseries (multi-timeframe & multi-instrument), can I be sure that after executing the OBU of a dataserie the OMD of that same dataserie will always be executed next, and never the OBU or the OMD of another dataserie? If the answer is yes,then I can use BarsInProgress to distinguish within the OMD.

                  Thanks

                  Comment


                    #10
                    Hello cls71,

                    Yes, you could expect OMD to be called after OBU.

                    I put together a sample indicator which if you apply to a ES 09-18 chart with the output window open, you will see that in real time, the prints for Update will always alternate between OBU and OMD.

                    Please let us know if you need further assistance.
                    Attached Files
                    Alan P.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Alan,

                      I already know that with a single instrument it works well. My concern is with multi-timeframe, as I asked you in the previous post.

                      Originally posted by cls71 View Post
                      In a multithreaded environment with multiple dataseries (multi-timeframe & multi-instrument), can I be sure that after executing the OBU of a dataserie the OMD of that same dataserie will always be executed next, and never the OBU or the OMD of another dataserie? If the answer is yes,then I can use BarsInProgress to distinguish within the OMD.

                      Regards

                      Comment


                        #12
                        Hello cls71,

                        The sample I provided has an additional data series of 15 minutes.

                        Does the sample not demonstrate OBU is called before OMD?

                        If you modify the script to add even more series, does that change the behavior of the prints?

                        Please let us know if you need further assistance.
                        Alan P.NinjaTrader Customer Service

                        Comment


                          #13
                          Thansk Alan

                          Comment


                            #14
                            Great solution here

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by DJ888, 04-16-2024, 06:09 PM
                            6 responses
                            18 views
                            0 likes
                            Last Post DJ888
                            by DJ888
                             
                            Started by Jon17, Today, 04:33 PM
                            0 responses
                            1 view
                            0 likes
                            Last Post Jon17
                            by Jon17
                             
                            Started by Javierw.ok, Today, 04:12 PM
                            0 responses
                            6 views
                            0 likes
                            Last Post Javierw.ok  
                            Started by timmbbo, Today, 08:59 AM
                            2 responses
                            10 views
                            0 likes
                            Last Post bltdavid  
                            Started by alifarahani, Today, 09:40 AM
                            6 responses
                            41 views
                            0 likes
                            Last Post alifarahani  
                            Working...
                            X