Forex Mythbusters Lection 2: Hourly Data can predict the end of the day

 

Hello again to the mythbusters channel.

Today we are going to analyze the hourly data in relationship to the daily close price.

We assume that there exists hours which predicts the direction of the ending day.

The indicator we need to collect the data is quite simple:

//+------------------------------------------------------------------+
//|                                                  -wmmm-Stats.mq4 |
//|                                                           zzuegg |
//|                                       when-money-makes-money.com |
//+------------------------------------------------------------------+
#property copyright "zzuegg"
#property link      "when-money-makes-money.com"

#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int hour[24];
int count[24];
int hit[24];

int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
extern int dailyShift=1;
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   datetime last=0;
   if(last!=Time[0]){
      int i=0;
      for(i=0;i<24;i++){
         hour[i]=0;
         count[i]=0;
         hit[i]=0;
      }
      for(i=Bars;i>0;i--){
         int h=TimeHour(Time[i]);
         int day=iBarShift(Symbol(),PERIOD_D1,Time[i],false)-dailyShift;
         bool hup=Open[i]>Close[i];
         bool dup=iOpen(Symbol(),PERIOD_D1,day)>iClose(Symbol(),PERIOD_D1,day);
         if(hup==dup){
            count[h]=count[h]+1;
            hit[h]=hit[h]+1;
         }else{
            count[h]=count[h]+1;        
         }
      }
      string c="";
      for(i=0;i<24;i++){
         if(hit[i]!=0)c=c+"Hour "+i+" /"+dailyShift+" "+hit[i]+": Correct: "+((hit[i]*1.0/count[i]*1.0)*100)+"\n";
      }
      Comment(c);      
   }   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Nothing fancy in it. I have also added the option to check if todays hourly data predicts the movement of tomorrow but that is another story.

So what are the result on EURUSD?

Hour
Prediction Quality %
0
54
1
53
2
51
3
54
4
51
5
52
6
52
7
52
8
55
9
58
10
56
11
56
12
56
13
54
14
59
15
57
16
61
17
56
18
52
19
56
20
53
21
54
22
54
2351


As you can see there are a few hours which are interesting:

The red one are the two hours with the highest probaillity. So lets trade this ones:


Why the test failed? Even if the prediction ratio is high more than half of the day, and the daily movement has already happend.

Now lets look at the blue marked hours. The have the advantage that big part of the day still happen.

And here are the results:

As you can see the edge can beat at least the spread. Of course this will not make you rich and the demo EA does not use a Stoploss or Takeprofit, but it will close all trades on the end of the day.


Conclusion: Indeed following the trend of the intraday movement seems to be a good idea, especially we like the 9:00 candle with a prediction power of 58%.

Additionally here is the EA i have tested with. Its only a fast writen code,

ONLY FOR STRATEGY TESTER,

ONLY FOR STRATEGY TESTER

ONLY FOR STRATEGY TESTER

//+------------------------------------------------------------------+
//|                                            -wmmm-HourlyClose.mq4 |
//|                                                           zzuegg |
//|                                       when-money-makes-money.com |
//+------------------------------------------------------------------+
#property copyright "zzuegg"
#property link      "when-money-makes-money.com"

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
void closeAll(int mode){
   for(int i=OrdersTotal()-1;i>=0;i--){
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()==mode){
         OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,CLR_NONE);
      }
   }
}

void openOrder(int mode){
   double op=Ask;
   double lot=NormalizeDouble(AccountBalance()/100000,2);
   lot=MathMin(lot,MarketInfo(Symbol(),MODE_MAXLOT));
   lot=MathMax(lot,MarketInfo(Symbol(),MODE_MINLOT));
   if(mode==OP_SELL){
    op=Bid;
   }
   OrderSend(Symbol(),mode,lot,op,0,0,0,"",0,0,CLR_NONE);
}

extern int TradeHour=4;
extern int reverse=0;

int hourArr[]={1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

int start()
  {
//----

      static datetime day=0;
      if(iTime(Symbol(),PERIOD_D1,0)!=day){
         closeAll(OP_BUY);
         closeAll(OP_SELL);
         day=iTime(Symbol(),PERIOD_D1,0);
      }
      static datetime hour=0;
      if(iTime(Symbol(),PERIOD_H1,0)!=hour){
         hour=iTime(Symbol(),PERIOD_H1,0);
         int direction=hourArr[(TimeHour(Time[0]))];
         if(direction!=0){
            if(Open[1]>Close[1]){
               if(direction==1) openOrder(OP_BUY);
               if(direction==-1) openOrder(OP_SELL);
            }else{
               if(direction==1) openOrder(OP_SELL);
               if(direction==-1) openOrder(OP_BUY);            
            }
         }
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

And here is prior work in this field: https://www.mql5.com/en/articles/1576.

Using the article script you can see something interesting:

2012.02.25 10:25:51 script_Statistics_candles_V2 AUDUSD,H4: Processed - 356 days; 1841 bars, period 240 minutes
2012.02.25 10:25:51 script_Statistics_candles_V2 AUDUSD,H4: For the period there are 297 bars with the time of the opening 0:0 .Bullish- 125.Bearish- 172.Equal - 0
2012.02.25 10:25:51 script_Statistics_candles_V2 AUDUSD,H4: For the bars with the opening time 0:0,average distance between the Open-Close prices - 163.1347 points. Between the High-Low prices - 362.4444 points.

This is over the last year or so using 4H timeframe. You can see if you just blindly went short on AUDUSD at midnight you would have done quite well. There are other timeframes on AUDUSD that are interesting too.

 
rocketman99:

And here is prior work in this field: https://www.mql5.com/en/articles/1576.

Using the article script you can see something interesting:

2012.02.25 10:25:51 script_Statistics_candles_V2 AUDUSD,H4: Processed - 356 days; 1841 bars, period 240 minutes
2012.02.25 10:25:51 script_Statistics_candles_V2 AUDUSD,H4: For the period there are 297 bars with the time of the opening 0:0 .Bullish- 125.Bearish- 172.Equal - 0
2012.02.25 10:25:51 script_Statistics_candles_V2 AUDUSD,H4: For the bars with the opening time 0:0,average distance between the Open-Close prices - 163.1347 points. Between the High-Low prices - 362.4444 points.

This is over the last year or so using 4H timeframe. You can see if you just blindly went short on AUDUSD at midnight you would have done quite well. There are other timeframes on AUDUSD that are interesting too.


Yeah, i have read this article a while ago, but the article and my work are different, the article assumes that candles go in one direction each day, while i assume that if hour(x) is bullisch/bearish, the whole day will close bullish/bearish.

Of course this does not imply that it will behave in the future like this but it seamed to work for the last 10 years. However, this should not be a complete strategy but this could act as a filter, for example i the filter would suggest to short only on days where the 9:00 candle was a short one.

 

What does the daily shift parameter do?

Using the AUDUSD as with previous example using your code I see on H1 things are pretty much 50% all the way. On H4 there is a 52% at Hour 8 which corresponds roughly with my previous post.

 
rocketman99:

What does the daily shift parameter do?

Using the AUDUSD as with previous example using your code I see on H1 things are pretty much 50% all the way. On H4 there is a 52% at Hour 8 which corresponds roughly with my previous post.

Well, the indicator is designed only for H1 since i wanted to inspect every hour. The shift parameter allows to shift the day forward. It is used to test the prediction potential for the x day after

If all are 50% then there is no edge for us

 
zzuegg:

Well, the indicator is designed only for H1 since i wanted to inspect every hour. The shift parameter allows to shift the day forward. It is used to test the prediction potential for the x day after

If all are 50% then there is no edge for us


Ok. Still confused a little. Does the indicator take the entire history (all bars), or can you set a range.
 
All bars
 
zzuegg:
All bars
I am not a big fan of all bars and 10 year testing. Markets change and I would rather want to look at a specific snapshot, like this year or last and base my statistics on the changing conditions.
 
rocketman99:
I am not a big fan of all bars and 10 year testing. Markets change and I would rather want to look at a specific snapshot, like this year or last and base my statistics on the changing conditions.
Then modify the code.
 
WHRoeder:
Then modify the code.
Thanks for the insightful comment. I have code that satisfies my needs. My point is around 10 year backtests. Look at the graph above - would you tollerate the years and years of losses and drawdowns before starting to make a profit only at the very end? I think not. Anyway, backtesting is a discussion of for another thread.
Reason: