Ichimoku check for different timeframe does not work (little help needed)

 

Hi Forum,

I use the Ichimoku indicator and I wanted to see if the the price is above, in or below the cloud in a higher timeframe. I trade the M5 and wanted to know how the M15 looks like without switching the timeframe.

Green = last bar is above the could

Yellow = last bar is in the cloud (or part of the bar)

Red = last bar is below the cloud

Unfortunately it does not work correct. I used an input parameter which timeframe should be checked by the indicator. I trade M5, so I used 15. But the indicator only shows the correct colors when I switch to M15, although I use the correct period for iIchimoku().

Can anyone have a look at it? Thank you!

Files:
 

u have to use

iOpen(Symbol(),PERIOD_M15,shift+1);
iClose(Symbol(),PERIOD_M15,shift+1);

instead of

Open[shift+1]

that represent the current chart (M5)

 

Unfortunately that doesn't work. Today the EURUSD (M15) was below the cloud from 0 - 9:30 (GMT+2). So the indicator should only be red at this time. But it isn't. It only works when I switch to M15 timeframe.

Maybe I am wrong but I think it is not important if the indicator uses the correct timeframe for open and close of the bars. It is only important if the prices are in, above or below the M15 cloud. And in this EURUSD example the prices are below the cloud last night and therefore the prices of M5 must also be below the M15 cloud.

 

I have an idea. At the moment the loop checks the M15 Ichimoku every bar. But the chart I use is the M5 timeframe. So the indicator also checks the M15 Ichimoku at XX:05 and XX:10. And I think that is the problem with the wrong colors. There is no value at minute 05 or minute 10. So I think I must check if the bar is minute 0 or minute 15 and then print 3 colors in the indicator because minute 05 and 10 should not be checked.

Maybe... But I have no idea how to do that. Hopefully somebody could help.


PS: I just tried this:

int start()
{
for(shift=Bars-1;shift>=0;shift--)
{
if (Minute()!=0 || Minute()!=15 || Minute()!=30 || Minute()!=45) return;

double SpanA=iIchimoku(NULL, IchimokuPeriod, 9, 26, 52, MODE_SENKOUSPANA, shift+1);
double SpanB=iIchimoku(NULL, IchimokuPeriod, 9, 26, 52, MODE_SENKOUSPANB, shift+1);


But the Minute()-Test does also not work... :-/

 

try to put this

Buffer1[shift+1]=0;
Buffer2[shift+1]=1;
Buffer3[shift+1]=0;

@ the end

like this

   for(shift=Bars-1;shift>=0;shift--)
      { 
      double SpanA=iIchimoku(NULL, IchimokuPeriod, 9, 26, 52, MODE_SENKOUSPANA, shift+1);
      double SpanB=iIchimoku(NULL, IchimokuPeriod, 9, 26, 52, MODE_SENKOUSPANB, shift+1);
          
          if (iOpen(Symbol(),IchimokuPeriod,shift+1)>SpanA && iClose(Symbol(),IchimokuPeriod,shift+1)>SpanA && iOpen(Symbol(),IchimokuPeriod,shift+1)>SpanB && iClose(Symbol(),IchimokuPeriod,shift+1)>SpanB) 
             {
             Buffer1[shift+1]=1;
             Buffer2[shift+1]=0;
             Buffer3[shift+1]=0;
             }
          else if (iOpen(Symbol(),IchimokuPeriod,shift+1)<SpanA && iClose(Symbol(),IchimokuPeriod,shift+1)<SpanA && iOpen(Symbol(),IchimokuPeriod,shift+1)<SpanB && iClose(Symbol(),IchimokuPeriod,shift+1)<SpanB) 
             {
             Buffer1[shift+1]=0;
             Buffer2[shift+1]=0;
             Buffer3[shift+1]=1;
             }
          else
             {
             Buffer1[shift+1]=0;
             Buffer2[shift+1]=1;
             Buffer3[shift+1]=0;
             }
          }
 
Now the indicator prints exactly the same colors in every timeframe. The colors are 100% correct when I choose the M15 chart but it stays the same in all other timeframes. I never thought that this could be so complicated. But maybe it's not possible to make this a MTF indicator.
Reason: