The author of the idea: Scriptor, the author of the MQL5 code: barabashkakvn.
The Expert Advisor works with one position (can be used on netting accounts). The direction of a new open signal is calculated depending on the direction of the last closed position (BUY or SELL) and the way that position was closed (by Stop Loss or Take Profit).
General principle:
Type of closing is determined in OnTradeTransaction() using ENUM_DEAL_REASON: the transaction and its type is accessed in OnTradeTransaction() first:
, and then the DEAL_REASON property is checked.
If the Breakeven parameter is not equal to zero, the position will be moved to breakeven if possible.
After determining the direction in OnTradeTransaction(), check for further conditions:
Default parameters, EURUSD,M30 from 2017.01.08 to 2018.02.05

Tradotto dal russo da MetaQuotes Ltd.
Codice originale https://www.mql5.com/ru/code/19951
AO_Divergence
The indicator searches for divergences and displays them on the chart of the custom AO indicator.
EMA Cross Contest Hedged
A trading system based on three indicators: two iMAs (Moving Average) and iMACD (Moving Average Convergence/Divergence, MACD).