Creator of the Idea: Scriptor, MQL5 Code Author: barabashkakvn.
The Trend Me Leave Me Expert Advisor is designed to manage a single position, making it suitable for netting accounts. The EA determines the direction of the next trade based on the last closed position—whether it was a BUY or SELL—and how that position was closed, either by hitting Stop Loss or taking Profit.
How It Works:
- If the last trade was closed with Take Profit, the next trade will be in the same direction;
- If it was closed with Stop Loss, the next trade will be in the opposite direction.
The type of closing is determined in OnTradeTransaction() using the ENUM_DEAL_REASON. Initially, you check the transaction type in OnTradeTransaction():
Next, the DEAL_REASON property is evaluated.
If the Breakeven parameter is set to a non-zero value, the EA will attempt to move the position to breakeven if conditions allow.
After establishing the trade direction in OnTradeTransaction(), the EA checks the following conditions:
- For a BUY position, the SAR indicator on the current bar must be less than the Close of that bar, and the ADX on the current bar must be below 20.
- For a SELL position, the SAR indicator on the current bar must be greater than the Close of that bar, with the ADX also below 20;
Input Parameters
- Stop Loss (in pips): Set your Stop Loss value;
- Take Profit (in pips): Set your Take Profit value;
- Risk per Trade (%): Define your risk percentage for each trade;
- Breakeven (in pips): Set your breakeven value;
- ADX: Averaging Period: Specify the ADX indicator parameter;
- SAR: Price Increment Step - Acceleration Factor: Set the SAR indicator parameter;
- SAR: Maximum Value of Step: Set the maximum step for the SAR indicator.
Default parameters are set for EURUSD, M30 from 2017-01-08 to 2018-02-05.

Comments 0