Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Get Speed of Price Change

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

    Get Speed of Price Change

    Is their a builtin method that allows one to get the speed at which a price changed? Not really bid/ask change but when a price is changed as a result of taking liquidity. Say bid is 10 and ask is 11. I don't care about the speed at which they trade at 10 or 11 I care about the price when it changes to 9 or 12.

    Any ideas to point me in the right direction would be appreciated.

    My first thought is to use OnMarketData and inside create a timer that starts a timer at say 10 and stops it when price goes to 9 or 12. It feels hackish but I also don't know how this timer will act in market replay when running at full speed.

    Thanks,

    #2
    Hi bc24fl, thanks for your post.

    I would not recommend doing this with the Time[] array on historical data as that uses DateTime objects which only have a 15 millisecond resolution, so it would not be accurate. You would need to use a stop watch like so:

    Code:
    private Stopwatch stopWatch = new Stopwatch();
    
    protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
            {
                stopWatch.Stop();
    
                TimeSpan ts = stopWatch.Elapsed;
                Print(String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                ts.Hours, ts.Minutes, ts.Seconds,
                ts.Milliseconds / 10));
                stopWatch.Reset();
                stopWatch.Start();
            }
    If you wanted to try this on historical data, you would run this code on a 1 tick series:

    Code:
    private DateTime TimeNow;
    private DateTime PreviousTime;
    
    ...
    
    else if(State == State.DataLoaded)
    {
        TimeNow = Time.GetValueAt(0);
        PreviousTime = Time.GetValueAt(0);
    }
    
    protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
    {
        if(CurrentBar < 1)
            return;
    
        TimeNow = Time[0];
        Print("Time since last OMD call:" + TimeNow.Subtract(PreviousTime).Milliseconds);
    
        PreviousTime = TimeNow;    
    }
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thank you. I guess i'll have to test this in realtime.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Brevo, Today, 01:45 AM
      0 responses
      3 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      3 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      239 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      384 views
      1 like
      Last Post Gavini
      by Gavini
       
      Started by oviejo, Today, 12:28 AM
      0 responses
      6 views
      0 likes
      Last Post oviejo
      by oviejo
       
      Working...
      X