void OnChartEvent( const int id, // Event ID const long& lparam, // Parameter of type long event const double& dparam, // Parameter of type double event const string& sparam // Parameter of type string events ) { int new_timeframe; switch(id) { case CHARTEVENT_KEYDOWN: if(lparam=='J' || lparam=='j') { //ENUM_TIMEFRAMES new_timeframe=PERIOD_CURRENT; switch(Period()) { case PERIOD_M1: new_timeframe = PERIOD_M1; break; case PERIOD_M5: new_timeframe = PERIOD_M1; break; case PERIOD_M15: new_timeframe = PERIOD_M5; break; case PERIOD_M30: new_timeframe = PERIOD_M15; break; case PERIOD_H1: new_timeframe = PERIOD_M30; break; case PERIOD_H4: new_timeframe = PERIOD_H1; break; case PERIOD_D1: new_timeframe = PERIOD_H4; break; case PERIOD_W1: new_timeframe = PERIOD_D1; break; case PERIOD_MN1: new_timeframe = PERIOD_W1; break; } if(new_timeframe!=PERIOD_CURRENT) { ChartSetSymbolPeriod(0,NULL,new_timeframe); } } else if(lparam=='K' || lparam=='k') { new_timeframe= PERIOD_CURRENT; switch(Period()) { case PERIOD_M1: new_timeframe = PERIOD_M5; break; case PERIOD_M5: new_timeframe = PERIOD_M15; break; case PERIOD_M15: new_timeframe = PERIOD_M30; break; case PERIOD_M30: new_timeframe = PERIOD_H1; break; case PERIOD_H1: new_timeframe = PERIOD_H4; break; case PERIOD_H4: new_timeframe = PERIOD_D1; break; case PERIOD_D1: new_timeframe = PERIOD_W1; break; case PERIOD_W1: new_timeframe = PERIOD_MN1; break; case PERIOD_MN1: new_timeframe = PERIOD_MN1; break; } if(new_timeframe!=PERIOD_CURRENT) { ChartSetSymbolPeriod(0,NULL,new_timeframe); } } break; } } //+------------------------------------------------------------------+
Why MT4(build 625) hang-up?
=== Step ===
(1) create a new chart
(2) drag and drop Expert Advisor ( testEA ) onto the chart
(3) repeat key press ( key is 'j' or 'k' )
(4) MT4 hang-up
<< text code (Expert Advisor) -- testEA.mq4 >>
It's just running fine for me.
Edit : I am using build 628.
Which problem are you trying to correct with these modifications ?
Well I included the additional cases so to avoid "Not all control paths return a value", although it could probably be better done with a default.
int new_timeframe can just be left at ENUM_TIMEFRAMES new_timeframe=PERIOD_CURRENT;
but it needed to be moved because it was declared locally to the first if and so had no value in the 2nd if
The code as posted will not compile in 625.
void OnChartEvent( const int id, // Event ID const long& lparam, // Parameter of type long event const double& dparam, // Parameter of type double event const string& sparam // Parameter of type string events ) { int new_timeframe; switch(id) { case CHARTEVENT_KEYDOWN: if(lparam=='J' || lparam=='j') { //ENUM_TIMEFRAMES new_timeframe=PERIOD_CURRENT; switch(Period()) { case PERIOD_M1: new_timeframe = PERIOD_M1; break; case PERIOD_M5: new_timeframe = PERIOD_M1; break; case PERIOD_M15: new_timeframe = PERIOD_M5; break; case PERIOD_M30: new_timeframe = PERIOD_M15; break; case PERIOD_H1: new_timeframe = PERIOD_M30; break; case PERIOD_H4: new_timeframe = PERIOD_H1; break; case PERIOD_D1: new_timeframe = PERIOD_H4; break; case PERIOD_W1: new_timeframe = PERIOD_D1; break; case PERIOD_MN1: new_timeframe = PERIOD_W1; break; } if(new_timeframe!=PERIOD_CURRENT) { ChartSetSymbolPeriod(0,NULL,new_timeframe); } } else if(lparam=='K' || lparam=='k') { new_timeframe= PERIOD_CURRENT; switch(Period()) { case PERIOD_M1: new_timeframe = PERIOD_M5; break; case PERIOD_M5: new_timeframe = PERIOD_M15; break; case PERIOD_M15: new_timeframe = PERIOD_M30; break; case PERIOD_M30: new_timeframe = PERIOD_H1; break; case PERIOD_H1: new_timeframe = PERIOD_H4; break; case PERIOD_H4: new_timeframe = PERIOD_D1; break; case PERIOD_D1: new_timeframe = PERIOD_W1; break; case PERIOD_W1: new_timeframe = PERIOD_MN1; break; case PERIOD_MN1: new_timeframe = PERIOD_MN1; break; } if(new_timeframe!=PERIOD_CURRENT) { ChartSetSymbolPeriod(0,NULL,new_timeframe); } } break; } }
I was changed source code.
But MT4 was hang-up. (>_<)/
<< MT4 hang-up >>
Well I included the additional cases so to avoid "Not all control paths return a value", although it could probably be better done with a default.
int new_timeframe can just be left at ENUM_TIMEFRAMES new_timeframe=PERIOD_CURRENT;
but it needed to be moved because it was declared locally to the first if and so had no value in the 2nd if
The code as posted will not compile in 625.
Bug was fixed.
It did not hang-up in MT4 build 646.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Why MT4(build 625) hang-up?
=== Step ===
(1) create a new chart
(2) drag and drop Expert Advisor ( testEA ) onto the chart
(3) repeat key press ( key is 'j' or 'k' )
(4) MT4 hang-up
<< text code (Expert Advisor) -- testEA.mq4 >>