How does your EA's algorithm work?
In this chapter we will discuss how the algorithm works with the parts of your EA and how it will act.
Your EA's modular system
Your EA consists out of modules the algorithm interacts with. It's because of the modulairity that you are able to create any EA. The modules are divided into three categories:
- Modules which prevent opening
- Module for opening
- Modules for closing
Read more about Modules. As you've seen in the image above, the algorithm will interact with one or more modules. In the next chapter we will go into detail about this.
Your EA's behaviour
Your EA's algorithm will behave differently depending on its state:
- There are no open orders
- There are one or more open orders
No open orders
When no orders are opened, all the EA does is wait for an Open Signal. When the signal activates, it will open an order, unless a Prevent Open module blocks it.
Setup: You've got one Prevent Open module: Maximum spread. The module is set to only allow a maximum of 1.3 pips of spread.
Situation: There are no open orders.
A new quote is processed: The current spread on the Pair (f.e. AUDCAD) is 1.5 pips, the algorithm will now read from the Maximum spread module that it is not allowed to open any orders, so it will not evaluate it's Open Signals. Once the spread drops to 1.3 or lower, the Open Signal is evaluated. If the Open Signal activates an order will be opened.
One or more open orders
When orders are open, your EA will evaluate if the open orders should be closed, based on if a SL/TP was hit or a Close Signal has activated. When SL/TP is hit, or a Close Signal actives, it will first check if a new order would be (hypothetically) opened after closing the current order. This is done by evaluating Open signals (taking into account Modules which prevent opening) and Close Signals. So, the same process, as when there are no open orders, is evaluated. If an order would (hypothetically) not be opened, the order will be closed. Also, the EA will evaluate if additional orders have to be opened. Additional orders will only be opened when an Open signal activates, thus after being inactive for at least 1 processed quote.
Setup: You've got one Take Profit module and one Stop Loss module, both set at 10 pips. You've got one Prevent Open module: Time gap between orders. The module is set so that it allows an order to be opened 60 minutes after a previous order was closed.
Situation: There is one open order. The Open Signal is currently active. The open order's TP is hit.
The Algorithm will read that the order should be closed because the TP was hit. Before closing, it will evaluate if it should indeed close the order, or if a new order would be opened directly after closing. Since the Time gap between orders module would block opening an order after closing the current order, the Open Signal is discarded and the current order will be closed.
Setup: You configured your EA for allowing multiple open orders. You've got one Take Profit module and one Stop Loss module, both set at 10 pips. You've got one Prevent Open module: Time gap between orders. The module is set so that it allows an additional order to be opened 60 minutes after a previous order was opened.
Situation: There is one open order which was opened 30 minutes ago. The Open Signal is currently active.
A new quote is processed: The algorithm will read that the currently opened order should not be closed yet. The Open Signal is active, but it has been active since opening the previous order. Since this is still the same active signal, an additional order will not be opened. The Open Signal deactivates and reactivates, the algorithm will now check if a Prevent Open module prevents opening an additional order. This is the case, because the previous order was opened 30 minutes ago, so an additional order will not be opened yet. When the 60 minutes has passed, the additional order is still not opened, because the current Open signal is considered to be an old Signal. Only when the Signal deactivates and reactivates an addition order will be opened.