OPEN-SOURCE SCRIPT

RSI + MACD Long-Only Strategy

632
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.

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。