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 junkone, Today, 11:37 AM
      0 responses
      1 view
      0 likes
      Last Post junkone
      by junkone
       
      Started by quantismo, 04-17-2024, 05:13 PM
      5 responses
      34 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by proptrade13, Today, 11:06 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by love2code2trade, 04-17-2024, 01:45 PM
      4 responses
      34 views
      0 likes
      Last Post love2code2trade  
      Started by cls71, Today, 04:45 AM
      2 responses
      10 views
      0 likes
      Last Post eDanny
      by eDanny
       
      Working...
      X