RSI Divergence Strategy - AliferCrypto by AliferCrypto
By AliferCrypto
Performance Metrics
- Author: AliferCrypto
- Symbol: BINANCE:FILUSDT
- Timeframe: 4 hours
- Net P&L: +325.38 USDT (+32.05%)
- Win Rate: 44.6%
- Profit Factor: 1.998
- Max Drawdown: 55.89 USDT (4.80%)
- Total Trades: 56
- Sharpe Ratio: 0.221
Description
Apr 23Strategy OverviewThe RSI Divergence Strategy is designed to identify potential reversals by detecting regular bullish and bearish divergences between price action and the Relative Strength Index (RSI). It automatically enters positions when a divergence is confirmed and manages risk with configurable stop-loss and take-profit levels.Key FeaturesAutomatic Divergence Detection: Scans for RSI pivot lows/highs vs. price pivots using user-defined lookback windows and bar ranges.Dual SL/TP Methods:- Swing-based: Stops placed a configurable percentage beyond the most recent swing high/low.- ATR-based: Stops placed at a multiple of Average True Range, with a separate risk/reward multiplier.Long and Short Entries: Buys on bullish divergences; sells short on bearish divergences.Fully Customizable: Input groups for RSI, divergence, swing, ATR, and general SL/TP settings.Visual Plotting: Marks divergences on chart and plots stop-loss (red) and take-profit (green) lines for active trades.Alerts: Built-in alert conditions for both bullish and bearish RSI divergences.Detailed LogicRSI Calculation: Computes RSI of chosen source over a specified period.Pivot Detection:- Identifies RSI pivot lows/highs by scanning a lookback window to the left and right.- Uses ta.barssince to ensure pivots are separated by a minimum/maximum number of bars.Divergence Confirmation:- Bullish: Price makes a lower low while RSI makes a higher low.- Bearish: Price makes a higher high while RSI makes a lower high.Entry:- Opens a Long position when bullish divergence is true.- Opens a Short position when bearish divergence is true.Stop-Loss & Take-Profit:- Swing Method: Computes the recent swing high/low then adjusts by a percentage margin.- ATR Method: Uses the current ATR × multiplier applied to the entry price.- Take-Profit: Calculated as entry price ± (risk × R/R ratio).*Exit Orders: Uses strategy.exit to place bracket orders (stop + limit) for both long and short positions.Inputs and ConfigurationRSI Settings: Length & price source for the RSI.Divergence Settings: Pivot lookback parameters and valid bar ranges.SL/TP Settings: Choice between Swing or ATR method.Swing Settings: Swing lookback length, margin (%), and risk/reward ratio.ATR Settings: ATR length, stop multiplier, and risk/reward ratio.Usage NotesAdjust the Pivot Lookback and Range values to suit the volatility and timeframe of your market.Use higher ATR multipliers for wider stops in choppy conditions, or tighten swing margins in trending markets.Backtest different R/R ratios to find the balance between win rate and reward.DisclaimerThis script is for educational purposes only and does not constitute financial advice. Trading carries significant risk and you may lose more than your initial investment. Always conduct your own research and consider consulting a professional before making any trading decisions.Apr 24Release NotesUpdate - Change LogRSI-Zone FilterAdded Enable RSI Zone Filter toggleNew inputs: RSI Oversold Level (arms bullish only after RSI level)Internal flags (rsiOversoldFlag / rsiOverboughtFlag) track first breach and reset on entryTrend FilterAdded Enable Trend Filter toggleFull MA configuration under “Filter Settings”: MA Timeframe (blank = chart) MA Type (SMA, EMA, SMMA, WMA, VWMA) MA Length, MA Source, MA ColorOnly allows longs when price > MA, shorts when price < MAMA PlottingPlots the configured MA line when the trend filter is enabledEntry Logic UpdatesIncorporated both RSI-zone and trend checks into the final bullCond / bearCond conditionsReset of oversold/overbought flags immediately upon taking a tradeNo other parameters were changed—everything else (divergence detection, SL/TP methods) remains as originally implemented.Apr 24Release NotesUpdate – Change LogExit Levels ModeAdded Exit Levels Mode toggle under SL/TP Settings with two options: - Dynamic: Recalculates stop-loss and take-profit each bar based on current swing/ATR levels - Static: Locks SL/TP once at the entry bar and holds those fixed levels for the life of the tradeIntroduced entrySL and entryTP variables to capture and store the static exit prices at the moment of entryExit logic now chooses between live (slCalc/tpCalc) or locked (entrySL/entryTP) values based on the selected modeStatic storage is automatically reset when the position closesNo other behaviors (divergence detection, filters, SL/TP calculations) have been changed.