Finding Liquidity
Liquidity Sweeps, Trend Reversals, MACD, and RSI Combination
Liquidity Sweeps, Trend Reversals, MACD, and RSI Combination
Code:
# Liquidity Sweeps, Trend Reversals, MACD, and RSI Combination
# Inputs
input lookback = 5; # Swing high/low lookback period
input macdFastLength = 12;
input macdSlowLength = 26;
input macdSignalLength = 9;
input rsiLength = 14;
input rsiOverbought = 70;
input rsiOversold = 30;
input showVolumeFilter = yes;
input volumeMultiplier = 1.5; # Multiplier for above-average volume confirmation
# Swing High and Low Detection
def isSwingHigh = high > Highest(high[1], lookback) and high > Highest(high[-lookback], lookback);
def isSwingLow = low < Lowest(low[1], lookback) and low < Lowest(low[-lookback], lookback);
# Liquidity Sweep Detection
def liquidityGrabHigh = isSwingHigh[1] and close < high[1];
def liquidityGrabLow = isSwingLow[1] and close > low[1];
# Trend Reversal Detection
def breakHigherLow = low < Lowest(low[1], lookback) and close > high[1];
def breakLowerHigh = high > Highest(high[1], lookback) and close < low[1];
# MACD Calculation
def macdValue = ExpAverage(close, macdFastLength) - ExpAverage(close, macdSlowLength);
def macdSignal = ExpAverage(macdValue, macdSignalLength);
def macdBullish = macdValue > macdSignal; # MACD Line above Signal Line
def macdBearish = macdValue < macdSignal; # MACD Line below Signal Line
# RSI Calculation
def rsi = RSI(rsiLength);
def rsiBullish = rsi > 50;
def rsiBearish = rsi < 50;
# Volume Confirmation
def avgVolume = Average(volume, lookback);
def volumeHigh = volume > avgVolume * volumeMultiplier;
# Combined Signal Conditions
def bullishSignal = (liquidityGrabLow or breakHigherLow) and macdBullish and rsiBullish and (if showVolumeFilter then volumeHigh else yes);
def bearishSignal = (liquidityGrabHigh or breakLowerHigh) and macdBearish and rsiBearish and (if showVolumeFilter then volumeHigh else yes);
# Plot Liquidity Sweeps and Reversals
AddChartBubble(bullishSignal, low, "Buy", Color.GREEN, no);
AddChartBubble(bearishSignal, high, "Sell", Color.RED, yes);
# Highlight Bars
AssignPriceColor(if bullishSignal then Color.GREEN else if bearishSignal then Color.RED else Color.CURRENT);
# Alerts
Alert(bullishSignal, "Bullish Signal: Liquidity Sweep or Reversal Confirmed", Alert.BAR, Sound.Ding);
Alert(bearishSignal, "Bearish Signal: Liquidity Sweep or Reversal Confirmed", Alert.BAR, Sound.Ding);
Last edited by a moderator: