MQL4 buffer trick, I cant believe MQL4 is that weird!

 

Hello,

When I check how indicator run in Tester, the buffer show up wrong value. Here is the code.

Somehow MQL4 read the "condition(i)" incorrectly. I check, check, check, go back to the original indicator to make sure that it works fine.

if((buy1[i]==1 && condition(i)<6)    signal[i]=2;

...
double condition(int shift){
if((NULL,0,....,shift))!=EMPTY_VALUE)return(iCustom(NULL,0,....,shift));
 else
 return(0);

Finally, I figure out 1 way to correct it. Simply, create a buffer to track that condition."new_buffer[i]=condition(i);"

Then MQL4 works correctly.

However, I find it quite stupid somehow.

Can you tell me why MQL4 works that way and is the any better way to fix this issue?

Thank you.

HHCFX

if((buy1[i]==1 && condition(i)<6)    signal[i]=2;

new_buffer[i]=condition(i);
...
double condition(int shift){
if((NULL,0,....,shift))!=EMPTY_VALUE)return(iCustom(NULL,0,....,shift));
 else
 return(0);
 
  1. Do you really expect an answer? We have no idea what condition(i) is. There are no mind readers here and our crystal balls are cracked.

  2. Do you really expect an answer? "Why MQL4 works" what way? There are no mind readers here and our crystal balls are cracked.

  3. Do you really expect an answer? "What issue?" There are no mind readers here and our crystal balls are cracked.

  4. Likely you are using a variable value from the previous iteration, which means you can't process bar zero more than once, ever. Put it in a buffer so you can restore it, or only process bar zero once, or save and restore them when processing bar zero.
 

The new buffer doesnt do any job at all, just for me to check the value of "condition(i)". This new buffer is not used anywhere else.

But it still make the code read the value correctly.

Reason: