Cannot compile as variable is not defined.....however variable will come from an indicator which will be linked. How can I compile EA that is coded to accept variables from an external indicator?
Use the SRC button to paste Source code.
The values in the iCustom call need to be explicit values. If variables, you need to define them. Post the indicator code and we will be able to see what it is you are trying to do. The iCustom is setting values in the indicator. If it requires the letter H as a string then you will need to write "H", in other words put double quotes around it.
Hi,
I am a newbie at this so please be patient. I am practising on an EA that uses an external indicator to pass variables to the EA. However, after coding the EA it will not compile as there is an error message stating "variables not defined". How can I get the EA to compile.
Here is the relevant section of code:-
double L_1=iCustom(NULL,0,"rocseparate",H,P,B,A,1,0);
double L_5=iCustom(NULL,0,"rocseparate",H,P,B,A,5,0);
//------------------------------------------------------------------------5b--
if (L_5>=-Level && L_1<L_5)
"variables not defined". So do it In the code of the indicator simply to read at... https://book.mql4.com/samples/iroc
extern int History =5000; // Amount of bars in calculation history
extern int Period_MA_1=21; // Period of calculated MA
extern int Bars_V =13; // Amount of bars for calc. rate
extern int Aver_Bars =5; // Amount of bars for smoothing
define H, P, B, A in iCustom, or directly put value inside it
//double L_1=iCustom(NULL,0,"rocseparate",H,P,B,A,1,0); int H, P, B, A; double L_1=iCustom(NULL,0,"rocseparate",H,P,B,A,1,0); double L_1=iCustom(NULL,0,"rocseparate", 5000, 21, 13, 5, 1, 0);
And please reply back tell us the result
LOL. onewithzacchy posted a link in another thread.
https://book.mql4.com/samples/shared
I assume this is where your code came from.
double L_1=iCustom(NULL,0,"rocseparate",H,P,B,A,1,0); double L_5=iCustom(NULL,0,"rocseparate",H,P,B,A,5,0); //-------------------------------------------------------------- 5b -- if (L_5>=-Level && L_1<L_5)
The H,P,B,and A variables made no sense out of context. BUT, in the immediately preceding lines in that example they are defined!
//--------------------------------------------------------------- 5 -- // Trading criteria int H= 1000; // Amount of bars in calc. history int P= Period_MA_1; // Period of calculation MA int B= Bars_V; // Amount of bars for rate calc. int A= Aver_Bars; // Amount of bars for smoothing //-------------------------------------------------------------- 5a -- double L_1=iCustom(NULL,0,"rocseparate",H,P,B,A,1,0); double L_5=iCustom(NULL,0,"rocseparate",H,P,B,A,5,0); //-------------------------------------------------------------- 5b -- if (L_5>=-Level && L_1<L_5)
Hi Guys,
thank you soo much for your help. OK, let me summarise where I am now. I still cannot compile and it comes up with the same error messages - "variable not defined"
Dabbler, you are indeed correct. The code I am using comes from https://book.mql4.com/samples/shared and it is Problem 30. However, even after I have cheated and just pasted the whole code into the Editor I still get the same error message when I compile.
DeVries - thanks for your answer, you are correct but it was my fault in not sharing the whole story. Sorry! :-(
onewithzachy - yup that would work but I need to link the code to the indicator.
Given that I am just learning how to spell "MQL4" could you guys help and tell me why the examples in a learning text i.e. Problem 30 in the above URL are not compiling. I used to have a full head of hair but it is thinning fast and the wife is looking at me strangely!!
LOL. onewithzacchy posted a link in another thread.
Did you mean this thread ?, The guy has iCustom problem too. I've highlighted the variables that need to be declared, why don't you make those 2 lines as comment and compile again.
double L_1, L_5; L_1=iCustom(NULL,0,"rocseparate",H,P,B,A,1,0); L_5=iCustom(NULL,0,"rocseparate",H,P,B,A,5,0);
... and this below, as far as I know we're not allowed to add ";" inside if
if (L_5>=-Level && L_1<L_5) // <<== what the ...
If you still have compile error, double click on the report will usually point you to the error line and column.
Or read us the compile error messages. :)
what da ya know, I didn't read dabbler post entirely. :), dabbler codes is correct.
Now double click the error messages and read them to us.
thank you soo much for your help. OK, let me summarise where I am now. I still cannot compile and it comes up with the same error messages - "variable not defined"
Dabbler, you are indeed correct. The code I am using comes from https://book.mql4.com/samples/shared and it is Problem 30. However, even after I have cheated and just pasted the whole code into the Editor I still get the same error message when I compile.
I just did this and the message I get is
'amp' - variable not defined
The clue is in the first word which you omitted!
Now there are lots of this sort of error
if (Total==0 && Opn_S==true) // No new orders +
This code is gibberish as it stands. I think that what has happened is that a text editor has mis-interpreted
&&
into
&&
if in your pasted code you do a search and replace of the spurious term "&&" for the correct double ampersand "&&" it will then compile and may even work.
I should point out that was a VERY nasty error in a tutorial and not something a beginner should be expected to have handled.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I am a newbie at this so please be patient. I am practising on an EA that uses an external indicator to pass variables to the EA. However, after coding the EA it will not compile as there is an error message stating "variables not defined". How can I get the EA to compile.
Here is the relevant section of code:-
double L_1=iCustom(NULL,0,"rocseparate",H,P,B,A,1,0);
double L_5=iCustom(NULL,0,"rocseparate",H,P,B,A,5,0);
//------------------------------------------------------------------------5b--
if (L_5>=-Level && L_1<L_5)