How does your EA's algorithm work?
In this chapter we will discuss how the algorithm interacts with the other modular parts of your EA and how it will behave depending on its state.
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 flexible EA's. The modules are divided into three categories:
- Prevent Open
Read more about Modules. Depending on the algorithm's state it 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:
- No open orders
- One or more open orders
No open orders
When no orders are opened, all it does is wait for an Open Signal. When the signal becomes active, 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 so that it allows 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 Prevent Open module that it can not open any orders at the time, 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 becomes active 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. When SL/TP is hit, or a Close signal becomes active, 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 flow when no orders are opened is evaluated. If an order would 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 becomes active, after being inactive.
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.
A new quote is processed: The Algorithm will read that the order should be closed because the TP was hit. Before closing, it will evaluate if it should close the order, or if a new order would be opened directly after closing, but because the Time gap between orders (prevent open) module would block opening an order after closing the order, the Open Signal is discarded and the 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 yet. 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.