Question from beginner - page 2

 

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

Reason: