OPEN-SOURCE SCRIPT
Strategy XAU/M5 RSI+EMA

XAU M5 Strategy — EMA + RSI with Flexible TP/SL
Recommended timeframe: M5
Best suited for: XAUUSD (Gold) — can also be tested on other pairs after optimization.
Concept
This strategy combines trend direction via EMA and momentum confirmation via RSI (oversold/overbought levels).
Buy (Long): when price is above EMA and RSI crosses above the oversold level.
Sell (Short): when price is below EMA and RSI crosses below the overbought level.
This method follows the trend but waits for RSI confirmation, avoiding premature entries during unconfirmed market moves.
Entry Conditions
Buy: close > EMA and RSI crossover RSI_oversold
Sell: close < EMA and RSI crossunder RSI_overbought
Default settings:
EMA Length = 500 (smooth trend filter for M5)
RSI Length = 8, Overbought = 70, Oversold = 30 (sensitive enough to catch early impulses)
Trade Management (TP/SL)
This strategy supports two TP/SL modes:
Fixed Value
Adds or subtracts a fixed price value directly from the entry price.
Example: TP = +14, SL = -7 (measured in price points, not USD).
Pip Mode
Uses pip size conversion: pip = syminfo.mintick * 10.
TP/SL = (entered pip value × pip size) added/subtracted from entry.
Note: although the inputs are labeled “USD/Pip,” the calculations are based on price points and pip-size scaling.
If you use a symbol other than XAUUSD, double-check pip size to ensure TP/SL aligns correctly.
Suggested Parameters (for XAUUSD M5)
EMA Length: 500
RSI Length: 8
RSI Overbought: 70
RSI Oversold: 30
TP/SL Mode: “Fixed Value” (easier for beginners)
TP (Value): 14
SL (Value): 7
Default risk–reward ratio ≈ 1:2 (TP twice the SL), ideal for fast-paced M5 scalping.
Usage & Optimization Tips
Use on M5 timeframe as designed. Adjust EMA/RSI if changing timeframes.
Select one TP/SL mode only (“Value” or “Pip”) and confirm actual units.
Avoid high-volatility news events (NFP, CPI, FOMC) to reduce slippage.
Focus on active sessions:
Gold is most volatile during London and New York sessions.
Risk management:
Risk ≤1–2% per trade.
Avoid countertrend stacking when RSI remains extreme in strong trends.
Trend confirmation:
EMA 500 filters noise well;
Backtesting Tips
Set initial capital realistically.
Include commissions/spread to mirror broker conditions.
Keep pyramiding low (0–1) to assess signal quality.
Start with On bar close mode, then test Every tick for detailed sensitivity.
Strengths
Simple and transparent: clear, rule-based signals.
Trend + momentum confirmation: avoids catching falling knives.
Flexible TP/SL system: switch easily between fixed or pip-based setups.
Limitations
RSI can trigger early during extended strong trends (persistent overbought/oversold).
TP/SL tuning is essential for each market and volatility regime.
Disclaimer
This is not financial advice.
Past performance does not guarantee future results.
Always backtest and paper trade before using real capital, and practice strict risk management.
Recommended timeframe: M5
Best suited for: XAUUSD (Gold) — can also be tested on other pairs after optimization.
Concept
This strategy combines trend direction via EMA and momentum confirmation via RSI (oversold/overbought levels).
Buy (Long): when price is above EMA and RSI crosses above the oversold level.
Sell (Short): when price is below EMA and RSI crosses below the overbought level.
This method follows the trend but waits for RSI confirmation, avoiding premature entries during unconfirmed market moves.
Entry Conditions
Buy: close > EMA and RSI crossover RSI_oversold
Sell: close < EMA and RSI crossunder RSI_overbought
Default settings:
EMA Length = 500 (smooth trend filter for M5)
RSI Length = 8, Overbought = 70, Oversold = 30 (sensitive enough to catch early impulses)
Trade Management (TP/SL)
This strategy supports two TP/SL modes:
Fixed Value
Adds or subtracts a fixed price value directly from the entry price.
Example: TP = +14, SL = -7 (measured in price points, not USD).
Pip Mode
Uses pip size conversion: pip = syminfo.mintick * 10.
TP/SL = (entered pip value × pip size) added/subtracted from entry.
Note: although the inputs are labeled “USD/Pip,” the calculations are based on price points and pip-size scaling.
If you use a symbol other than XAUUSD, double-check pip size to ensure TP/SL aligns correctly.
Suggested Parameters (for XAUUSD M5)
EMA Length: 500
RSI Length: 8
RSI Overbought: 70
RSI Oversold: 30
TP/SL Mode: “Fixed Value” (easier for beginners)
TP (Value): 14
SL (Value): 7
Default risk–reward ratio ≈ 1:2 (TP twice the SL), ideal for fast-paced M5 scalping.
Usage & Optimization Tips
Use on M5 timeframe as designed. Adjust EMA/RSI if changing timeframes.
Select one TP/SL mode only (“Value” or “Pip”) and confirm actual units.
Avoid high-volatility news events (NFP, CPI, FOMC) to reduce slippage.
Focus on active sessions:
Gold is most volatile during London and New York sessions.
Risk management:
Risk ≤1–2% per trade.
Avoid countertrend stacking when RSI remains extreme in strong trends.
Trend confirmation:
EMA 500 filters noise well;
Backtesting Tips
Set initial capital realistically.
Include commissions/spread to mirror broker conditions.
Keep pyramiding low (0–1) to assess signal quality.
Start with On bar close mode, then test Every tick for detailed sensitivity.
Strengths
Simple and transparent: clear, rule-based signals.
Trend + momentum confirmation: avoids catching falling knives.
Flexible TP/SL system: switch easily between fixed or pip-based setups.
Limitations
RSI can trigger early during extended strong trends (persistent overbought/oversold).
TP/SL tuning is essential for each market and volatility regime.
Disclaimer
This is not financial advice.
Past performance does not guarantee future results.
Always backtest and paper trade before using real capital, and practice strict risk management.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
phamchitam2004
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
phamchitam2004
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.