Real Multi time Frame

Hamidreza Taheri
1946
Hamidreza Taheri  

Hi,

I like to discuss about Multi time frame indicators. There are many kinds of MTF indicators in WEB. By all of known MTF indicators we got the last available value in each time frame(see the picture) and the value will be constant until before last bars.

If some body want to check his/her idea using historical data, this mtf indicators does not help at all. It is better to improve MTF codes, so that in a certain time frame we got the MTF value according to his candel value.

The above picture shows the value of MTF RSI with period 2 and Daily time frame. The code of this indicator is below:

//+------------------------------------------------------------------+
//|                                                     #MTF_RSI.mq4 |
//|------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 HotPink
#property indicator_level1 0.000000
//---- input parameters
/*************************************************************************
PERIOD_M1   1
PERIOD_M5   5
PERIOD_M15  15
PERIOD_M30  30 
PERIOD_H1   60
PERIOD_H4   240
PERIOD_D1   1440
PERIOD_W1   10080
PERIOD_MN1  43200
You must use the numeric value of the timeframe that you want to use
when you set the TimeFrame' value with the indicator inputs.
---------------------------------------*/
extern int    TimeFrame=0;
extern int    Periods=2;
extern int AppliedPrice=0;
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator line
   SetIndexStyle(0,DRAW_LINE,EMPTY,1);
   SetIndexBuffer(0,ExtMapBuffer1);
//---- name for DataWindow and indicator subwindow label   
   switch(TimeFrame)
     {
      case 1 : string TimeFrameStr="Period_M1"; break;
      case 5 : TimeFrameStr="Period_M5"; break;
      case 15 : TimeFrameStr="Period_M15"; break;
      case 30 : TimeFrameStr="Period_M30"; break;
      case 60 : TimeFrameStr="Period_H1"; break;
      case 240 : TimeFrameStr="Period_H4"; break;
      case 1440 : TimeFrameStr="Period_D1"; break;
      case 10080 : TimeFrameStr="Period_W1"; break;
      case 43200 : TimeFrameStr="Period_MN1"; break;
      default : TimeFrameStr="Current Timeframe";
     }
   IndicatorShortName(" #MTF_RSI ( "+TimeFrameStr+" ) ");
  }
//----
   return(0);
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   datetime TimeArray[];
   int    i,limit,y=0,counted_bars=IndicatorCounted();
   // Plot defined time frame on to current time frame
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);
   limit= Bars-1;
   for(i=0,y=0;i<limit;i++)
     {
      if (Time[i]<TimeArray[y]) y++;
/***********************************************************   
   Add your main indicator loop below.  You can reference an existing
      indicator with its iName  or iCustom.
   Rule 1:  Add extern inputs above for all neccesary values   
   Rule 2:  Use 'TimeFrame' for the indicator time frame
   Rule 3:  Use 'y' for your indicator's shift value
**********************************************************/
      ExtMapBuffer1[i]=iRSI(Symbol(),TimeFrame,Periods,AppliedPrice,y);
     }
   return(0);
  }
//+------------------------------------------------------------------+

If any body can modify the above code in order to get the real MTF value and his real drawing by each candel please share it.

Many thanks

onewithzachy
1863
onewithzachy  

Hi there hmrt135

BB MTF.

Files:
band_mtf.mq4  6 kb
William Roeder
24607
William Roeder  
hmrt135:

If some body want to check his/her idea using historical data, this mtf indicators does not help at all. It is better to improve MTF codes, so that in a certain time frame we got the MTF value according to his candel value.

If any body can modify the above code in order to get the real MTF value and his real drawing by each candel please share it.

What are you talking about. The above code is fine. Does EXACTLY what you want.

Except:

  1. You MUST have history for that time frame
  2. You can't get bar zero data in the tester
Hamidreza Taheri
1946
Hamidreza Taheri  
WHRoeder:

What are you talking about. The above code is fine. Does EXACTLY what you want.

Except:

  1. You MUST have history for that time frame
  2. You can't get bar zero data in the tester

Hi WHRoeder,

Actualy i do not want to see the backtest results because of limited options in MT4. In the above code you will get only the last value of MTF indicator and if you like to compare other indicators with MTF indicator, you could not realize your strategy in the past. For example in the above picture by 9. August. In real time MTF RSI will give you various values relative to its last bar but if the higher time frame candles ( in this example is Period_D1) closed you will see only the value of the last closed bar of higher time frame. But i would like to modify the above code so that could record each bar value by MTF indicator. For this purpose i give you an advise.

" if your higher time frame is 1440 and your current timeframe is 60, so you have iClose(symbol(), 60, 0) = iClose (symbol(),1440, 0) but after closing of current time frame bar you do not have iClose(symbol(), 60,1) = iClose (symbol(),1440, 0). It means a frequency of values in a MTF indicator that must be redraw.

I have tried to modify it but i could only get this values for last day using the traditional RSI definition for MTF RSI with period 2 and Time frame 1440 on current time frame. see the below code. Unfortunately i could not make a serial code for making a MTF indicator like the above code. And the other days values mismatched.

         while(k>=i)
           {
           rel_D1=(iClose(symbol(),1440 , 1)-iClose(symbol(),1440 , 2);
            if(rel_D1>0) sump_D1+=rel_D1;
            else      sumn_D1-=rel_D1;
 
           rel=Close[k]-rel_D1 ;
                     
            if(rel>0) sump+=rel;
            else      sumn-=rel;
            k--;
           }
         positive=sump/RSIPeriod;
         negative=sumn/RSIPeriod;
        }
Hamidreza Taheri
1946
Hamidreza Taheri  
onewithzachy:

Hi there hmrt135

BB MTF.


Thank you very much, i will try your code. I hope it is what i am looking for.
Hamidreza Taheri
1946
Hamidreza Taheri  
onewithzachy:

Hi there hmrt135

BB MTF.


I have checked the code, it is not what i am looking for.
William Roeder
24607
William Roeder  

hmrt135:

" if your higher time frame is 1440 and your current timeframe is 60, so you have iClose(symbol(), 60, 0) = iClose (symbol(),1440, 0) but after closing of current time frame bar you do not have iClose(symbol(), 60,1) = iClose (symbol(),1440, 0). It means a frequency of values in a MTF indicator that must be redraw.

I still don't understand your problem.

When the M60 bar closes iClose(NULL,1440,0) does not equal iClose(NULL,60,1).

When the M60 bar closes iClose(NULL,1440,0) equals iClose(NULL,60,0). STILL. And will be until the end of the day.

The D1 MTF indicator is still on the same D1 bar until midnight.

A D1 MTF indicator does NOT compute it's values based on the high/low of the last 24 H1 bars. It computes it's value on the D1 bars. The MTF indicator must NOT redraw after every H1 bar.

I suggest you bring up the indicator on a D1 chart and compare the D1 chart indicator values with the MTF indicator using D1 TF. They MUST match.

Hamidreza Taheri
1946
Hamidreza Taheri  
WHRoeder:

I still don't understand your problem.

When the M60 bar closes iClose(NULL,1440,0) does not equal iClose(NULL,60,1).

When the M60 bar closes iClose(NULL,1440,0) equals iClose(NULL,60,0). STILL. And will be until the end of the day.

The D1 MTF indicator is still on the same D1 bar until midnight.

A D1 MTF indicator does NOT compute it's values based on the high/low of the last 24 H1 bars. It computes it's value on the D1 bars. The MTF indicator must NOT redraw after every H1 bar.

I suggest you bring up the indicator on a D1 chart and compare the D1 chart indicator values with the MTF indicator using D1 TF. They MUST match.

Ok it is simple but difficult. So take a look at the above picture again. The last close price of current bar in H1 time frame is equal to last close price of current bar in D1. So in H1 time frame by Time[0] we have the value " 9.0875" for our MTF RSI indicator and this value will be changed until the end of current D1 bar and we see this value for the whole past H1 bar constant. But in the real it is not constant. Better to explain is the previous bar in H1 time frame. The value of MTF RSI indicator by previous bar in H1 is not the same value of the current bar in both H1 and D1. Also I want to modifiy the above code, so that the value of MTF RSI indicator by previous bar in the lower ( current ) time frame will be record and visible in history. I hope you understand what i mean. For Example the value of MTF RSI indicator by current bar in H1 time frame is " 9.0875" but this value for MTF RSI by the previous bar in H1 time frame is "8.9806". I want to get this values and not the last value of MTF indicator for entire of a day.

William Roeder
24607
William Roeder  
  1. last close price of current bar in H1 time frame is equal to last close price of current bar in D1
    Agreed
  2. The value of MTF RSI indicator by previous bar in H1 is not the same value of the current bar in both H1 and D1.

    Wrong. The value of the MTF indicator will NOT change from the previous h1 bar to the current h1 one bar until the D1 bar is done. Your image shows the current H1 bar is at "10 Aug 16:00" and that is 8 hours before the end of the day.


  3. I hope you understand what i mean.
    I don't. The MTF bar should not change until the end of the day.
  4. RSI indicator by current bar in H1 time frame is " 9.0875" but this value for MTF RSI by the previous bar in H1 time frame is "8.9806"
    Your image shows that the RSI MFT value for the current bar AND the previous var is ~7.087. The value at 10 Aug 01:00, one H1 bar into the day is the same 7.087

  5. I don't know what you're talking about. Do what I previous said. post the RSI on the D1 chart and the MTF side by side and show the difference. There shouldn't be any on a live chart. There will be for the D1 zero bar in the tester as already referenced.