| / | Forum |
|
Brygada
2010.11.13 22:06
Error: variable not defined. What can be wrong here? Thanks. int start() { for(int a=0;a<Bars;a++) double A = High[a] – Open[a]; return(0); } |
|
This article dwells on the ways of transferring an indicator code into an Expert Advisor Code and on writing Expert Advisors with no calling to custom indicators, and with the whole program code for the calculation of necessary indicator values inside the Expert Advisor. This article gives a general scheme of Expert Advisor changing and the idea of building an indicator function based on a custom indicator. The article is intended for readers, already having experience of programming in MQL4 language. |
|
jjc
2010.11.13 22:17
Brygada: The - symbol as posted in your code is ASCII symbol 150, not ASCII symbol 45.
Error: variable not defined. |
|
Brygada
2010.11.13 22:30
jjc: The - symbol as posted in your code is ASCII symbol 150, not ASCII symbol 45.
|
|
jjc
2010.11.13 22:38
Brygada: Thanks. Can you please correct the code to be usable.? I know it looks identical, but the - in this code is a different character... int start() { for(int a=0;a<Bars;a++) double A = High[a] - Open[a]; return(0); } |
|
Brygada
2010.11.13 22:58
jjc: I know it looks identical, but the - in this code is a different character... It works. Thanks for your help. |
|
ex4tomq4
2010.11.13 23:07
int start() { double A = 0.0; for(int a=0; a < Bars; a++){ A = High[a] - Open[a]; // if you put the 'double A' here then the ea will create 'A' variable each time the loop returns to the next increment value. } // as a result you will not get your desired value. Initialize the 'A' variable before the loop starts. return(0); } |
2030 |
gordon
2010.11.14 00:08
ex4tomq4: int start() { double A = 0.0; for(int a=0; a < Bars; a++){ A = High[a] - Open[a]; // if you put the 'double A' here then the ea will create 'A' variable each time the loop returns to the next increment value. } // as a result you will not get your desired value. Initialize the 'A' variable before the loop starts. return(0); } The code won't work as 'expected' because variable A will simply be equal to High[Bars-1]-Open[Bars-1] at the end of the loop. The loop actually does nothing, A is overwritten each iteration with a value that does not rely on any previous iteration values. Your explanation of why it doesn't work is not entirely correct in MQL4 (maybe it is in other programming languages). Example: int start() { int cnt1; // declared outside loop for(int i = 0; i < 5; i++) { cnt1 = cnt1 + i; Print("cnt1 = ", cnt1); } for(int j = 0; j < 5; j++) { int cnt2 = cnt2 + j; // declared inside loop Print("cnt2 = ", cnt2); } } Output: 2010.11.13 23:02:37 Testing USDCHF,H4: cnt2 = 10 2010.11.13 23:02:37 Testing USDCHF,H4: cnt2 = 6 2010.11.13 23:02:37 Testing USDCHF,H4: cnt2 = 3 2010.11.13 23:02:37 Testing USDCHF,H4: cnt2 = 1 2010.11.13 23:02:37 Testing USDCHF,H4: cnt2 = 0 2010.11.13 23:02:37 Testing USDCHF,H4: cnt1 = 10 2010.11.13 23:02:37 Testing USDCHF,H4: cnt1 = 6 2010.11.13 23:02:37 Testing USDCHF,H4: cnt1 = 3 2010.11.13 23:02:37 Testing USDCHF,H4: cnt1 = 1 2010.11.13 23:02:37 Testing USDCHF,H4: cnt1 = 0 So actually it works fine. There's some more details about this here -> http://forum.mql4.com/22626. |
|
Cosan
2012.03.05 20:43
Hi all, I have similar problem.. Altough I think that I wrote the code correct, it says 'Buy1' - variable not defined.. When I replaced the fist line with the second then I got 'Buy2' - variable not defined. Can anyone help me regarding this problem.. Thnx in advance.. int start() { if (EachTickMode && Bars != BarCount) TickCheck = False; double EMAS = iMA("EURUSD", PERIOD_H1, 7, 0, MODE_EMA, PRICE_CLOSE, Current + 0); double Buy1 = Fibo1 + Markup ;
|
|
Cosan
2012.03.05 20:46
ok.. I found out that I didn't put a ";" after the defination of Mark up..
|