Indicator · Pine Script v4 · On the chart

Chad's Swing Points (@tradeprophet)

by TPCharts

This indicator identifies and plots minor and major swing highs and lows directly on the price chart.

View on GitHub

Repaints

GitHub stars10on the repository
Pine versionv4older, still runs
Lines of code134
Settings12inputs
LicenceGPL-3.0
Last update5 years ago1 Dec 2020

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

134 lines of Pine Script v4 from Chad's Swing Points (expanded) copy.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Chad's Swing Points (expanded) copy.pine
//@version=4
// Shows traditional fractal lows/highs (two lower/higher lows/highs on each side), as well as three bar lows/highs (one lower/higher low/high on each side)
// Basically an expansion on the default William's Fractal script to fit PA daytrading strategies.
// Probably rife with repainting issues, at least for alerts. Use at your own risk.
study("Chad's Swing Points (@tradeprophet)", overlay=true)

// START DEBUG
ds(str) => label.new(bar_index, high, str)
dsl(str) =>
    if barstate.islast
        ds(str)
d(val) => ds(tostring(val))
dl(val) => dsl(tostring(val))
// END DEBUG

var plotOffset = 3
var negativePlotOffset = plotOffset * -1


// Minor highs (3 bar pattern)
var isMinorHighShown = input(true, "Show Minor Highs?")
var isAllMinorHighPriceLabelShown = input(false, "Show All Minor High Price Labels?")
var isOnlyLastMinorHighPriceLabelShown = input(true, "Show Only Last Minor High Price Label?")
var lastMinorHighIndex = int(na)
var lastMinorHighPrice = float(na)

// Minor lows (3 bar pattern)
var isMinorLowShown = input(true, "Show Minor Lows?")
var isAllMinorLowPriceLabelShown = input(false, "Show All Minor Low Price Labels?")
var isOnlyLastMinorLowPriceLabelShown = input(true, "Show Only Last Minor Low Price Label?")
var lastMinorLowIndex = int(na)
var lastMinorLowPrice = float(na)

// Major Highs (5 par patterns)
var isMajorHighShown = input(true, "Show Major Highs?")
var isAllMajorHighPriceLabelShown = input(false, "Show All Major High Price Labels?")
var isOnlyLastMajorHighPriceLabelShown = input(true, "Show Only Last Major High Price Label?")
var lastMajorHighIndex = int(na)
var lastMajorHighPrice = float(na)

// Major Lows (5 bar patterns)
var isMajorLowShown = input(true, "Show Major Lows?")
var isAllMajorLowPriceLabelShown = input(false, "Show All Major Low Price Labels?")
var isOnlyLastMajorLowPriceLabelShown = input(true, "Show Only Last Major Low Price Label?")
var lastMajorLowIndex = int(na)
var lastMajorLowPrice = float(na)



// Minor highs (3 bar pattern)
isMinorHigh = (high[3] < high[2]) and (high[1] < high[2])

if isMinorHigh
    lastMinorHighIndex := bar_index-plotOffset
    lastMinorHighPrice := high[plotOffset]

// Minor lows (3 bar pattern)
isMinorLow = (low[3] > low[2]) and (low[1] > low[2])

if isMinorLow
    lastMinorLowIndex:= bar_index-plotOffset
    lastMinorLowPrice := low[plotOffset]

// Major Highs (5 par patterns)
isMajorHigh = isMinorHigh and (((high[5] < high[3]) and (high[1] < high[3]))
     or ((high[6] < high[3]) and (high[5] < high[3]) and (high[5] == high[3]) and (high[4] <= high[3]) and (high[2] < high[3]) and (high[1] < high[3]))
     or ((high[7] < high[3]) and (high[6] < high[3]) and (high[5] == high[3]) and (high[5] == high[3]) and (high[4] <= high[3]) and (high[2] < high[3]) and (high[1] < high[3]))
     or ((high[8] < high[3]) and (high[7] < high[3]) and (high[6] == high[3]) and (high[5] <= high[3]) and (high[5] == high[3]) and (high[4] <= high[3]) and (high[2] < high[3]) and (high[1] < high[3])))

if isMajorHigh
    lastMajorHighIndex:= bar_index+-plotOffset
    lastMajorHighPrice := high[plotOffset]

// Major Lows (5 par patterns)
isMajorLow = isMinorLow and (((low[5] > low[3]) and (low[1] > low[3]))
     or ((low[5] > low[3]) and (low[5] > low[3]) and (low[4] == low[3]) and (low[2] > low[3]) and (low[1] > low[3]))
     or ((low[6] > low[3]) and (low[5] > low[3]) and (low[5] == low[3]) and (low[4] >= low[3]) and (low[2] > low[3]) and (low[1] > low[3]))
     or ((low[7] > low[3]) and (low[6] > low[3]) and (low[5] == low[3]) and (low[5] == low[3]) and (low[4] >= low[3]) and (low[2] > low[3]) and (low[1] > low[3]))
     or ((low[8] > low[3]) and (low[7] > low[3]) and (low[6] == low[3]) and (low[5] >= low[3]) and (low[5] == low[3]) and (low[4] >= low[3]) and (low[2] > low[3]) and (low[1] > low[3])))

if isMajorLow 
    lastMajorLowIndex := bar_index-plotOffset
    lastMajorLowPrice := low[plotOffset]

//
// Plot them & create the alerts
//
createCurrentBarLabel(barindex, value, under) =>
    label.new(barindex, value*(under ? 0.999 : 1.001), text=tostring(value), color=color.gray, style=under ? label.style_label_up : label.style_label_down)

createHighLabelAt(barindex, val) => createCurrentBarLabel(barindex, val, false)
createLowLabelAt(barindex, val) => createCurrentBarLabel(barindex, val, true)
createHighLabel() => createHighLabelAt(bar_index-plotOffset, high[plotOffset])
createLowLabel() => createLowLabelAt(bar_index-plotOffset, low[plotOffset])

// Minor highs
plotshape(isMinorHighShown and isMinorHigh and not isMajorHigh, style=shape.xcross, location=location.abovebar, offset=negativePlotOffset+1, color=color.black, transp=60, size = size.tiny)
alertcondition(high > lastMinorHighPrice, title="Chad's Minor High Breaks", message="Last minor high broke")

if(isAllMinorHighPriceLabelShown and not isOnlyLastMinorHighPriceLabelShown)
    createHighLabel()

if(isOnlyLastMinorHighPriceLabelShown and barstate.islast)
    createHighLabelAt(lastMinorHighIndex, lastMinorHighPrice)

// Minor lows
plotshape(isMinorLowShown and isMinorLow and not isMajorLow, style=shape.xcross, location=location.belowbar, offset=negativePlotOffset+1, color=color.black, transp=60, size = size.tiny)
alertcondition(low > lastMinorLowPrice, title="Chad's Minor Low Breaks", message="Last minor low broke")

if(isAllMinorLowPriceLabelShown and not isOnlyLastMinorHighPriceLabelShown)
    createLowLabel()

if(isOnlyLastMinorLowPriceLabelShown and barstate.islast)
    createLowLabelAt(lastMinorLowIndex, lastMinorLowPrice)

// Major highs
plotshape(isMajorHighShown and isMajorHigh, style=shape.circle, location=location.abovebar, offset=negativePlotOffset, color=color.black, transp=80, size = size.tiny)
alertcondition(high > lastMajorHighPrice, title="Chad's Major High Breaks", message="Last major high broke")

if(isAllMajorHighPriceLabelShown and not isOnlyLastMajorHighPriceLabelShown)
    createHighLabel()

if(isOnlyLastMajorHighPriceLabelShown and barstate.islast)
    createHighLabelAt(lastMajorHighIndex, lastMajorHighPrice)

// Major Lows
plotshape(isMajorLowShown and isMajorLow, style=shape.circle, location=location.belowbar, offset=negativePlotOffset, color=color.black, transp=80, size = size.tiny)
alertcondition(low > lastMajorLowPrice, title="Chad's Major Low Breaks", message="Last major low broke")

if(isAllMajorLowPriceLabelShown and not isOnlyLastMajorLowPriceLabelShown)
    createLowLabel()

if(isOnlyLastMajorLowPriceLabelShown and barstate.islast)
    createLowLabelAt(lastMajorLowIndex, lastMajorLowPrice)

Overview

Minor swings are calculated using a 3-bar pivot structure, while major swings expand upon traditional 5-bar Williams Fractals. Users can toggle the visibility of minor and major swing points and choose whether to display price labels for all historical swings or only the most recent one. Because pivot identification requires future bars to confirm local peaks and troughs, signals lag by several bars and will repaint prior bars upon confirmation.

Details

Published by

TPCharts on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Support & resistance, Candlestick patterns

Markets

Any symbol

Timeframes

M1-M5, M15-H1

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

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

SettingTypeDefaultVariable
Show Minor Highs?booltrueisMinorHighShown
Show All Minor High Price Labels?boolfalseisAllMinorHighPriceLabelShown
Show Only Last Minor High Price Label?booltrueisOnlyLastMinorHighPriceLabelShown
Show Minor Lows?booltrueisMinorLowShown
Show All Minor Low Price Labels?boolfalseisAllMinorLowPriceLabelShown
Show Only Last Minor Low Price Label?booltrueisOnlyLastMinorLowPriceLabelShown
Show Major Highs?booltrueisMajorHighShown
Show All Major High Price Labels?boolfalseisAllMajorHighPriceLabelShown
Show Only Last Major High Price Label?booltrueisOnlyLastMajorHighPriceLabelShown
Show Major Lows?booltrueisMajorLowShown
Show All Major Low Price Labels?boolfalseisAllMajorLowPriceLabelShown
Show Only Last Major Low Price Label?booltrueisOnlyLastMajorLowPriceLabelShown
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

[RS]MTF Candle Sticks

by ricardosantos79
261 stars

This indicator overlays up to five higher-timeframe candlestick groups on the price chart. For each enabled timeframe it requests open, high, low, and close and can show up to five candles, offset by a spacing setting. The main inputs set the candle count, the

Indicator v4 Candlestick patternsSupport & resistance Repaints
Updated 4 years ago · None stated GitHub repository of [RS]MTF Candle Sticks

Candlestick Patterns

by harryguiacorn
219 stars

This indicator plots optional candlestick pattern signals on the price chart. It detects engulfing bars, inside bars, HOLP and LOHP, kicker patterns, body-mass extremes, higher highs and lower lows, ATR warnings, and four-bar fractals. Optional pivot marks use

Indicator v5 Candlestick patternsVolatility & bands
Updated 1 year ago · None stated GitHub repository of Candlestick Patterns

Strat Assistant

by rickyzcarroll
90 stars

The Strat Assistant indicator identifies candlestick patterns from the STRAT methodology on the price chart. It detects inside bars, 2-candle directional bars, 3-candle outside bars, and sequences like 212 and 222 for continuations and reversals. Shapes such a

Indicator v4 Candlestick patternsSupport & resistance
Updated 5 years ago · None stated GitHub repository of Strat Assistant
56 stars

This overlay indicator highlights candles with a body smaller than 50% of their total range by coloring them white on the price chart. Simultaneously, it calculates and plots horizontal lines for open prices across multiple higher timeframes, such as daily, we

Indicator v6 Support & resistanceCandlestick patterns Repaints
Updated 2 months ago · None stated GitHub repository of Daily Weekly Monthly Yearly Opens

This Pine Script indicator identifies liquidity sweeps and confirms signals using a close-back candle pattern directly on the price chart. It tracks recent swing highs and lows over a customizable lookback period. A bullish signal forms when a prior bar sweeps

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 2 months ago · MPL-2.0 GitHub repository of Liquidity Sweep + Close-Back Confirmation

8020 System Indicator

by TamaraKGreen
46 stars

This overlay indicator draws 80/20 price levels and optional 40-point zone bands on the price chart. It marks repairs, cross sections, and forks with optional letter labels, and can highlight confluence when those marks sit near a level. Separate options shade

Indicator v6 Support & resistanceCandlestick patterns
Updated 7 weeks ago · None stated GitHub repository of 8020 System Indicator

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