Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnMarketData Method

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

    OnMarketData Method

    Hello!
    How to use OnMarketData method in my strategy?
    Can I simply change OnBarUpdate() to OnMarketData without changing strategy conditions?
    When I tried to do this I have got only sell orders...
    My strategy use GetCurrentAsk/Bid.
    Last edited by Alexpl; 08-30-2012, 07:21 AM.

    #2
    Hello Alexpl,
    Unfortunately you cannot simply change OnBarUpdate to OnMarketData.

    OnBarUpdate and OnMarketData runs on different threads and thus GetCurrentAsk/Bid may be different for each event.

    If you want to use the Current Bid/Ask price in OnBarUpdate then simply set the property CalculateOnBarClose to false.


    If you need to calculate any specific values at the end of the bar, while other values in realtime, then you can use the FirstTickOfBar property to filter your logic. Please refer to this sample code which further demonstrates it.



    Also please refer to our help guide to know more about OnMarketData event
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Joydeep,

      A clarification is needed: you are saying that
      OnBarUpdate and OnMarketData runs on different threads
      .

      Do you mean that these handlers may be executed at the same moment (i.e. strategy must protect variables from concurrent usages) OR they are originated by different threads but are marshalled into strategy, i.e. a strategy is always single-threaded (unless additional threads are created by user)

      Thank you.

      Comment


        #4
        Alex, they will run different threads, but if you stay within the supported NinjaScript scope you would not have to worry about parallel processing, as all NinjaScript would be handled in the main program thread by NT's core. What you need to be aware of though is that's there's no guaranteed event sequence for this handles, as to when they are called in their relation, so for example OnMarketData() always before the OnBarUpdate() or vice versa.

        Comment


          #5
          Great, that's exactly what I thought and would like to confirm. Thank you.

          Comment


            #6
            You're welcome Alex, to further add - we would still suggest making sure to develop your custom code thread safe, so it's prepared for potential threading changes.

            Comment


              #7
              You made me start, Bertrand.
              Are you saying there are upcoming changes in a way how NT treats OnBarUpdate/OnOrderUpdate/etc handlers?

              Comment


                #8
                Yes, I probably did - but your interpretation was not my intention here, I just felt it good to add that we always have recommend developing code thread safe so you're prepared for potential changes in this area.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                77 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                45 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                27 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                32 views
                0 likes
                Last Post TheRealMorford  
                Started by Mindset, 02-28-2026, 06:16 AM
                0 responses
                63 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Working...
                X