1 indicator monitoring multiple periods

 

I would like to have an indicator that I can leave open on the daily chart but it monitors all timeframes below it.

How can I get the close of a timeframe with set period?


if (Period() == PERIOD_D1 || Period() == PERIOD_H4 || Period() == PERIOD_H1)
{
      if (Period() == PERIOD_D1) {
         if (Close[1] > SpanA_Buffer[0] && Close[1] > SpanB_Buffer[0] && DailyLastAlert != 1)
            {  Alert ("Price closed above the cloud on "+Symbol() + ": "+Period());
               DailyLastAlert = 1; //buy was last alert
            }
         if (Close[1] < SpanA_Buffer[0] && Close[1] < SpanB_Buffer[0] && DailyLastAlert != 0)
            {  Alert ("Price closed below the cloud on "+Symbol() + ": "+Period());
               DailyLastAlert = 0; //buy was last alert
            }
      }
      
      if (Period() == PERIOD_H4) {
         if (Close[1] > SpanA_Buffer[0] && Close[1] > SpanB_Buffer[0] && FourHourLastAlert != 1)
            {  Alert ("Price closed above the cloud on "+Symbol() + ": "+Period());
               FourHourLastAlert = 1; //buy was last alert
            }
         if (Close[1] < SpanA_Buffer[0] && Close[1] < SpanB_Buffer[0] && FourHourLastAlert != 0)
            {  Alert ("Price closed below the cloud on "+Symbol() + ": "+Period());
               FourHourLastAlert = 0; //buy was last alert
            }
      }
      
      if (Period() == PERIOD_H1) {
         if (Close[1] > SpanA_Buffer[0] && Close[1] > SpanB_Buffer[0] && HourLastAlert != 1)
            {  Alert ("Price closed above the cloud on "+Symbol() + ": "+Period());
               HourLastAlert = 1; //buy was last alert
            }
         if (Close[1] < SpanA_Buffer[0] && Close[1] < SpanB_Buffer[0] && HourLastAlert != 0)
            {  Alert ("Price closed below the cloud on "+Symbol() + ": "+Period());
               HourLastAlert = 0; //buy was last alert
            }
      }
}  
 

You have to use iClose and all those functions starting with "i" so you can fix the period regardless of which timeframe you are displaying,

eg iClose(NULL, PERIOD_M30, 0) will return the Close value of PERIOD_M30 even when you are displaying the Daily chart.