Hi Friends,
I know the problem is so simple so that I coudn't solve it as I'm not expert on coding yet...
The result will be like a = 0, 2, 4, 6, 8, 10,... It's okay until a certain condition will be fulfilled but my problem is How to initialize the variables again to a = 0 / b = 2 once a condition is fulfilled. Compiling works well as a solution but it must be an automated solution inside the code.
Thank you.
a = 0; b = 2;
Thank you it's helpful but what if the variables are externals
extern int a = 0; extern int b = 2;
Thank you it's helpful but what if the variables are externals
Same
Unless you declare them using input instead of extern (in which case you can not change their values)
Same
Unless you declare them using input instead of extern (in which case you can not change their values)
I need a solution to initialize their values as if I restart the EA or Compile at the middle of calculations, I think as I mentionned that "Compiling" is the best to understand what I meant. As you know the result of (a += b) is a = 0, 2, 4, 6, 8, 10... until I hit "Compile" button witch leads to initialize (a = 0) & (b = 2) and the calculation restarts again. In short, I need a solution instead of compiling.
Thank you.
You have the solution. When you want to reset the values, use the code:
a = 0; b = 2;
You need to decide when you want that to happen. Maybe on a new day, maybe after you click a button, maybe after a certain value is reached. Endless choices.
e.g.
a += b; if(a >= 100) { a = 0; b = 2; }
You have the solution. When you want to reset the values, use the code:
You need to decide when you want that to happen. Maybe on a new day, maybe after you click a button, maybe after a certain value is reached. Endless choices.
e.g.
Your code works well in case values are entered inside the code but in this case they are external
extern int a = 0; extern int b = 2;
The user may enter different values than the example above this is why I can't use your code.
I don't know maybe a command that restarts the EA ?
Restarting the EA is never the right answer. Any code that needs recompiling / restarting to work correctly has a problem.
Try working with an intermediate variable rather than changing the value of the extern variables directly.
extern int a = 0; extern int b = 2; // ... int c = a; // ... c += b; if(c>=100) c = a;
Restarting the EA is never the right answer. Any code that needs recompiling / restarting to work correctly has a problem.
Try working with an intermediate variable rather than changing the value of the extern variables directly.
You're the Best !!

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi Friends,
I know the problem is so simple so that I coudn't solve it as I'm not expert on coding yet...
The result will be like a = 0, 2, 4, 6, 8, 10,... It's okay until a certain condition will be fulfilled but my problem is How to initialize the variables again to a = 0 / b = 2 once a condition is fulfilled. Compiling works well as a solution but it must be an automated solution inside the code.
Thank you.