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.

    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

        Comment


          #5
          Much appreciated ChrisL. Thank you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          86 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          48 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          30 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          33 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          67 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X