Announcement

Collapse
No announcement yet.

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 Jeremytang, 07-14-2018, 06:45 PM
      21 responses
      439 views
      0 likes
      Last Post mav8rick  
      Started by LeonK, Yesterday, 09:26 PM
      1 response
      7 views
      0 likes
      Last Post bltdavid  
      Started by NicholasJoannette, Yesterday, 03:01 PM
      2 responses
      11 views
      0 likes
      Last Post NicholasJoannette  
      Started by rach1994, Yesterday, 12:20 PM
      1 response
      35 views
      0 likes
      Last Post bltdavid  
      Started by litamm89, Yesterday, 11:00 AM
      5 responses
      21 views
      1 like
      Last Post rafael_delima86  
      Working...
      X