Summer Sale: 40% Off All Annual PlansUpgrade Now
← All Analyses
NSENIFTY
Neutral

prince

Prince Nimbran
6d ago
prince
  • //@version=6
  • strategy("SMC - Liquidity Sweep + MSS + FVG",
  •      overlay=true,
  •      initial_capital=100000,
  •      default_qty_type=strategy.percent_of_equity,
  •      default_qty_value=1,
  •      pyramiding=0,
  •      commission_type=strategy.commission.percent,
  •      commission_value=0.05,
  •      process_orders_on_close=true)
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • // INPUTS
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • swingLen = input.int(5, "Swing Length", minval=2)
  • rr = input.float(2.0, "Risk : Reward", minval=0.5, step=0.5)
  • maxBarsFVG = input.int(10, "Max Bars To Wait For FVG Retest", minval=1)
  • slBufferPct = input.float(0.05, "SL Buffer %", minval=0.0, step=0.01)
  • useLong = input.bool(true, "Enable Longs")
  • useShort = input.bool(true, "Enable Shorts")
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • // SWING LIQUIDITY
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • pivotHigh = ta.pivothigh(high, swingLen, swingLen)
  • pivotLow = ta.pivotlow(low, swingLen, swingLen)
  • var float lastSwingHigh = na
  • var float lastSwingLow = na
  • if not na(pivotHigh)
  •     lastSwingHigh := pivotHigh
  • if not na(pivotLow)
  •     lastSwingLow := pivotLow
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • // LIQUIDITY SWEEP
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • // Sell-side liquidity sweep:
  • // Price trades below previous swing low,
  • // but closes back above it.
  • sellSideSweep =
  •      not na(lastSwingLow) and
  •      low < lastSwingLow and
  •      close > lastSwingLow
  • // Buy-side liquidity sweep:
  • // Price trades above previous swing high,
  • // but closes back below it.
  • buySideSweep =
  •      not na(lastSwingHigh) and
  •      high > lastSwingHigh and
  •      close < lastSwingHigh
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • // MSS LOGIC
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • // After bullish sweep, price must break recent high.
  • // After bearish sweep, price must break recent low.
  • var float sweepLow = na
  • var float sweepHigh = na
  • var int bullishSweepBar = na
  • var int bearishSweepBar = na
  • if sellSideSweep
  •     sweepLow := low
  •     bullishSweepBar := bar_index
  • if buySideSweep
  •     sweepHigh := high
  •     bearishSweepBar := bar_index
  • // Recent structure levels
  • recentHigh = ta.highest(high[1], swingLen)
  • recentLow = ta.lowest(low[1], swingLen)
  • // MSS
  • bullishMSS =
  •      not na(bullishSweepBar) and
  •      bar_index > bullishSweepBar and
  •      close > recentHigh
  • bearishMSS =
  •      not na(bearishSweepBar) and
  •      bar_index > bearishSweepBar and
  •      close < recentLow
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • // FVG DETECTION
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • // Bullish FVG:
  • // Current candle low > high from 2 candles ago
  • bullishFVG =
  •      low > high[2]
  • // Bearish FVG:
  • // Current candle high < low from 2 candles ago
  • bearishFVG =
  •      high < low[2]
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • // STORE FVG
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • var float bullFVGTop = na
  • var float bullFVGBottom = na
  • var float bearFVGTop = na
  • var float bearFVGBottom = na
  • var int bullFVGBar = na
  • var int bearFVGBar = na
  • if bullishFVG
  •     bullFVGTop := low
  •     bullFVGBottom := high[2]
  •     bullFVGBar := bar_index
  • if bearishFVG
  •     bearFVGTop := low[2]
  •     bearFVGBottom := high
  •     bearFVGBar := bar_index
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • // VALID FVG RETEST
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • bullFVGValid =
  •      not na(bullFVGBar) and
  •      bar_index - bullFVGBar <= maxBarsFVG
  • bearFVGValid =
  •      not na(bearFVGBar) and
  •      bar_index - bearFVGBar <= maxBarsFVG
  • // FVG midpoint
  • bullFVGmid =
  •      (bullFVGTop + bullFVGBottom) / 2
  • bearFVGmid =
  •      (bearFVGTop + bearFVGBottom) / 2
  • // Price retraces into FVG
  • bullRetest =
  •      bullFVGValid and
  •      low <= bullFVGTop and
  •      high >= bullFVGBottom
  • bearRetest =
  •      bearFVGValid and
  •      high >= bearFVGBottom and
  •      low <= bearFVGTop
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • // ENTRY CONDITIONS
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • // Long sequence:
  • //
  • // Sell-side liquidity sweep
  • // ↓
  • // Bullish MSS
  • // ↓
  • // Bullish FVG
  • // ↓
  • // FVG retracement
  • // ↓
  • // BUY
  • longSetup =
  •      useLong and
  •      bullishMSS and
  •      bullFVGValid and
  •      bullRetest
  • // Short sequence:
  • //
  • // Buy-side liquidity sweep
  • // ↓
  • // Bearish MSS
  • // ↓
  • // Bearish FVG
  • // ↓
  • // FVG retracement
  • // ↓
  • // SELL
  • shortSetup =
  •      useShort and
  •      bearishMSS and
  •      bearFVGValid and
  •      bearRetest
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • // TRADE VARIABLES
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • var float longSL = na
  • var float longTP = na
  • var float shortSL = na
  • var float shortTP = na
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • // LONG ENTRY
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • if longSetup and strategy.position_size == 0
  •     entryPrice = bullFVGmid
  •     sl = sweepLow * (1 - slBufferPct / 100)
  •     risk = entryPrice - sl
  •     if risk > syminfo.mintick
  •         tp = entryPrice + risk * rr
  •         longSL := sl
  •         longTP := tp
  •         strategy.entry(
  •              "LONG",
  •              strategy.long,
  •              limit=entryPrice)
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • // SHORT ENTRY
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • if shortSetup and strategy.position_size == 0
  •     entryPrice = bearFVGmid
  •     sl = sweepHigh * (1 + slBufferPct / 100)
  •     risk = sl - entryPrice
  •     if risk > syminfo.mintick
  •         tp = entryPrice - risk * rr
  •         shortSL := sl
  •         shortTP := tp
  •         strategy.entry(
  •              "SHORT",
  •              strategy.short,
  •              limit=entryPrice)
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • // EXIT
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • if strategy.position_size > 0
  •     strategy.exit(
  •          "LONG EXIT",
  •          "LONG",
  •          stop=longSL,
  •          limit=longTP)
  • if strategy.position_size < 0
  •     strategy.exit(
  •          "SHORT EXIT",
  •          "SHORT",
  •          stop=shortSL,
  •          limit=shortTP)
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • // VISUAL MARKERS
  • //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  • plot(lastSwingHigh,
  •      "Buy-side Liquidity",
  •      color=color.red,
  •      style=plot.style_linebr)
  • plot(lastSwingLow,
  •      "Sell-side Liquidity",
  •      color=color.green,
  •      style=plot.style_linebr)
  • plotshape(
  •      sellSideSweep,
  •      title="Sell-side Sweep",
  •      style=shape.triangleup,
  •      location=location.belowbar,
  •      color=color.green,
  •      size=size.tiny,
  •      text="SSL")
  • plotshape(
  •      buySideSweep,
  •      title="Buy-side Sweep",
  •      style=shape.triangledown,
  •      location=location.abovebar,
  •      color=color.red,
  •      size=size.tiny,
  •      text="BSL")
  • plotshape(
  •      bullishMSS,
  •      title="Bullish MSS",
  •      style=shape.labelup,
  •      location=location.belowbar,
  •      color=color.green,
  •      text="MSS↑")
  • plotshape(
  •      bearishMSS,
  •      title="Bearish MSS",
  •      style=shape.labeldown,
  •      location=location.abovebar,
  •      color=color.red,
  •      text="MSS↓")
  • plotshape(
  •      longSetup,
  •      title="Long Setup",
  •      style=shape.labelup,
  •      location=location.belowbar,
  •      color=color.green,
  •      text="BUY")
  • plotshape(
  •      shortSetup,
  •      title="Short Setup",
  •      style=shape.labeldown,
  •      location=location.abovebar,
  •      color=color.red,
  •      text="SELL")
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 GoCharting. Read more in the Terms of Use.

Comments (0)

Loading comments…