Indicator · Pine Script v5 · On the chart

Canca's Sweeps n Raids

by g-moe· code credited to goodgains

Canca's Sweeps n Raids is a price-chart indicator that marks bullish and bearish liquidity sweeps of prior swing highs and lows.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code207
Settings21inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

207 lines of Pine Script v5 from Tradingview/canca-s-sweeps-n-raids.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

canca-s-sweeps-n-raids.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains

// @version=5
indicator(title ="Canca`s Sweeps`n`Raids", overlay=true, max_lines_count = 500, max_labels_count = 500)

// @keywords: liquidity-sweep, liquidity-raid, stop-hunt, stop-run, bearish-sweep, bullish-sweep, swing-high-sweep, swing-low-sweep, wick-only-sweep, prior-swing-level, sweep-level-lines, liquidity-grab, mtf-sweeps, hourly-sweep-levels, daily-sweep-levels, weekly-sweep-levels, broken-sweep-cleanup, sweep-alerts, timeframe-sweep-labels, canca-sweeps-raids

max_bars_back(time, 4998)

sweepType = input.string(defval='Wick Only', title="Type", options=['Regular', 'Wick Only'], group='General')
enable_clear = input.bool(true, "Delete broken", group='General')
s_style = input.string(defval='Dotted', title="Style", options=['Solid', 'Dotted', 'Dashed'], group='Lines')
lineStyle = s_style == 'Dotted' ? line.style_dotted : s_style == 'Dashed' ? line.style_dashed : line.style_solid
lineWidth = input.int(2, "Width", group='Lines')
BullColor = input.color(defval=#2195f3, title='Bullish', group='Lines')
BearColor = input.color(defval=#ff0000, title='Bearish', group='Lines')
enable_label = input.bool(true, title= "Labels", group='Labels')
LabelColor = input.color(defval=color.gray, title='Color', group='Labels')
LabelSize = input.string(defval=size.small, title="Size", options=[size.huge, size.large, size.small, size.tiny, size.auto, size.normal], group='Labels')

type sweep
    float lvl = na // y1 and y2
    int start = na // time
    int stop = na // time
    int tf = na // TF in minutes

type plot
    line line = na
    label label = na
    bool isbull = na // true = bull and false = bear
    int tf = na

var plot[] lines  = array.new <plot>()

tf1 = input.bool(true, "1", group='Timeframe')
tf2 = input.bool(true, "3", group='Timeframe')
tf3 = input.bool(true, "5", group='Timeframe')
tf4 = input.bool(false, "15", group='Timeframe')
tf5 = input.bool(false, "30", group='Timeframe')
tf6 = input.bool(false, "45", group='Timeframe')
tf7 = input.bool(true, "60", group='Timeframe')
tf8 = input.bool(false, "120", group='Timeframe')
tf9 = input.bool(false, "180", group='Timeframe')
tf10 = input.bool(false, "240", group='Timeframe')
tf11 = input.bool(true, "D", group='Timeframe')
tf12 = input.bool(false, "W", group='Timeframe')

find_lines(string sweepType, int t) =>
    sweep bearishSweep = na
    sweep bullishSweep = na
    float thresholdSwingLow = na
    float thresholdSwingHigh = na
    for i = 1 to 4998 by 1
        if high[i] >= thresholdSwingHigh or na(thresholdSwingHigh)
            thresholdSwingHigh := high[i]
        if high[i] >= high or thresholdSwingHigh >= high
            break
        if high[i + 1] <= high[i] and high[i - 1] <= high[i] and high >= high[i] and open <= high[i] and high[i] >= thresholdSwingHigh
            if sweepType == 'Regular' or (sweepType == 'Wick Only' and close <= high[i])
                bearishSweep := sweep.new(high[i], time - t * 60000 * i, time + t * 60000, t)
    for j = 1 to 4998 by 1
        if low[j] <= thresholdSwingLow or na(thresholdSwingLow)
            thresholdSwingLow := low[j]
        if low[j] <= low or thresholdSwingLow <= low
            break
        if low[j + 1] >= low[j] and low[j - 1] >= low[j] and low <= low[j] and open >= low[j] and low[j] <= thresholdSwingLow
            if sweepType == 'Regular' or (sweepType == 'Wick Only' and close >= low[j])
                bullishSweep := sweep.new(low[j], time - t * 60000 * j, time + t * 60000, t)                 
    [bearishSweep, bullishSweep]

remove_lastline(plot[] lines)=>
    sz = array.size(lines)
    if sz >= 199
        temp = array.get(lines, 0)
        line.delete(temp.line)
        if enable_label
            label.delete(temp.label)
            array.remove(lines, 0)

get_txt(tf)=>
    string out = na
    out := switch tf
        1 => "1"
        3 => "3"
        5 => "5"
        15 => "15"
        30 => "30"
        45 => "45"
        60 => "60"
        120 => "120"
        180 => "180"
        240 => "240"
        1440 => "D"
        10080 => "W"
        => "XXX" 
    out

create_lines(sweep bearishSweep, sweep bullishSweep, int tf) =>
    currentTF = timeframe.multiplier
    if not na(bearishSweep) and tf >= currentTF
        remove_lastline(lines)
        label temp_label = na
        if enable_label
            temp_label := label.new(bearishSweep.stop+1, bearishSweep.lvl, get_txt(bearishSweep.tf), xloc.bar_time, yloc.price, na, label.style_none, LabelColor, LabelSize)
        temp_line = line.new(bearishSweep.start, bearishSweep.lvl, bearishSweep.stop+1, bearishSweep.lvl, xloc=xloc.bar_time, color=BearColor, style=lineStyle, width=lineWidth)
        array.push(lines, plot.new(temp_line, temp_label, false, bearishSweep.tf))
    if not na(bullishSweep) and tf >= currentTF
        remove_lastline(lines)
        label temp_label = na
        if enable_label
            temp_label := label.new(bullishSweep.stop+1, bullishSweep.lvl, get_txt(bullishSweep.tf), xloc.bar_time, yloc.price, na, label.style_none, LabelColor, LabelSize)
        temp_line = line.new(bullishSweep.start, bullishSweep.lvl, bullishSweep.stop+1, bullishSweep.lvl, xloc=xloc.bar_time, color=BullColor, style=lineStyle, width=lineWidth)
        array.push(lines, plot.new(temp_line, temp_label, true, bullishSweep.tf))

control_lines(plot[] lines)=>
    sz = array.size(lines)
    id = array.new_int()
    if sz > 0
        for i = sz - 1 to 0 by 1
            temp = array.get(lines, i)
            tf = temp.tf
            if timeframe.change(get_txt(tf))
                line = temp.line
                lineLvl = line.get_y1(line)
                isbull = temp.isbull
                if (isbull == true and high < lineLvl) or ( isbull == false and low > lineLvl)
                    if enable_label
                        label.delete(temp.label)
                        line.delete(line)
                        array.set(lines, i, na)
                        array.push(id, i)
        if array.size(id) > 0
            array.sort(id, order.ascending)
            for i = array.size(id) - 1 to 0 by 1
                array.remove(lines, array.get(id, i))

[bearishSweep1, bullishSweep1]    = request.security(syminfo.tickerid, "1",   find_lines(sweepType, 1),     barmerge.gaps_off,  barmerge.lookahead_on)
[bearishSweep2, bullishSweep2]    = request.security(syminfo.tickerid, "3",   find_lines(sweepType, 3),     barmerge.gaps_off,  barmerge.lookahead_on)
[bearishSweep3, bullishSweep3]    = request.security(syminfo.tickerid, "5",   find_lines(sweepType, 5),     barmerge.gaps_off,  barmerge.lookahead_on)
[bearishSweep4, bullishSweep4]    = request.security(syminfo.tickerid, "15",  find_lines(sweepType, 15),    barmerge.gaps_off,  barmerge.lookahead_on)
[bearishSweep5, bullishSweep5]    = request.security(syminfo.tickerid, "30",  find_lines(sweepType, 30),    barmerge.gaps_off,  barmerge.lookahead_on)
[bearishSweep6, bullishSweep6]    = request.security(syminfo.tickerid, "45",  find_lines(sweepType, 45),    barmerge.gaps_off,  barmerge.lookahead_on)
[bearishSweep7, bullishSweep7]    = request.security(syminfo.tickerid, "60",  find_lines(sweepType, 60),    barmerge.gaps_off,  barmerge.lookahead_on)
[bearishSweep8, bullishSweep8]    = request.security(syminfo.tickerid, "120", find_lines(sweepType, 120),   barmerge.gaps_off,  barmerge.lookahead_on)
[bearishSweep9, bullishSweep9]    = request.security(syminfo.tickerid, "180", find_lines(sweepType, 180),   barmerge.gaps_off,  barmerge.lookahead_on)
[bearishSweep10, bullishSweep10]  = request.security(syminfo.tickerid, "240", find_lines(sweepType, 240),   barmerge.gaps_off,  barmerge.lookahead_on)
[bearishSweep11, bullishSweep11]  = request.security(syminfo.tickerid, "D",   find_lines(sweepType, 1440),  barmerge.gaps_off,  barmerge.lookahead_on)
[bearishSweep12, bullishSweep12]  = request.security(syminfo.tickerid, "W",   find_lines(sweepType, 10080), barmerge.gaps_off,  barmerge.lookahead_on)

currentTF = timeframe.multiplier
if tf1 and currentTF <= 1
    create_lines(bearishSweep1, bullishSweep1, 1)
if tf2 and currentTF <= 3
    create_lines(bearishSweep2, bullishSweep2, 3)
if tf3 and currentTF <= 5
    create_lines(bearishSweep3, bullishSweep3, 5)
if tf4 and currentTF <= 15
    create_lines(bearishSweep4, bullishSweep4, 15)
if tf5 and currentTF <= 30
    create_lines(bearishSweep5, bullishSweep5, 30)
if tf6 and currentTF <= 45
    create_lines(bearishSweep6, bullishSweep6, 45)
if tf7 and currentTF <= 60
    create_lines(bearishSweep7, bullishSweep7, 60)
if tf8 and currentTF <= 120
    create_lines(bearishSweep8, bullishSweep8, 120)
if tf9 and currentTF <= 180
    create_lines(bearishSweep9, bullishSweep9, 180)
if tf10 and currentTF <= 240
    create_lines(bearishSweep10, bullishSweep10, 240)
if tf11 and currentTF <= 1440
    create_lines(bearishSweep11, bullishSweep11, 1440)
if tf12 and currentTF <= 10080
    create_lines(bearishSweep12, bullishSweep12, 10080)

if enable_clear
    control_lines(lines)

// Define alert conditions for each timeframe
SweepAlert1  = (na(bearishSweep1)  ? false : true) or (na(bullishSweep1)  ? false : true) 
SweepAlert2  = (na(bearishSweep2)  ? false : true) or (na(bullishSweep2)  ? false : true) 
SweepAlert3  = (na(bearishSweep3)  ? false : true) or (na(bullishSweep3)  ? false : true) 
SweepAlert4  = (na(bearishSweep4)  ? false : true) or (na(bullishSweep4)  ? false : true) 
SweepAlert5  = (na(bearishSweep5)  ? false : true) or (na(bullishSweep5)  ? false : true) 
SweepAlert6  = (na(bearishSweep6)  ? false : true) or (na(bullishSweep6)  ? false : true) 
SweepAlert7  = (na(bearishSweep7)  ? false : true) or (na(bullishSweep7)  ? false : true) 
SweepAlert8  = (na(bearishSweep8)  ? false : true) or (na(bullishSweep8)  ? false : true) 
SweepAlert9  = (na(bearishSweep9)  ? false : true) or (na(bullishSweep9)  ? false : true) 
SweepAlert10 = (na(bearishSweep10) ? false : true) or (na(bullishSweep10) ? false : true) 
SweepAlert11 = (na(bearishSweep11) ? false : true) or (na(bullishSweep11) ? false : true) 
SweepAlert12 = (na(bearishSweep12) ? false : true) or (na(bullishSweep12) ? false : true)
SweepAlert13 = (na(bearishSweep1)  ? false : true) or (na(bullishSweep1)  ? false : true) or (na(bearishSweep2) ? false : true) or (na(bullishSweep2) ? false : true) or (na(bearishSweep3) ? false : true) or (na(bullishSweep3) ? false : true) or (na(bearishSweep4) ? false : true) or (na(bullishSweep4) ? false : true) or (na(bearishSweep5) ? false : true) or (na(bullishSweep5) ? false : true) or (na(bearishSweep6) ? false : true) or (na(bullishSweep6) ? false : true) or (na(bearishSweep7) ? false : true) or (na(bullishSweep7) ? false : true) or (na(bearishSweep8) ? false : true) or (na(bullishSweep8) ? false : true) or (na(bearishSweep9) ? false : true) or (na(bullishSweep9) ? false : true) or (na(bearishSweep10) ? false : true) or (na(bullishSweep10) ? false : true) or (na(bearishSweep11) ? false : true) or (na(bullishSweep11) ? false : true) or (na(bearishSweep12) ? false : true) or (na(bullishSweep12) ? false : true)

alertcondition(SweepAlert13, title="All timeframes", message="Sweep has occurred!")
alertcondition(SweepAlert1,  title="1",              message="1 minute sweep has occurred!") 
alertcondition(SweepAlert2,  title="3",              message="3 minutes sweep has occurred!") 
alertcondition(SweepAlert3,  title="5",              message="5 minutes sweep has occurred!") 
alertcondition(SweepAlert4,  title="15",             message="15 minutes sweep has occurred!") 
alertcondition(SweepAlert5,  title="30",             message="30 minutes sweep has occurred!") 
alertcondition(SweepAlert6,  title="45",             message="45 minutes sweep has occurred!") 
alertcondition(SweepAlert7,  title="60",             message="Hourly sweep has occurred!") 
alertcondition(SweepAlert8,  title="2H",             message="2H sweep has occurred!") 
alertcondition(SweepAlert9,  title="3H",             message="3H sweep has occurred!") 
alertcondition(SweepAlert10, title="4H",             message="4H sweep has occurred!") 
alertcondition(SweepAlert11, title="D",              message="Daily sweep has occurred!") 
alertcondition(SweepAlert12, title="W",              message="Weekly sweep has occurred!")

Overview

Canca's Sweeps n Raids scans historical bars for swing levels that price has swept, using either a wick-only or regular close condition, then draws a line and an optional label for each selected timeframe from one minute through the weekly chart. Users can change line style, width, and colors, and can remove levels once they are broken. It does not generate trade entries or exits.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

SMC / ICT / price action, Support & resistance

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
TypestringWick OnlysweepType
Delete brokenbooltrueenable_clear
StylestringDotteds_style
Widthint2lineWidth
Bullishcolor#2195f3BullColor
Bearishcolor#ff0000BearColor
Labelsbooltrueenable_label
Colorcolorcolor.grayLabelColor
Sizestringsize.smallLabelSize
1booltruetf1
3booltruetf2
5booltruetf3
Show all 21 settings
SettingTypeDefaultVariable
15boolfalsetf4
30boolfalsetf5
45boolfalsetf6
60booltruetf7
120boolfalsetf8
180boolfalsetf9
240boolfalsetf10
Dbooltruetf11
Wboolfalsetf12
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

ICT Equal Highs and Lows

by ArunKBhaskar
575 stars

This overlay indicator finds pivot highs and lows on the price chart and compares the last two highs and the last two lows. When the percentage difference between a pair is below the Equal HL threshold, it treats them as equal levels and draws a box. Left and

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows

DE-tracker

by Allen1212
303 stars

This indicator plots labels on the TradingView price chart to mark ARK Invest's buy and sell trades for the DE stock. Buy transactions appear in green with X1 or X2 multipliers showing the number of ARK ETFs involved on the same day; sells appear in red. The m

Indicator v4 Support & resistanceSMC / ICT / price action
Updated 2 years ago · None stated GitHub repository of DE-tracker

This Pine Script indicator plots a ZigZag on the price chart. It identifies reversal points when price moves more than a set percentage from the last pivot. The script calculates forecasts using zigzag data and labels detected geometric patterns including harm

Indicator v4 TrendSupport & resistance

Golden Bullet Strategy

by TradersPost
218 stars

The Golden Bullet Strategy is an overlay signal indicator based on Smart Money Concepts and time-based liquidity models. It identifies liquidity sweeps of a designated reference session range during a specified hunt window. It then confirms Market Structure Sh

Indicator v6 SMC / ICT / price actionSessions & time
Updated 3 months ago · None stated GitHub repository of Golden Bullet Strategy

Open Source Fractal

by cantolab
183 stars

This indicator implements the Fractal Model concept to plot market structure shifts, liquidity sweeps, and Change in State of Delivery (CISD) levels. It overlays custom higher-timeframe candle previews, open prices, and time markers directly on the price chart

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 2 months ago · MIT GitHub repository of Open Source Fractal

Swing Failure Signals

by Ganador1
154 stars

This indicator calculates pivot highs and pivot lows to detect liquidity sweeps and Swing Failure Patterns. It identifies when price breaks past recent key swing highs or lows within a configurable historical window, then looks for a quick reversal or change i

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 2 months ago · Apache-2.0 GitHub repository of Swing Failure Signals

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers