You have to create a "counting" variable and also two "timer" variables so you can determine if it is a new day. The counting variable essentially acts as an on/off switch; if it is "0" it will allow your code to run, if it is "1" it will not let your code run. I use the "on/off switch" coding algorithm for a lot of things in my EA's, and likewise with the timer algorithm, I use it for new minutes, new 15 min bars etc etc. Of course with each new counter you introduce you have to create a new variable name for that counter, otherwise it will get reset if you re-use the same variable in another counting situation.
int counter=0;
int NewDay=0;
int OldDay=0;
start()
NewDay=Day()
if(NewDay!=OldDay)
{
if(counter==0)
{
// run your code here
counter=1;
OldDay=NewDay;
}
counter=0;
}
I had an after thought. In this case you don't actually have to use the counting variable because you run the code only one time; however, if you wanted to run the code say 5 time in the NewDay you would have to insert a counting variable and of course adjust the critical value in the Conditional-IF operator accordingly.
Thus, without the counting variable the code would look like this:
int NewDay=0;
int OldDay=0;
start()
NewDay=Day()
if(NewDay!=OldDay)
{
// run your code here
OldDay=NewDay;
wow! thank you for your answer i really got it :)

- 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 I am an amatur with code which trying to find is way through MQL :)
im building an indicator but its work consistly all the time whan i only want it to work once a day...
how can i do it?
the next step is to change this indicator and make it an EA, but because its works all the time its keep open positions, but what i meant is it to open one position whan it finds the right situation,
thanks.