Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 177 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
Page 1 of 3 1 2 3
Market Meanness Index #443791
07/24/14 15:56
07/24/14 15:56
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
Every algorithmic trader has the duty to invent an indicator sooner or later, so here's now my contribution, the Market Meanness Index.

Code:
var MMI(vars Data,int TimePeriod)
{
	var 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 that 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.

Real prices 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). For instance, you can use the rise or fall of the MMI to filter out unprofitable periods in the simple trend following system of workshop 4:

Code:
function run()
{
	vars Price = series(price());
	vars Trend = series(LowPass(Price,500));
	
	Stop = 4*ATR(100);
	
	vars Meanness = series(MMI(Price,200));
	vars 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();
	}
}



Here's the profit curve without meanness filter - AR 40%:



And here with meanness filter - AR 200%:



Enjoy!

Re: Market Meanness Index [Re: jcl] #443792
07/24/14 16:44
07/24/14 16:44
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline
Serious User
DdlV  Offline
Serious User
D

Joined: Jun 2013
Posts: 1,609
Way cool! Thanks, and Congratulations! laugh

Re: Market Meanness Index [Re: DdlV] #443803
07/24/14 19:53
07/24/14 19:53
Joined: May 2013
Posts: 627
Bonn
Sundance Offline
User
Sundance  Offline
User

Joined: May 2013
Posts: 627
Bonn
Really nice one JCL!! cool

Re: Market Meanness Index [Re: Sundance] #445558
09/13/14 08:52
09/13/14 08:52
Joined: Apr 2014
Posts: 482
Sydney, Australia
B
boatman Offline
Senior Member
boatman  Offline
Senior Member
B

Joined: Apr 2014
Posts: 482
Sydney, Australia
Hi JCL,

Thanks for the indicator! This may be a silly question, but I wasn't able to find an answer in the manual or the forum. Is it possible to add the MMI code to the indicators.c file so that it is available to be called in any Zorro script? If so, how does one do this? I have tried copying it directly, but can't seem to get it to work. The Zorro GUI gives me the message: "Unidentified fucntion: MMI"

Thanks again!

Re: Market Meanness Index [Re: boatman] #445565
09/13/14 19:02
09/13/14 19:02
Joined: Dec 2013
Posts: 568
Fuerth, DE
Sphin Offline
User
Sphin  Offline
User

Joined: Dec 2013
Posts: 568
Fuerth, DE
Take a look at the "What's new" of the manual: MM will be part of the indicator library as of version 1.26. We only need to be patient let's say one or two months.:)

Re: Market Meanness Index [Re: Sphin] #445567
09/13/14 19:49
09/13/14 19:49
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline
Serious User
DdlV  Offline
Serious User
D

Joined: Jun 2013
Posts: 1,609
Hi boatman. Where did you paste it into indicators.c? At the end? Before the #endif's?

Re: Market Meanness Index [Re: DdlV] #445568
09/13/14 22:04
09/13/14 22:04
Joined: Apr 2014
Posts: 482
Sydney, Australia
B
boatman Offline
Senior Member
boatman  Offline
Senior Member
B

Joined: Apr 2014
Posts: 482
Sydney, Australia
Thanks for the responses!

After the line

#ifdef INDICATORS_H

I pasted

var MMI (vars Data, int TimePeriod);

The after

#else
//Helper functions and and definitions

I pasted the code for the MMI.

Re: Market Meanness Index [Re: boatman] #445569
09/13/14 22:08
09/13/14 22:08
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline
Serious User
DdlV  Offline
Serious User
D

Joined: Jun 2013
Posts: 1,609
Hi boatman. It works for me if I just paste the whole MMI from above in between the 2 #endif's.

HTH.

EDIT: But I think the right way is to put it above both #endif's and duplicate the definition line above the #else, adding the ";". laugh

Re: Market Meanness Index [Re: DdlV] #445576
09/15/14 00:25
09/15/14 00:25
Joined: Apr 2014
Posts: 482
Sydney, Australia
B
boatman Offline
Senior Member
boatman  Offline
Senior Member
B

Joined: Apr 2014
Posts: 482
Sydney, Australia
Thanks DdlV, much appreciated!

Re: Market Meanness Index [Re: boatman] #445727
09/22/14 08:58
09/22/14 08:58
Joined: Jul 2013
Posts: 110
B
bfleming Offline
Member
bfleming  Offline
Member
B

Joined: Jul 2013
Posts: 110
And be extension, wouldn't it make sense to filter counter-trend strategies to trade when the market is more mean?

Page 1 of 3 1 2 3

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1