for loops don't work in EAs what am I missing?

To add comments, please log in or register
GEORGIOS VERGAKIS
481
GEORGIOS VERGAKIS  

Hi everyone

I have some great trading ideas, well tested in manual trading and in some basic MQL4 code,   but I lack experience in making EAs.  

The code works fine in indicators,  but it fails in EA.    For example:  For Loops used to fill in and update arrays,   they work fine in indicators,

and yet the EAs  complile ok, no errors,  and the for-loop just doesn't run at all,   what I am I missing here?


ie:


for (J=30;J>=0;J--)

{

myarray[J]=function(J);

}



I tested everything,  arrays work on their own, it is the for /while loops that simply don't work,  even if you ask them to do J=J+1  for J times

Icham Aidibe
11675
Icham Aidibe  
GEORGIOS VERGAKIS:

Hi everyone

I have some great trading ideas, well tested in manual trading and in some basic MQL4 code,   but I lack experience in making EAs.  

The code works fine in indicators,  but it fails in EA.    For example:  For Loops used to fill in and update arrays,   they work fine in indicators,

and yet the EAs  complile ok, no errors,  and the for-loop just doesn't run at all,   what I am I missing here?


ie:


for (J=30;J>=0;J--)

{

myarray[J]=function(J);

}



I tested everything,  arrays work on their own, it is the for /while loops that simply don't work,  even if you ask them to do J=J+1  for J times

for (J=ArraySize(myarray)-1;J>=0;J--)
{
myarray[J]=function(J);
}
William Roeder
20208
William Roeder  

Arrays work fine. For/while loops work fine. Do you really expect  an answer? We can't see your broken code.There are no mind readers here and our crystal balls are cracked.

Post all the relevant code. Like where you declare myarray. You say "code works fine in indicators,  but it fails in EA." Is myarray a buffer? There are no buffers in EAs.

GEORGIOS VERGAKIS
481
GEORGIOS VERGAKIS  
whroeder1:

Arrays work fine. For/while loops work fine. Do you really expect  an answer? We can't see your broken code.There are no mind readers here and our crystal balls are cracked.

Post all the relevant code. Like where you declare myarray. You say "code works fine in indicators,  but it fails in EA." Is myarray a buffer? There are no buffers in EAs.


I put even this simple loop  and it doesn't work,   it compliles ok, it runs,  but it doesn't run,  I tried all steps,  checking with Alter()  function to see tick by tick,  nothing happens,  and it's the for loop that's the problem.  No I don't use buffers or anything.  Just this loop inside the OnTick function....


for (J=30;J>=0;J--)

{

A=A+J;

}


could it be the variable J?  does it need to be declared withthin the loop?


As I said, I am new to MT4, and even more so to EAs,  I can detect errors fast,   but this one compliles with no errors.  Today is Saturday there no ticks,   but I was testing this on trading days and the for loops wouldn't run, even though everything else in the OnTick function run.   I will try again next week,   the only warning I remember seeing once was 'expression not boolean'

William Roeder
20208
William Roeder  
  1. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor
  2. GEORGIOS VERGAKIS: for (J=30;J>=0;J--)
    Apparently incapable of following requests, so that someone could possibly help you. What part of "Post all the relevant code. Like where you declare ..." was unclear?

  3. GEORGIOS VERGAKIS: it's the for loop that's the problem
    As previously stated, there is nothing wrong with that loop. Use the debugger or print out your variables, and find out why.
Marco vd Heijden
Moderator
12702
Marco vd Heijden  

You can just use it in OnTimer() function in stead of OnTIck() no need to wait for next week.

And also:

whroeder1:
  1. "Post all the relevant code.
Icham Aidibe
11675
Icham Aidibe  
GEORGIOS VERGAKIS:

Hi everyone

I have some great trading ideas, well tested in manual trading and in some basic MQL4 code,   but I lack experience in making EAs.  

The code works fine in indicators,  but it fails in EA.    For example:  For Loops used to fill in and update arrays,   they work fine in indicators,

and yet the EAs  complile ok, no errors,  and the for-loop just doesn't run at all,   what I am I missing here?


ie:


for (J=30;J>=0;J--)

{

myarray[J]=function(J);

}



I tested everything,  arrays work on their own, it is the for /while loops that simply don't work,  even if you ask them to do J=J+1  for J times

Did you try ? 

To add comments, please log in or register