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 benmarkal, Yesterday, 12:52 PM
          3 responses
          22 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by helpwanted, Today, 03:06 AM
          1 response
          17 views
          0 likes
          Last Post sarafuenonly123  
          Started by Brevo, Today, 01:45 AM
          0 responses
          11 views
          0 likes
          Last Post Brevo
          by Brevo
           
          Started by aussugardefender, Today, 01:07 AM
          0 responses
          6 views
          0 likes
          Last Post aussugardefender  
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          244 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Working...
          X