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 DJ888, Today, 10:57 PM
          0 responses
          2 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by MacDad, 02-25-2024, 11:48 PM
          7 responses
          158 views
          0 likes
          Last Post loganjarosz123  
          Started by Belfortbucks, Today, 09:29 PM
          0 responses
          7 views
          0 likes
          Last Post Belfortbucks  
          Started by zstheorist, Today, 07:52 PM
          0 responses
          7 views
          0 likes
          Last Post zstheorist  
          Started by pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          151 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Working...
          X