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.
        BertrandNinjaTrader Customer Service

        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.
            BertrandNinjaTrader Customer Service

            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.
                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by rocketman7, Today, 01:00 AM
                0 responses
                1 view
                0 likes
                Last Post rocketman7  
                Started by wzgy0920, 04-20-2024, 06:09 PM
                2 responses
                27 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, 02-22-2024, 01:11 AM
                5 responses
                32 views
                0 likes
                Last Post wzgy0920  
                Started by wzgy0920, 04-23-2024, 09:53 PM
                2 responses
                74 views
                0 likes
                Last Post wzgy0920  
                Started by Kensonprib, 04-28-2021, 10:11 AM
                5 responses
                193 views
                0 likes
                Last Post Hasadafa  
                Working...
                X