Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unsubscribe from OnMarketData in real-time

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

    Unsubscribe from OnMarketData in real-time

    Hello,

    I have an indicator that does, sometimes requires tick by tick bid / ask prices, even if price has not changed For that, I use OnMarketData event. But, that is the only thing it is used for. Per the nt docs, I don't want this left in the code, even if empty. Should the bid / ask prices not be needed (I can use on price change which will be more efficient). Is there a way for my code to unsubscribe from the OnMarketData, even though it is declared in code? Idea being, if the bid / ask options are not checked in the indicator options, I can save precious NT resources by unsubscribing from OnMarketData once the indicator starts and then will not have a full stream of tick and bid ask changes etc. flowing that I do not need.

    Thanks.

    #2
    Hello pjsmith, thanks for your note.

    The OnMarketdata override is compiled into the script so there is nothing that could be done at runtime to unsubscribe from it. You can add boolean inputs to run code in OnMarketData based on if the boolean inputs are true, this way less code will run when OnMarketData is called.

    Kind regards.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks. I already return using a bool, but given the NT docs suggest leaving even an empty OnMarketData overide in your code can consume significant resources, I would have rather have removed this resource altogether. If I had no OnMarketData overide in the script at all, is there a way to programatically subscribe/unsubscribe to same data stream?

      Thanks.

      Comment


        #4
        Hi pjsmith, thanks for your reply.

        I was able to toggle OnMarketData in the attached code example. Be sure to only do that in State.RealTime and not State.Historical.
        Attached Files
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Much appreciated ChrisL. Thank you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by nicthe, Yesterday, 07:38 AM
          6 responses
          27 views
          0 likes
          Last Post WaleeTheRobot  
          Started by spencerp92, 10-10-2023, 09:56 AM
          5 responses
          317 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by flybuzz, Yesterday, 10:33 AM
          2 responses
          12 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Salahinho99, Yesterday, 04:13 AM
          1 response
          22 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by RamiRK86, Today, 08:05 AM
          1 response
          2 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X