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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    47 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    22 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    15 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    21 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    23 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X