alerts repeated on chart refreshes

 

I am having problems with alerts being repeated every time I change the chart period or reload metatrader.

I though of using globalvariables but can you store datetimes in global variables?


if (iIchimoku(Symbol(), PERIOD_H4, 9, 26, 52, MODE_TENKANSEN, 0) > iIchimoku(Symbol(), PERIOD_H4, 9, 26, 52, MODE_KIJUNSEN, 0) && //current cross
    iIchimoku(Symbol(), PERIOD_H4, 9, 26, 52, MODE_TENKANSEN, 1) <= iIchimoku(Symbol(), PERIOD_H4, 9, 26, 52, MODE_KIJUNSEN, 1) && //previous
    FourHourLastAlertTime < Time[0] &&
    //price is also above cloud on higher timeframes
    (Bid > iIchimoku(Symbol(), PERIOD_D1, 9, 26, 52, MODE_SENKOUSPANA, 0) && Bid > iIchimoku(Symbol(), PERIOD_D1, 9, 26, 52, MODE_SENKOUSPANB, 0))
    )
{
   Alert ("TS crossed KS upwards on+ "+Symbol() + " 4HR");
   FourHourLastAlertTime = Time[0];
   Comment("Last Alert: TS/KS cross UP on 4hr");
}
 

"I though of using globalvariables but can you store datetimes in global variables?"

GlobalVariables are doubles, datetime an int.

So, yes.

 
An nteresting side effect of this is that if the variable is set in the 1hr chart using
FourHourLastAlertTime = Time[0];

it will sound every time a lower timeframe chart is selected but if you select a higher timeframe chart, it will not.
Any ideas why?
Reason: