Market Meanness Index

Discussion in 'Technical Analysis' started by jcl366, Jul 27, 2014.

  1. jcl366

    jcl366

    Every algorithmic trader has to invent an indicator sooner or later, so here's now my contribution, the Market Meanness Index :). Here's the algorithm in C, applied to a data series:

    Code:
    double MMI(double *Data, int TimePeriod)
    {
    	double m = Median(Data,TimePeriod);
    	int i, nh=0, nl=0;
    	for(i=1; i < TimePeriod; i++) {
    		if(Data[i] > m && Data[i] > Data[i-1])
    			nl++;
    		else if(Data[i] < m && Data[i] < Data[i-1])
    			nh++;
    	}
    	return 100.*(nl+nh)/(TimePeriod-1);
    }
    As the name says, this indicator measures the meanness of the market. The theory behind it is this: In a completely uncorrelated price series, the probability of a price to revert to the mean is exactly 75%. That means if the current price is above the median price, the next price will be below the current price; and if the current price is below the median price, the next price will be above the current price. This rule is fulfilled for 75% of all prices of an uncorrelated price series. The proof of the 75% is relatively easy. The price distribution does not matter for the proof, it needs not be Gaussian.

    Real prices however are more or less autocorrelated, so the probability of a real price series to revert to the mean is less than 75%, but normally more than 50%. The higher it is, the meaner is the market.

    How can this be used for trading? The meanness index can determine when trend following systems become more profitable (market gets less mean) or less profitable (market gets meaner).
     
  2. Interesting indicator.
    Just glancing at the code :
    "for(i=1; i m && Data > Data[i-1])"
    I guess it is i<=m somewhere?
     
  3. jcl366

    jcl366

    Here's a practical example. It's an extremely simple trend following system, like the one from this thread:

    http://www.elitetrader.com/vb/showthread.php?t=249314

    First, the version without meanness filter:

    Code:
    double* Price = series(price());
    double* Trend = series(LowPass(Price,500));
    	
    Stop = 4*ATR(100);
    
    if(valley(Trend))
    	enterLong();
    else if(peak(Trend))
    	enterShort();
    The Lowpass filter, peak/valley and the rest are explained in the linked thread. And this is the profit curve - not too exciting:

    [​IMG]

    Now, we only trade when the market becomes less mean, i.e. the Market Meanness Index is falling. This is the code now:

    Code:
    double* Price = series(price());
    double* Trend = series(LowPass(Price,500));
    	
    Stop = 4*ATR(100);
    	
    double* Meanness = series(MMI(Price,200));
    double* Filter = series(LowPass(Meanness,500));
    	
    if(valley(Trend)) {
    	exitShort();  // close opposite position
    	if(falling(Filter))
    		enterLong();
    } else if(peak(Trend)) {
    	exitLong();
    	if(falling(Filter))
    		enterShort();
    }
    And this is the profit curve of the same system when market meanness is used for filtering trades:

    [​IMG]

    In this example the Market Meanness Index improves the average annual return from about 40% to about 200%. Enjoy!
     
  4. jcl366

    jcl366

    Smallstops: Never try to post some code with a "<" in it on this forum without special precautions. I forgot that...
     
  5. Thx for sharing. Not active in this forum anymore?