![]()
1. Introduction
This EA executes the Relative Strength Index (RSI) technical indicator strategy. It enters new trades when a candle opens.
It is by default optimized to trade the pair XAUUSD on 30-minutes candles with conservative risk settings. Larger lotsize settings will generate higher profits but might involve larger risks.
For using this EA to trade any other pair, candle period, or server hours, the EA needs to be re-optimized by the user to adapt to the specific price action. For that purpose the user should use the MT5 strategy tester to identify new values for the input variables.
This strategy/EA might ideally be seen as part of an ecosystem of EAs trading an account instead of the single EA responsible for all trades. It executes a certain strategy (looking for a certain price action pattern, and trades when that pattern occurs), whereas other EAs execute other strategies and execute trades when other price action patterns occur (e.g., a Bollinger Bands Bounce or a Bollinger Bands Squeeze pattern). It is therefore suggested that traders consider to simultaneously run several EAs on a trading account, each of which with different and complementary trading strategies.
Back-testing conditions: XAUUSD 30-minutes candles
- Lot size at most 0.015 per USD1.000 equity
- 30-minutes candles
- Account currency EUR
- Leverage 1:200
- Initial balance EUR30.000
- 12 months period: 2021-02-01 to 2022-01-30
- Maximum spread 15 points
- Server ping 100 milliseconds
- Server trade hours: 07:00 to 15:00
Back-testing results: XAUUSD 30-minutes candles
- 362 positions, win rate 99,7 %
- Average position holding time: 41 minutes
- End Balance EUR3 7 . 250 , net profit 24,2 %
- Maximum balance drawdown 0,0 5 %
- Maximum equity drawdown 3 ,94 %
Current back-testing period is useful for training EAs as it reflects normal and current conditions. The EA has therefore not been back-tested/trained on the 2017–2020 period that saw market turmoil caused by a combination of Covid, trade wars, Brexit talks, election events, etc., which is a combination that is unlikely to be repeated. It must be stressed that past trading success does not guarantee future success.
2. Number of allowed positions
For any candle, the EA might open one buy positions or one sell position. It allows up to four positions, which may occur if a position from a candle is not closed before the next candle, and the EA opens a position during the subsequent candle. The number of allowed positions can be adjusted by the input variables “MaxBuyPositions”, “MaxSellPositions” and “MaxNumberPositions.”
input int MaxBuyPositions = 2;
//Max number allowed buy positions
input int MaxSellPositions = 2;
//Max number allowed sell positions
input int MaxNumberPositions = 4;
//Max total number allowed positions
3. Stop loss and take profit
Take profit levels are set by the input variables “TakeProfitPointsSell” and “TakeProfitPointsBuy” that the user can change to desired levels. Similarly, Stop loss levels are set by the input variables “StopLossLevelSell” and “StopLossLevelBuy” that can be adjusted manually. Stoploss and take profit levels can also be adjusted manually once a position has opened.
input double StopLossLevelSell = 103;
//Stoploss price in % of Bid price for sell positions
input int TakeProfitPointsSell = 150 ;
//Take profit in points for sell positions
input double StopLossLevelBuy = 97;
//Stoploss price in % of Ask price for buy positions
input int TakeProfitPointsBuy = 110 ;
//Take profit in points for buy positions
4. Settings for calculating the RSI
Commonly, a single calculation is used to calculate RSI for buy and sell positions . However, the dynamics for sell positions might not be identical to dynamics for buy positions. Therefore, this EA has two separate RSI calculations: one for buy positions and one for sell positions.
Lower RSI level : for buy positions
input int RSILowerBandCandles = 4;
//# candles to calculate RSI for buy positions
input ENUM_APPLIED_PRICE PriceRSILowerBand = PRICE_CLOSE;
//Price used for calculating RSI value for buy positions
input int RSIBuyLevel = 20;
//RSI value for buy positions indicating oversold pair
Upper RSI level : for sell positions
input int RSIUpperBandCandles = 6;
//# candles to calculate RSI for sell positions
input ENUM_APPLIED_PRICE PriceRSIUpperBand = PRICE_CLOSE;
//Price used for calculating RSI value for sell positions
input int RSISellLevel = 72;
//RSI value for sell positions indicating overbought pair
5. Trailing stop
Instead of using a certain number of points movement beyond the opening price before the trailing stop moves the stoploss to above (buy position) or below (sell position) the opening price, this EA checks whether the price has moved a certain % towards the take profit price from the opening price (Step I). If so, the EA then moves the stoploss and locks in a small profit.
Next (Step II), the EA checks whether the price has moved a specified number of points from the new stoploss towards the take profit price, and if so, it moves the stoploss 1 point closer to the take profit price for every tick.
Finally (Step III), if the position is not yet closed after a number of minutes set by an input variable (“PositionExitMinutes”), the position will exit if the price is at least a number of points (as specified by input variables “ExitPointsBuy” and “ExitPointsSell”) above (buy positions)/below (sell positions) the position opening price, or if that is not the case, the EA will enter a new minimum take profit price that is a number of points (as specified by input variables “ExitPointsBuy” and “ExitPointsSell”) above (buy positions)/below (sell positions) the position opening price.
Input variables for buy position trailing stop
input int TrailStopBuyFirstMove = 24 ;
//%move towards buy take profit price before trailstop initiated
input int TrailStopPointsBuy = 20 ;
//# of points of first trailstop above buy opening price
input int TrailDistanceBuy = 27 ;
//# of points above stoploss before stoploss adjustment
input int ExitPointsBuy = 30 ;
//# of points as exit strategy for buy positions
Input variables for sell position trailing stop
input int TrailStopSellFirstMove = 24 ;
//%move towards sell take profit price before trailing stop initiated
input int TrailStopPointsSell = 20 ;
//# of points of first trailing stop below sell opening price
input int TrailDistanceSell = 40 ;
//# of points below stoploss before stoploss adjustment
input int ExitPointsSell = 30 ;
//# of points as exit strategy for sell positions
6. General input variables
input bool BuyAllowed = true;
//New buy positions allowed
input bool SellAllowed = true;
//New sell positions allowed
input int MaxAllowedSpread = 15;
//Max allowed spread in points
input double MaxLotPer1000Equity = 0.015
//Allowed lotsize per 1000 equity units
Input int MagicNumber = 55555
//EA Magic Number
input int FirstTradeHour = 7;
//First chart hour positions allowed to open
input int LastTradeHour = 15;
//Last chart hour positions allowed to open
input int FirstTradingDayYear = 8;
//Day number of the year: 0 to 365
input int LastTradingDayYear = 355;
//Day number of the year: 0 to 365
input int PositionExitMinutes = 28;
//Number of minutes from position open to implement exit strategy
7. A final note on risk management: do not “orphan” EAs, stay proactive and informed
The back-testing results reflect a situation where the EA is completely “orphaned” as it trades without human intervention. However, no algorithm can predict and respond properly to every type of event. To reduce the risk for equity and balance drawdowns it is therefore advisable to use this or any EA as an “Advisor” that does most of the trading by itself, while the EA owner is constantly ready to intervene should circumstances so require. EA’s or any robots should not be “orphaned.“ You need to stay active, stay informed and use your judgement even if an EA is supporting your trading.
It is for instance a prudent risk management strategy to prematurely close positions manually if they are deemed sufficiently profitable – or prematurely close positions if they are incurring an acceptable loss – instead of waiting for positions to be closed by the EA. It is also prudent to temporarily deactivate the EA’s buy or sell module if it is believed that the GOLD-USD price is nearing a risky peak and is about to go down, or is nearing a risky low and is about to increase.
It is also prudent and advisable to pause the EA’s buy function, sell function, or both, on days when large market volatilities might be expected or are taking place. For instance, during the first Friday of the month the US (08.30 local time) releases monthly data on non-farm payrolls, which may cause significant changes of the GOLD-USD price. This means that EA traders are wise to stay informed about economic matters, which includes remaining seized on the calendar of financial reports that may influence the USD and the GOLD price. When important financial reports of the type just mentioned are due to take place, it may thus be prudent to temporarily pause the EA’s buy and sell functions. This calendar can be found in MT5.
As EAs are trading without human oversight during back-testing, the risk settings are strict to compensate for lack of human oversight. This means that during normal supervised EA trading, various settings (e.g., the number of candles used to calculate the RSI , lotsize, etc.) of this EA might be possible to relax to allow for more trades/larger lot sizes.
Finally, there is an old saying that deserves to be repeated as it applies also to trading: “the fastest way to succeed is to go slow.”

