Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time since last bid/ask change

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

    Time since last bid/ask change

    Hello all,

    I'd like to keep a running exponential moving average of the time since the last bid/ask change.

    Would the following work?

    Code:
    double currentBid = 0;
    double currentAsk = 0;
    double priorBid = 0;
    double priorAsk = 0;
    double xmaBidImproveTime = 0;
    double xmaAskImproveTime = 0;
    double currentTime = 0;
    double priorTime = 0;
    
    protected override void OnMarketData(MarketDataEventArgs e)
    {
        if (e.MarketDataType == MarketDataType.Bid) currentBid = e.Price;
        else if (e.MarketDataType == MarketDataType.Ask) currentAsk = e.Price;
    
        currentTime = e.Time;
    
        if (currentBid != priorBid and currentAsk == priorAsk){
            if (xmaBidImproveTime == 0 && priorTime != 0) xmaBidImproveTime = currentTime - priorTime;
            else if (xmaBidImproveTime != 0 && priorTime != 0) xmaBidImproveTime = xmaBidImproveTime * .9 + (currentTime - priorTime) * .1;
    
            priorBid = currentBid;
            priorTime = currentTime;
    
        }
        else if (currentBid == priorBid and currentAsk != priorAsk){
            if (xmaAskImproveTime == 0 && priorTime != 0) xmaAskImproveTime = currentTime - priorTime;
            else if (xmaAskImproveTime != 0 && priorTime != 0) xmaAskImproveTime = xmaAskImproveTime * .9 + (currentTime - priorTime) * .1;
    
            priorAsk = currentAsk;
            priorTime = currentTime;
    
        }
    }
    Last edited by kaydgee; 10-05-2010, 04:44 PM.

    #2
    It seems you are applying just 2 weights for the current and last values? From a glance over it seems like it would be okay. You would need to test this on your end to ensure this to be the case though.
    Josh P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    633 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    364 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    567 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    568 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X