1. Make a global variable "int modified_this_bar = 0;".
2. Before modifying, always check that (modified_this_bar == 0)
3. When modification has been successful, "modified_this_bar = 1;"
4. When a new bar occurs "modified_this_bar = 0;"
.
For #4:
1. Make a global variable called "int last_bar;"
2. "int last_bar = Time[0];" int your init() function for initialization simplicity (can be made better later on)
3. At every tick, if(last_bar != Time[0]), a new bar has appeared.
4. Update last_bar to Time[0] and "modified_this_bar = 0;"
.
You should always make sure that your settings you're trying to modify have actually changed. No use issuing an order modification request if the variables remain the same.
.
As for making it modify only at certain times inside a bar, you need to use a bit of simple math and https://docs.mql4.com/dateandtime depending on your timeframe.
I'll let you figure the time out, it should be straightforward after this.
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.
To modify once per bar:
1. Make a global variable "int modified_this_bar = 0;".
2. Before modifying, always check that (modified_this_bar == 0)
3. When modification has been successful, "modified_this_bar = 1;"
4. When a new bar occurs "modified_this_bar = 0;"
.
For #4:
1. Make a global variable called "int last_bar;"
2. "int last_bar = Time[0];" int your init() function for initialization simplicity (can be made better later on)
3. At every tick, if(last_bar != Time[0]), a new bar has appeared.
4. Update last_bar to Time[0] and "modified_this_bar = 0;"
.
You should always make sure that your settings you're trying to modify have actually changed. No use issuing an order modification request if the variables remain the same.
.
As for making it modify only at certain times inside a bar, you need to use a bit of simple math and https://docs.mql4.com/dateandtime depending on your timeframe.
I'll let you figure the time out, it should be straightforward after this.
.
Jon