Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Question regarding Crossed function
Hi Coders Guru,
Thank you very much for your lessons! I'm still learning mq4 and look forward to reading more of your tutorials.
I was following along the My_First_EA.mq4 code and have a question about the Crossed() function.
The first time the Crossed() function is called, current_direction != last_direction will always be TRUE, because upon the first call:
static int last_direction = 0; and current_direction is immediately assigned 1 or 2.
How about testing to see if last_direction = 0, which would make sure of Return(0) upon the first call of Crossed(). (see below)
Thank you again,
Bachy20
=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
int Crossed (double line1 , double line2)
{
static int last_direction = 0;
static int current_direction = 0;
if(line1>line2)current_direction = 1; //up
if(line1<line2)current_direction = 2; //down
//current direction will always be different from
//last direction, upon first use of this function
if(current_direction != last_direction) //changed
{
if (last_direction == 0) //return(0) upon first use of this function
{
last_direction = current_direction;
return (0);
}
else
{
last_direction = current_direction;
return (last_direction);
}
}
else
{
return (0);
}
}
Thanks for all your work.
Great Work Guruji... Keep up the good work...
Thanks a ton for the awesome tutorials
Dear Codeguru,
Thanks a lot for the awesome tutorial provided by you, it will be a great help for newbies in like me :-)
Thanks again.