Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information
We have reached the edge of the moon in our way to the truth, I’m not under the impact of alcoholic poisoning (I don’t drink at all), but I’m so happy to reach the last part of explaining or first expert advisor. Yes! This is the last part of the expert advisor lesson.
I hope you enjoyed the journey discovering how to write our simple yet important expert advisor.
Yep, excellent work, thanks for all this amazing help. It's going to take a few days to get to grips with all this but it's been really helpful to have your lessons.
you have decleared the two static variables inside the block of the function. then every time start function recieves a quote it will call the crossed function,and every time when start calls crossed, crossed will first initilize the two varibles to zero,so how could you compare current_direction with last_direction?
int Crossed (double line1 , double line2)
{
static int last_direction = 0;
static int current_dirction = 0;
you have decleared the two static variables inside the block of the function. then every time start function recieves a quote it will call the crossed function,and every time when start calls crossed, crossed will first initilize the two varibles to zero,so how could you compare current_direction with last_direction?
int Crossed (double line1 , double line2)
{
static int last_direction = 0;
static int current_dirction = 0;
There are two kinds of variables in MQL4, normal variables and static variables;
The static variables are very like the normal variables with only one extra feature:
The initialization of the static variables occurs only one time.
Which means if you write a line of code like that:
static int last_direction = 0;
You mean:
If this is the first call of the program, initialize the variable to 0, else (if it's the second, third, fourth etc call) don't initialize the variable again.
But if you used a normal variable instead of static variable, every time you call your program the initialization of the variable will be occurred.