-
int ticket,i,total,result; ⋮ double faster = iMACD(…), slower = iMACD(…), faster_2 = iMACD(…), slower_2 = iMACD(…), total = OrdersTotal();
You defined total at the top, you can't define it a second time or change its type to double.
-
double faster_2 = iMACD(NULL,PERIOD_H4,
On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4 2019.05.20
-
You defined total at the top, you can't define it a second time or change its type to double.
-
On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4 2019.05.20
Thanks
I think I understand your first answer. I need a semi colon at the end of where I define my double variables right ? Then I should be able to assign a value to "totals".
Like this
void OnTick() { //--- int ticket,i,total,result; double faster = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1), //MODE_SIGNAL faster_2 = iMACD(NULL,PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_2 = iMACD(NULL,PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); //MODE_SIGNAL total = OrdersTotal(); }
I think I understand what your referenced error handling code is doing but not completely. I don't think I completely understand this part "
period = (ENUM_TIMEFRAMES)_Period;
Thanks
period = (ENUM_TIMEFRAMES)_Period;
I didn't post that code, you didn't originally post that code. Go back and re-read #1.2 and its accompanying link.
I didn't post that code, you didn't originally post that code. Go back and re-read #1.2 and its accompanying link.
On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4 2019.05.20
The code shown in that link is this:
bool download_history(ENUM_TIMEFRAMES period=PERIOD_CURRENT){ return download_history(_Symbol, period); } bool download_history(SYMBOL symbol, ENUM_TIMEFRAMES period=PERIOD_CURRENT){ if(period == PERIOD_CURRENT) period = (ENUM_TIMEFRAMES)_Period; ResetLastError(); datetime other = iTime(symbol, period, 0); if(_LastError == 0 && other != 0) return true; if(_LastError != ERR_HISTORY_WILL_UPDATED && _LastError != ERR_NO_HISTORY_DATA ) PrintFormat("iTime(%s,%i) Failed: %i", symbol, period, _LastError); return false; }
I see your referenced #2 =
double faster_2 = iMACD(NULL,PERIOD_H4,
HA HA HA .... wait wait wait. Am I making this too complicated ?
Are you saying that the only thing I have to do is change "NULL" to Symbol() in order to call the specific symbol(s)/TF(s) referenced ?
So from what I'm reading it looks like I can write like this ?
double faster_2 = iMACD(Symbol(),PERIOD_H4 //or "EURUSD" or whatever "Symbol" string ?
Please confirm this
Thanks

- docs.mql4.com
-
Yes you are. You have to call the function provided (with H4) at the beginning of start and if it returns false, you return and wait for a new tick. Otherwise, your MACD(H4) will be bogus.
-
I said no such thing. I said "unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values." See № 1
- As far as NULL, I don't use NULL.
- On MT4, you can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not. OrderSend does not.
- Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
- Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
- MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
- Cloud Protector Bug? - MQL4 programming forum 2020.07.25
-
Yes you are. You have to call the function provided (with H4) at the beginning of start and if it returns false, you return and wait for a new tick. Otherwise, your MACD(H4) will be bogus.
-
I said no such thing. I said "unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values." See № 1
- As far as NULL, I don't use NULL.
- On MT4, you can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not. OrderSend does not.
- Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
- Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
- MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
- Cloud Protector Bug? - MQL4 programming forum 2020.07.25
I'm confused about this
Isn't the if(expression) a call to M5 ?
Like this ?
void OnTick() { //--- int ticket,i,total; double faster_1 = iMACD("EURUSD",PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_1 = iMACD("EURUSD",PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1), //MODE_SIGNAL faster_2 = iMACD("EURUSD",PERIOD_M5,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_2 = iMACD("EURUSD",PERIOD_M5,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1), //MODE_SIGNAL faster_3 = iMACD("EURUSD",PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_3 = iMACD("EURUSD",PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); //MODE_SIGNAL total = OrdersTotal(); if(total < 1) { if(faster_1 > slower_1 && faster_2 > slower_2)
Or does it need to be like this ? If so I don't completely understand why.
void OnTick() { //--- double faster_1 = iMACD("EURUSD",PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_1 = iMACD("EURUSD",PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1), //MODE_SIGNAL faster_2 = iMACD("EURUSD",PERIOD_M5,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_2 = iMACD("EURUSD",PERIOD_M5,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1), //MODE_SIGNAL faster_3 = iMACD("EURUSD",PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_3 = iMACD("EURUSD",PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); //MODE_SIGNAL if(faster_3>slower_3) Print ("H4 Higher = True"); //some code here if(faster_1>slower_1) etc etc. else Print ("H4 Higher = False"); return; if(faster_3<slower_3) Print ("H4 Lower = True"); else Print ("H4 Lower = False"); return;
Thanks
faster_2 = iMACD("EURUSD",PERIOD_M5,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_2 = iMACD("EURUSD",PERIOD_M5,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1), //MODE_SIGNAL ⋮ if(faster_1 > slower_1 && faster_2 > slower_2)
The if only compares two sets of doubles. If those doubles have garbage then your compare is bogus.
What part of "you must handle 4066/4073 errors before accessing" was unclear? Did you follow #1.2 or #5.1?
YOU DID NOT. So your doubles are bogus as is your compares.
The if only compares two sets of doubles. If those doubles have garbage then your compare is bogus.
What part of "you must handle 4066/4073 errors before accessing" was unclear? Did you follow #1.2 or #5.1?
YOU DID NOT. So your doubles are bogus as is your compares.
Regarding #1.2
I'm sure your instruction is clear but I'm struggling make sense of the information.
How can I tell if I'm getting errors that need to be handled.
Shouldn't Print(GetLastError()); give me these errors in order to handle them ?
I get zero for GetLastError()
void OnTick() { //--- double faster_1 = iMACD(NULL,PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_1 = iMACD(NULL,PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1), //MODE_SIGNAL faster_2 = iMACD(NULL,PERIOD_M5,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_2 = iMACD(NULL,PERIOD_M5,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1), //MODE_SIGNAL faster_3 = iMACD(NULL,PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_3 = iMACD(NULL,PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); //MODE_SIGNAL if(faster_3>slower_3) Print ("H4 Higher = True"," ","Code = ",GetLastError()); else Print ("H4 Higher = else False"," ","Code = ",GetLastError()); if(faster_3<slower_3) Print ("H4 Lower = True"," ","Code = ",GetLastError()); else Print ("H4 Lower = else False"," ","Code = ",GetLastError()); if(faster_2>slower_2) Print ("M5 Higher = True"," ","Code = ",GetLastError()); else Print ("M5 Higher = else False"," ","Code = ",GetLastError()); if(faster_2<slower_2) Print ("M5 Lower = True"," ","Code = ",GetLastError()); else Print ("M5 Lower = else False"," ","Code = ",GetLastError());
-
No. The moment you call a second function, you've lost the error from the first.
Check your return codes, and report your errors.
Don't look at GLE/LE unless you have an error. Don't just silence the compiler, it is trying to help you.
What are Function return values ? How do I use them ? - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 ArticlesOnly those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.
- I explained the problem. I gave you the solution. I told you to call it before accessing values. You have ignored me three times. I can't help you.
-
No. The moment you call a second function, you've lost the error from the first.
Check your return codes, and report your errors.
Don't look at GLE/LE unless you have an error. Don't just silence the compiler, it is trying to help you.
What are Function return values ? How do I use them ? - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 ArticlesOnly those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.
- I explained the problem. I gave you the solution. I told you to call it before accessing values. You have ignored me three times. I can't help you.
Sorry I'm just not understanding how to see the errors. I always get 0.
Compiler has 0 errors and 0 warnings
void OnTick() { //--- double faster_1 = iMACD(NULL,PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_1 = iMACD(NULL,PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1), //MODE_SIGNAL faster_2 = iMACD(NULL,PERIOD_M5,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_2 = iMACD(NULL,PERIOD_M5,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1), //MODE_SIGNAL faster_3 = iMACD(NULL,PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_3 = iMACD(NULL,PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); //MODE_SIGNAL Print (faster_3," ", GetLastError()); Print (slower_3," ", GetLastError()); }
0 19:22:58.738 testcodes EURUSD,M5: 1.512320472575447e-05 0 0 19:23:03.296 testcodes EURUSD,M5: -0.001422931064830824 0 0 19:23:03.296 testcodes EURUSD,M5: 1.512320472575447e-05 0 0 19:24:06.211 testcodes EURUSD,M5: -0.001422931064830824 0 0 19:24:06.211 testcodes EURUSD,M5: 1.512320472575447e-05 0 0 19:24:17.002 testcodes EURUSD,M5: -0.001422931064830824 0 0 19:24:17.002 testcodes EURUSD,M5: 1.512320472575447e-05 0 0 19:24:17.081 testcodes EURUSD,M5: -0.001422931064830824 0 0 19:24:17.081 testcodes EURUSD,M5: 1.512320472575447e-05 0 0 19:24:19.541 testcodes EURUSD,M5: -0.001422931064830824 0 0 19:24:19.541 testcodes EURUSD,M5: 1.512320472575447e-05 0 0 19:24:19.885 testcodes EURUSD,M5: -0.001422931064830824 0 0 19:24:19.885 testcodes EURUSD,M5: 1.512320472575447e-05 0I don't get errors from this either if I understand this at all.
void OnTick() { //--- double faster_1 = iMACD(NULL,PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_1 = iMACD(NULL,PERIOD_M1,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1), //MODE_SIGNAL faster_2 = iMACD(NULL,PERIOD_M5,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_2 = iMACD(NULL,PERIOD_M5,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1), //MODE_SIGNAL faster_3 = iMACD(NULL,PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN slower_3 = iMACD(NULL,PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); //MODE_SIGNAL ResetLastError(); if(faster_3) { if(GetLastError()!=0) Print("Error"," ",GetLastError()); } return; }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I get compiler error "variable already defined". Why
Please advise
Thanks