Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Coding a delay

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

    Coding a delay

    Hi all, I want to code a delay (in milliseconds) plot on bid ask.
    For example if my delay is 100 milliseconds, ask is 100 at t0 and it moves to 101 at t1, my plot it'll be 100 and change to 101 at t1+100 milliseconds.
    Thank you all

    #2
    Hello kantkant2,

    Scripts are event based and update when data is received. The script can Calculate OnEachTick, OnPriceChange, or OnBarClose, while OnMarketUpdate() will run on every market data update event.

    In real-time you could use a C# timer to delay actions, but this will not work in historical data.
    https://ninjatrader.com/support/foru...445#post496445
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      A timer would be the right way to accomplish this. You don't need to do this for historical data because you're describing something that only makes sense live.
      Bruce DeVault
      QuantKey Trading Vendor Services
      NinjaTrader Ecosystem Vendor - QuantKey

      Comment


        #4
        Originally posted by QuantKey_Bruce View Post
        A timer would be the right way to accomplish this. You don't need to do this for historical data because you're describing something that only makes sense live.
        Thanks Bruce and Chelsea.
        Yes I know a timer could be the right way, I tried lot of different tricks but I'm not able to make it.. I'm not so skilled on coding of course...
        Sorry do you have some easy example of a functioning delay under OnMarketData argument?
        Thanks a lot

        Comment


          #5
          Hello kantkant2,

          You could skip a market update, or use a counter to skip several market updates.

          Code:
          bool skipBar;
          
          protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
          {​
              if (skipBar == false)
              {
                  // trigger action here
              }
              skipBar = !skipBar;
          }
          Code:
          int updateCounter;
          
          protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
          {​
              if (updateCounter == 3)
              {
                  updateCounter = 0;
                  // trigger action here
              }
              else
              {
                  updateCounter++;
              }
          }
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            skipping a market update is not the same as a delay... am I wrong? my goal is to manage realtime bid ask quotes (without any skip) but with a delay of x milliseconds... if you imagine a plot of this dataseries, it's exactly the same as original bid/ask but with a delay on update of x milliseconds...

            Comment


              #7
              Hello kantkant2,

              MarketData is event driven not time driven.

              If you need something driven by time in milliseconds then you need a timer.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              596 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              343 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              556 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              554 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X