Multi timeframe Indicator

 
I get something wrong with backtest.
It dont show the same as forward test in buffer 0->2 and 1->3, and I think it should be equal at bar 0.

Please help

#property indicator_chart_window
#property indicator_buffers 4

double b0[],b1[],b2[],b3[];
int start(){
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;
for(int b=0; b<limit; b++){

int shift=iBarShift(Symbol(),PERIOD_H1,iTime(Symbol(),Period(),b));
b0[b]=iCCI(NULL,PERIOD_H1,14,PRICE_CLOSE,shift);

shift=iBarShift(Symbol(),PERIOD_H4,iTime(Symbol(),Period(),b));
b1[b]=iCCI(NULL,PERIOD_H4,14,PRICE_CLOSE,shift);

b2[b]=iCCI(NULL,PERIOD_H1,14,PRICE_CLOSE,b);

b3[b]=iCCI(NULL,PERIOD_H4,14,PRICE_CLOSE,b);

}
return(0);
}
int init(){
IndicatorBuffers(4);
SetIndexStyle(0,DRAW_NONE);SetIndexBuffer(0,b0);SetIndexEmptyValue(0,0);SetIndexLabel(0,"H1");
SetIndexStyle(1,DRAW_NONE);SetIndexBuffer(1,b1);SetIndexEmptyValue(1,0);SetIndexLabel(1,"H4");
SetIndexStyle(2,DRAW_NONE);SetIndexBuffer(2,b2);SetIndexEmptyValue(2,0);SetIndexLabel(2,"2H1");
SetIndexStyle(3,DRAW_NONE);SetIndexBuffer(3,b3);SetIndexEmptyValue(3,0);SetIndexLabel(3,"2H4");
}
 
Try more properly construction:
for(int b=limit; b>=0; b--){

int shift=iBarShift(Symbol(),PERIOD_H1,iTime(Symbol(),Period(),b));
b0[b]=iCCI(NULL,PERIOD_H1,14,PRICE_CLOSE,shift);

shift=iBarShift(Symbol(),PERIOD_H4,iTime(Symbol(),Period(),b));
b1[b]=iCCI(NULL,PERIOD_H4,14,PRICE_CLOSE,shift);

b2[b]=iCCI(NULL,PERIOD_H1,14,PRICE_CLOSE,b);

b3[b]=iCCI(NULL,PERIOD_H4,14,PRICE_CLOSE,b);

}



 
Well I have to say that was the first thing I've tried. I tryed a lot of other things that fail.
Why don't you try backtest it?

Thank you
 
To be more specific,

If I backtest it with backtest timeframe parameter H1, the H1 shows well (buffers 0 and 1), the H4 shows bad.

If I backtest it with backtest timeframe parameter H4, the H4 shows well (buffers 2 and 3), the H1 shows bad.

If I backtest it with backtest timeframe parameter M30, both H1 and H4 (all buffers) shows bad.
 
I don't understand your request.

This is correct written indicator:

//+------------------------------------------------------------------+
//|                                                         MTFI.mq4 |
//|                                                             Rosh |
//|                                        http://www.metaquotes.ru/ |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 4

#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Green
#property indicator_color4 Yellow

double b0[],b1[],b2[],b3[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
  int start(){
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   datetime currtime;
   int shift;
   for(int b=limit; b>=0; b--)
      {
      currtime=iTime(Symbol(),Period(),b);
      shift=iBarShift(Symbol(),PERIOD_H1,currtime);
      b0[b]=iCCI(NULL,PERIOD_H1,14,PRICE_CLOSE,shift);

      shift=iBarShift(Symbol(),PERIOD_H4,iTime(Symbol(),Period(),b));
      b1[b]=iCCI(NULL,PERIOD_H4,14,PRICE_CLOSE,shift);

      b2[b]=iCCI(NULL,PERIOD_H1,14,PRICE_CLOSE,b);

      b3[b]=iCCI(NULL,PERIOD_H4,14,PRICE_CLOSE,b);

      }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
  int init(){
   //IndicatorBuffers(4);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,b0);
   SetIndexEmptyValue(0,0);
   SetIndexLabel(0,"H1");

   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,b1);
   SetIndexEmptyValue(1,0);
   SetIndexLabel(1,"H4");

   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,b2);
   SetIndexEmptyValue(2,0);
   SetIndexLabel(2,"2H1");

   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,b3);
   SetIndexEmptyValue(3,0);
   SetIndexLabel(3,"2H4");
  }
//+------------------------------------------------------------------+




and this is picture of indicator




What is wrong?

 
It does the same as mine, works well in the chart, but not in the backtest.
If you call it from an EA, and run it in backtest, it will give wrong data to the EA.

When the backtest is running, if you drag the Indicator to the chart window in visual mode, it will show the wrong data.

Other thing, if you change the timeframe on the chart above H4, it will show different values in both.
 
Test this expert adviser and inform what you view.
//+------------------------------------------------------------------+
//|                                              ExpertCheckMTFI.mq4 |
//|                                                             Rosh |
//|                                        http://www.metaquotes.ru/ |
//+------------------------------------------------------------------+
#property copyright "Rosh"
#property link      "http://www.metaquotes.ru/"

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   double H1,H4,H1_2,H4_2;
   string Comm;
   H1=iCustom(NULL,0,"MTFI",0,0);
   H4=iCustom(NULL,0,"MTFI",1,0);   
   H1_2=iCustom(NULL,0,"MTFI",2,0);   
   H4_2=iCustom(NULL,0,"MTFI",3,0);
   Comm=StringConcatenate(" H1=",H1,"\n","2H1=",H1_2,"\n","\n"," H4=",H4,"\n","2H4=",H4_2);
   Comment(Comm);
//----
   return(0);
  }
//+------------------------------------------------------------------+



 
Hi superbem,

There are no MTF indicators that work on backtesting. I have not found one or coded one yet that does.
It's a fact that they will only work on live charts. Please let me know if you come up with a solution.

Thanks
 
I was wrong, deleted...
 
I'm having a same problem with MTF indicators and manual backtesting. They just don't work, nothing is shown. No problems when used on live charts.
Reason: