Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnBarUpdate and OnMarketData used in one indicator?

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

    OnBarUpdate and OnMarketData used in one indicator?

    Hello,

    If I have an indicator that uses both OnBarUpdate and OnMarketData, and let’s say there is a sell and the price ticks down. This means that both of these methods will be triggered. I assume that OnMarketData will be triggered first and then the logic will jump to OnBarUpdate. Is this the case?

    Thanks,
    redduke

    #2
    OnBarUpdate() only triggers off of last price. OnMarketData() triggers off of all market data events. OnBarUpdate() will trigger for every last price market data event fired. Although I suspect OnBarUpdate() is called second in most cases, you can not guarantee that.
    RayNinjaTrader Customer Service

    Comment


      #3
      Hi Ray,

      Thanks for the reply. I took a look at one of Ninja 6.5 indicators – BuySellVolume. It uses both of these methods. OnMarketData is used to calculate buy and sell volume and then OnBarUpdate plots it into display, so it is important for one to follow the other, which I assume it does based on your reply, it least in most cases.

      Regards,
      redduke

      Comment


        #4
        I have experienced a weird behavior today, when I tried to see how OnMarketData performs. Below is the code that I used:

        protected override void OnBarUpdate()
        {
        Print(LastVolume);
        }

        protected override void OnMarketData(MarketDataEventArgs e)
        {
        if (e.MarketDataType == MarketDataType.Last)
        LastVolume = e.Volume;
        }

        When I opened Output window and placed it next to Time and Sales, I have notices that there was about 1-2 seconds delay of the LastVolume appearing there. In some cases it appeared at the same time as volume in T&S, but most of the time there was a small delay.

        Any idea why there is a lag?

        Thanks,
        redduke

        Comment


          #5
          Is the Time and Sales set to refresh based on a timer? If yes, this would account for the delay.
          RayNinjaTrader Customer Service

          Comment


            #6
            No, T&S is set to be refreshed with every tick, and it is the indicator with the logic below that lags. I thought that they should behave identically, am i wrong?

            Thanks,
            redduke

            Comment


              #7
              Thanks for clarification. Looks like OnBarUpdate() may trigger first before OnMarketData thus the event that is printing LastVolume is actually the next incoming tick.
              RayNinjaTrader Customer Service

              Comment


                #8
                Ray,

                Thanks for this info. This would explain another anomaly that I have seen. I have put BuySellVolume indicator on constant volume charts (200 volumes per bar), so I should have never seen BuySellVolume greater than 200 for each bar. However, this is exactly what happened. BuySellVolume showed volumes like 230, 220 and so on for some of the bars.

                Now since, OnMarketData is triggered after OnBarUpdate, it just grabbed the volume that was supposed to stay in the previous bar and added to the current bar as soon as current bar is created.

                Regards,
                redduke

                Comment


                  #9
                  Hi Ray & RedDuke,

                  I have noticed the same issues with the interaction between OnMarketData and OnBarUpdate.

                  If you add e.Time to your short example and then include the timestamp in the Print statement you will see that the delay you notice is actually a 1 trade lag.

                  Not sure why this happens - any ideas Ray?

                  Comment


                    #10
                    Hi Rt-trader,

                    OnMarkerData will be called whenever somethig changes on level1. OnBarupdate will be called only when there is a trade, in which case it will be called before OnMarketData. The solution that I found to be working is migrate most my indicator logic to OnMarketData. I am very excited since I can now capture time and sales in indicator without some not so perfect coding in OnBarUpdate.

                    Regards,
                    redduke

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by ntbone, Today, 02:30 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post ntbone
                    by ntbone
                     
                    Started by tuliomgui, Yesterday, 10:07 PM
                    3 responses
                    13 views
                    0 likes
                    Last Post NinjaTrader_ShawnB  
                    Started by Learner Trader, Today, 08:36 AM
                    1 response
                    24 views
                    0 likes
                    Last Post NinjaTrader_ShawnB  
                    Started by GeorgeW, Today, 03:15 AM
                    1 response
                    16 views
                    0 likes
                    Last Post NinjaTrader_ShawnB  
                    Started by timko, Today, 11:55 AM
                    4 responses
                    12 views
                    0 likes
                    Last Post NinjaTrader_ShawnB  
                    Working...
                    X