Expert Advisor doesn't recognize if chart period is changed
Can use a switch for example
switch(Period())
{
case 0:// Current
break;
case 1:// M1
break;
case 5:// M5
break;
case 15:// M15
break;
case 30:// M30
break;
case 60:// H1
break;
case 240:// H4
break;
case 1440:// D1
break;
case 10080:// W1
break;
case 43200:// MN1
break;
}
Hi guys,
I wrote a small code to demonstrate my problem:
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
if (Time0!=iTime(NULL, _Period, 0)) {
Time0=iTime(NULL, _Period, 0);
Alert(_Period);
}
}
When I switch the chart period I expect the EA to pop up the alert window displaying the current chart period. Interestingly, sometimes it works and sometimes not. Here is the journal of my test:
I started with the daily and the alert was alright. Then I switched to H4 and the alert was also ok. But after switching to the H1 I waited for almost 2 minutes and there was no alert. The M30 period worked again but M15 and M5 didn't work. The weekly was ok again. Why doesn't the EA recognize all period changes?
Can somebody tell me what's wrong with the code? I can't see any mistake here...?!
{
static int _prevPeriod=0;
if (Time0!=iTime(NULL, _Period, 0) || _prevPeriod!=_Period) {
Time0 =iTime(NULL, _Period, 0); _prevPeriod =_Period;
Alert(_Period);
}
}
Hi guys,
I wrote a small code to demonstrate my problem:
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
if (Time0!=iTime(NULL, _Period, 0)) {
Time0=iTime(NULL, _Period, 0);
Alert(_Period);
}
}
When I switch the chart period I expect the EA to pop up the alert window displaying the current chart period. Interestingly, sometimes it works and sometimes not. Here is the journal of my test:
I started with the daily and the alert was alright. Then I switched to H4 and the alert was also ok. But after switching to the H1 I waited for almost 2 minutes and there was no alert. The M30 period worked again but M15 and M5 didn't work. The weekly was ok again. Why doesn't the EA recognize all period changes?
Can somebody tell me what's wrong with the code? I can't see any mistake here...?!