MidPoint statistics - surprising results!
Posted: Sat May 27, 2006 12:55 pm
NOTE: if you can't see the attached graphs, please LOG IN.
Hello,
Avery de Rumpledone asked me to run some stats on his MidPoint trading concept.
I tested:
- one NASDAQ stock (YHOO, Yahoo)
- one CME future (@ES, CME E-Mini S&P 500 futures continuous contract)
- one forex pair (EURUSD)
in timeframes:
- 1 min
- 5 min
- 15 min
- 60 min
- 240 min (4h)
- daily
For the purposes of this test I am using the term "Zone". This term relates to the price area either above or below the previous bar's midpoint.
midpoint is defined as (high + low)/2
The rules for conducting the research:
1. if the current bar closes above the previous bar's midpoint, it closed in the upper Zone
2. if the current bar closes below the previous bar's midpoint, it closed in the lower Zone
3. if the current bar closes at the very price of the previous bar's midpoint, we assume that it closed in the same Zone as the previous bar did
The basic question to be answered in our research with respect to the terms introduced above is:
What is the probability that the next bar’s close price will end up in the same Zone or in the opposite Zone than the current bar’s close price if we know how many consecutive bars, including the current bar, has had the close price in the present Zone?
Of course, the probability that the next bar will close in the present Zone and the probability that it will close in the opposite Zone always adds up to 100% since the bar has to close in one of the two Zones.
Independent variable here is the number of consecutive bars in the same Zone. Dependent variable is the probability that the next bar will close either in the same or in the opposite Zone (1 or -1 in the code, see below).
In the graphs I don't show probability in %, but rather the actual number of observations (number of consecutive bars' sequences) so that you may have a better idea of what was the testing sample size for each symbol/timeframe.
For the research to be valid with my algorithm that tracks only absolute Zone changes instead of upper to lower / lower to upper Zone change, we assume that the price behaviour in this respect is symmetric, i.e. there's no significant statistical difference between the tendency to change from the upper Zone to the lower Zone and the tendency to change from the lower Zone to the upper Zone.
Indeed, I was curious about the results. My working hypothesis was that:
1. the price action will resemble Brownian motion in Zone change with only one or several consecutive closes in the same Zone (i.e. the Zone selection will be random in this case)
2. with the higher value of consecutive bars closing in the same Zone there will be a significant tendency towards either staying in the current Zone or towards changing the current Zone.
But, as with many other studies, the results were quite surprising and I would say, strangely accurate! I double checked my code (I encourage you to do the same), but couldn't find any flaw that would explain the weird numerical accuracy of the results. I will be glad if you find the flaw in my code!
Anyway, have a look at the resulting graphs by yourself.
Notes:
- I only picked 10 highest consecutive bars sequences for every graph
- all the sequences/observations you will find in the attached zip file "MidPoint_stats.zip"
- from the graphs it is clear that the probability that the observation will occur decreases exponentially in inverse proportion with the number of consecutive bars in the sequence
- orange value: Zone changed after n consecutive bars in the Zone (x axis)
- green value: Zone didn't change after n consecutive bars in the Zone (x axis)
- look at the probability of Zone change (orange) versus Zone stay (green)!
The conclusion:
There is no evidence that there is a significant statistical relation between the number of consecutive bars in the same Zone and the probability that the Zone will change or not change on the following bar.
The code I used for calculations (you may re-run the experiment by yourself):
Michal
Hello,
Avery de Rumpledone asked me to run some stats on his MidPoint trading concept.
I tested:
- one NASDAQ stock (YHOO, Yahoo)
- one CME future (@ES, CME E-Mini S&P 500 futures continuous contract)
- one forex pair (EURUSD)
in timeframes:
- 1 min
- 5 min
- 15 min
- 60 min
- 240 min (4h)
- daily
For the purposes of this test I am using the term "Zone". This term relates to the price area either above or below the previous bar's midpoint.
midpoint is defined as (high + low)/2
The rules for conducting the research:
1. if the current bar closes above the previous bar's midpoint, it closed in the upper Zone
2. if the current bar closes below the previous bar's midpoint, it closed in the lower Zone
3. if the current bar closes at the very price of the previous bar's midpoint, we assume that it closed in the same Zone as the previous bar did
The basic question to be answered in our research with respect to the terms introduced above is:
What is the probability that the next bar’s close price will end up in the same Zone or in the opposite Zone than the current bar’s close price if we know how many consecutive bars, including the current bar, has had the close price in the present Zone?
Of course, the probability that the next bar will close in the present Zone and the probability that it will close in the opposite Zone always adds up to 100% since the bar has to close in one of the two Zones.
Independent variable here is the number of consecutive bars in the same Zone. Dependent variable is the probability that the next bar will close either in the same or in the opposite Zone (1 or -1 in the code, see below).
In the graphs I don't show probability in %, but rather the actual number of observations (number of consecutive bars' sequences) so that you may have a better idea of what was the testing sample size for each symbol/timeframe.
For the research to be valid with my algorithm that tracks only absolute Zone changes instead of upper to lower / lower to upper Zone change, we assume that the price behaviour in this respect is symmetric, i.e. there's no significant statistical difference between the tendency to change from the upper Zone to the lower Zone and the tendency to change from the lower Zone to the upper Zone.
Indeed, I was curious about the results. My working hypothesis was that:
1. the price action will resemble Brownian motion in Zone change with only one or several consecutive closes in the same Zone (i.e. the Zone selection will be random in this case)
2. with the higher value of consecutive bars closing in the same Zone there will be a significant tendency towards either staying in the current Zone or towards changing the current Zone.
But, as with many other studies, the results were quite surprising and I would say, strangely accurate! I double checked my code (I encourage you to do the same), but couldn't find any flaw that would explain the weird numerical accuracy of the results. I will be glad if you find the flaw in my code!
Anyway, have a look at the resulting graphs by yourself.
Notes:
- I only picked 10 highest consecutive bars sequences for every graph
- all the sequences/observations you will find in the attached zip file "MidPoint_stats.zip"
- from the graphs it is clear that the probability that the observation will occur decreases exponentially in inverse proportion with the number of consecutive bars in the sequence
- orange value: Zone changed after n consecutive bars in the Zone (x axis)
- green value: Zone didn't change after n consecutive bars in the Zone (x axis)
- look at the probability of Zone change (orange) versus Zone stay (green)!
The conclusion:
There is no evidence that there is a significant statistical relation between the number of consecutive bars in the same Zone and the probability that the Zone will change or not change on the following bar.
The code I used for calculations (you may re-run the experiment by yourself):
Code: Select all
{
program name: !MidPoint statistics
last change: May/27/2006
version: 1.15
author: Michal Kreslik
email: michal.kreslik@kreslik.com
website: http://kreslik.com
comments: measures what is the probability
that the next bar's close price winds up
in the opposite Zone than the current
bar's close price if we know how many
consecutive bars, including the current
bar, has had the close price
in the present Zone
}
vars:
iPrintToOutputBar( true ),
iPrintToFile( true ),
iFileFolder( "c:\data\temp" );
vars:
vZoneBoundary( 0 ),
vZone( 0 ),
vCounter( 0 ),
vMaxBarsInZone( 0 );
vars:
sTimeFrameString( "" ),
sFileName( "" );
vars:
bZoneChanged( false ),
bRunStats( false ),
intrabarpersist bFirstRun( true ),
tIndex( 0 );
arrays:
aZoneChanged[]( 0 ),
aZoneNotChanged[]( 0 );
bZoneChanged = false;
vZoneBoundary = (high + low)/2;
if close > vZoneBoundary[1] then vZone = 1;
if close < vZoneBoundary[1] then vZone = -1;
if vZone <> vZone[1] then
begin
bZoneChanged = true;
vCounter = 1;
end
else
vCounter = vCounter + 1;
if bRunStats = false
AND bZoneChanged
AND BarNumber > 1 then
bRunStats = true;
if bRunStats[1] then
begin
vMaxBarsInZone = MaxList(vMaxBarsInZone, vCounter[1]);
if vMaxBarsInZone > vMaxBarsInZone[1] then
begin
Array_SetMaxIndex(aZoneChanged, vMaxBarsInZone);
Array_SetMaxIndex(aZoneNotChanged, vMaxBarsInZone);
end;
if bZoneChanged then
aZoneChanged[vCounter[1]] = aZoneChanged[vCounter[1]] + 1
else
aZoneNotChanged[vCounter[1]] = aZoneChanged[vCounter[1]] + 1;
end;
if LastBarOnChart AND bFirstRun then
begin
bFirstRun = false;
if iPrintToOutputBar then
begin
ClearPrintLog;
Print("cons. bars: zone changed: zone not changed:");
for tIndex = 1 to vMaxBarsInZone
begin
Print(NumToStr(tIndex, 0), " ",
NumToStr(aZoneChanged[tIndex], 0), " ",
NumToStr(aZoneNotChanged[tIndex], 0));
end;
end;
if iPrintToFile then
begin
array: aTimeFrames[4]("");
aTimeFrames[0] = NumToStr(BarInterval, 0) + "_ticks";
aTimeFrames[1] = NumToStr(BarInterval, 0) + "_min";
aTimeFrames[2] = "daily";
aTimeFrames[3] = "weekly";
aTimeFrames[4] = "monthly";
sTimeFrameString = aTimeFrames[datacompression];
sFileName = iFileFolder + "\"
+ GetSymbolName + "_"
+ sTimeFrameString + "_"
+ "statistics.csv";
FileDelete(sFileName);
FileAppend(sFileName, "cons. bars,zone changed,zone not changed" + NewLine);
for tIndex = 1 to vMaxBarsInZone
begin
FileAppend(sFileName, NumToStr(tIndex, 0) + ","
+ NumToStr(aZoneChanged[tIndex], 0) + ","
+ NumToStr(aZoneNotChanged[tIndex], 0) + NewLine);
end;
end;
end;
Michal