OPEN-SOURCE SCRIPT
RSI + MACD Long-Only Strategy

RSI + MACD Long-Only Strategy
Overview: Momentum-based, long-only strategy combining RSI and MACD. Entries favor upside momentum; exits trigger on momentum fades or risk targets. Signals are state-gated so you get one exit per entry (no multiple exits without a prior entry).
Entry conditions:
RSI crosses above the midline (default 50) while MACD is bullish (MACD > Signal, optionally MACD > 0), OR
MACD crosses above its Signal while RSI is at/above the midline.
Optional filters:
EMA trend filter: only enter if price > EMA(n).
Oversold context: only enter within N bars after RSI dipped below the oversold threshold.
Exit conditions:
RSI crosses below the midline, OR
MACD crosses below its Signal with MACD histogram ≤ 0.
Optional risk exit: Take Profit / Stop Loss based on percentage from average entry price.
Risk management:
Inputs: Use TP/SL (on/off), TP% (default 3.0), SL% (default 1.5).
Implements protective strategy.exit (limit/stop) while in position.
Signal-based exit uses strategy.close to flatten.
Position management:
Long-only, no pyramiding (single position at a time).
Internal state ensures entries occur only when flat and exits only when in a position.
Inputs you can tune:
RSI: length, overbought, oversold, midline.
MACD: fast length, slow length, signal length; toggle “Require MACD > 0”.
Signals: oversold lookback window; EMA trend on/off and EMA length.
Risk: TP% and SL%.
Visuals: show entry/exit markers, bar coloring; optional debug background on raw triggers.
Visuals and alerts:
Plots EMA (optional), draws entry/exit markers, optional bar coloring, and a faint background on raw long triggers to aid tuning.
Alert conditions provided for entries and exits.
Notes:
Designed for bar-close evaluation; performance varies by symbol/timeframe—tune inputs accordingly.
Long-only; intended for trend-following momentum with basic risk control.
Not financial advice.
Overview: Momentum-based, long-only strategy combining RSI and MACD. Entries favor upside momentum; exits trigger on momentum fades or risk targets. Signals are state-gated so you get one exit per entry (no multiple exits without a prior entry).
Entry conditions:
RSI crosses above the midline (default 50) while MACD is bullish (MACD > Signal, optionally MACD > 0), OR
MACD crosses above its Signal while RSI is at/above the midline.
Optional filters:
EMA trend filter: only enter if price > EMA(n).
Oversold context: only enter within N bars after RSI dipped below the oversold threshold.
Exit conditions:
RSI crosses below the midline, OR
MACD crosses below its Signal with MACD histogram ≤ 0.
Optional risk exit: Take Profit / Stop Loss based on percentage from average entry price.
Risk management:
Inputs: Use TP/SL (on/off), TP% (default 3.0), SL% (default 1.5).
Implements protective strategy.exit (limit/stop) while in position.
Signal-based exit uses strategy.close to flatten.
Position management:
Long-only, no pyramiding (single position at a time).
Internal state ensures entries occur only when flat and exits only when in a position.
Inputs you can tune:
RSI: length, overbought, oversold, midline.
MACD: fast length, slow length, signal length; toggle “Require MACD > 0”.
Signals: oversold lookback window; EMA trend on/off and EMA length.
Risk: TP% and SL%.
Visuals: show entry/exit markers, bar coloring; optional debug background on raw triggers.
Visuals and alerts:
Plots EMA (optional), draws entry/exit markers, optional bar coloring, and a faint background on raw long triggers to aid tuning.
Alert conditions provided for entries and exits.
Notes:
Designed for bar-close evaluation; performance varies by symbol/timeframe—tune inputs accordingly.
Long-only; intended for trend-following momentum with basic risk control.
Not financial advice.
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.
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.
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.