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


        #4
        Are you using the Stopwatch efficiently in .NET?
        Check out the ABP Framework here: https://bit.ly/3FgwZLuJoin the NDC Conferences Giveaway: https://mailchi.mp/nickchapsas/ndcCheck out my courses: https://do...

        Comment


          #5
          Hello All, Hope you are well, I have a quick question! I am developing an indicator that can use Tick Replay to get the Delta values of bars. I have already developed the Bid/Ask Delta. I am having issues calculating the UpDownTick Delta. I have tried all the combinations I could think of, closest I came to the actual

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by tkaboris, Today, 07:53 PM
          0 responses
          1 view
          0 likes
          Last Post tkaboris  
          Started by JGriff5646, Yesterday, 05:47 PM
          2 responses
          20 views
          0 likes
          Last Post JGriff5646  
          Started by lezlebric, Today, 06:32 PM
          0 responses
          12 views
          0 likes
          Last Post lezlebric  
          Started by TheTechnician86, Today, 05:47 PM
          0 responses
          9 views
          0 likes
          Last Post TheTechnician86  
          Started by Ryan333, Today, 05:25 PM
          0 responses
          6 views
          0 likes
          Last Post Ryan333
          by Ryan333
           
          Working...
          X