Hi kenny, well when I put data in an array I imagine it as a grid so I can remember which elements contain which data, so I think of my_array[20][4] as a grid of 20 rows and 4 columns
so in other words i wanted to put my 20 variables into:
my_array[0,2]
my_array[1,2]
my_array[2,2]
my_array[3,2]
my_array[4,2] etc
nice one, thanks kenny im using that array because I’m trying to modify a function from coders guru to monitor multiple lines to see of they crossed instead of just the two he wrote it for but i was looking at it some more and his code goes like this:
call to the function is: int isCrossed = Crossed (shortEma,longEma);
int Crossed (double line1 , double line2)
{
static int last_direction = 0;
static int current_direction = 0;
I was thinking, as he initializes current_direction and last_direction to 0 would that not give false results the first time it is run ?
for instance if the new direction is up, current_direction=1
so in the next line:
if(current_direction !=last_direction) //changed
would it not therefore indicate the lines crossed the first time it is run even if they didnt as last_direction would still be at zero from when it was initialized ?
How about this ? I think the extra line would cause a value of 3 to be returned to the function call if the last direction was still at zero so it would not open a buy or a sell order unless the return was a 1 or a 2
The second time around the fucnction would behave normaly and change last direction to a 1 or a 2 if the lines crossed.
int Crossed (double line1 , double line2)
{
static int last_direction = 0;
static int current_direction = 0;
Edit: actually that wouldnt work either because then the second time around it would be comparing the current_direction with last_direction at 3 so it would see that as a line cross because they are not equal hmmm this is not an easy problem to solve
yep that would do it !!
I wonder how many people have used that function in their EA’s without realizing that error is in it, the function was from that Coders Guru tutorial on the mql4.com site, its dated 2005 !!
SDC, when I am just comparing two MA’s at a time, I use the iMACD function and put my MA values in that. It saves space and is easier to manage for me.
If the MACD is a positive value, the fast MA is above the slow. If it is a negative value, the fast MA is below. If it went from neg to positive or vice versa, it crossed.
i ended up doing it a different way because i decided i need to work with multiple lines so I did it by using an array to hold all the values then comparing the relevent array elements