Indicator · Pine Script v4 · On the chart

Chad's Swing Points (@tradeprophet)

by TPCharts

Chad's Swing Points marks swing highs and lows on the price chart.

View on GitHub

Repaints

GitHub stars10on the repository
Pine versionv4older, still runs
Lines of code183
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

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

Chad's Swing Points.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 miOff = 2
var nmiOff = -1*miOff

var maOff = 3
var nmaOff = -1*maOff

var eqOff = 1
var neqOff = -1*eqOff

var lastBullCandleIndex = 0
var lastBullCandlePrice = float(na)
var lastBearCandleIndex = 0
var lastBearCandlePrice = float(na)

// Equal Highs (2 par patterns)
var isAllEqualHighPriceLabelShown = input(false, "Show All Equal High Price Labels?")
var isOnlyLastEqualHighPriceLabelShown = input(true, "Show Only Last Equal High Price Label?")
var lastEqualHighIndex = int(na)
var lastEqualHighPrice = float(na)

// Equal Lows (2 par patterns)
var isAllEqualLowPriceLabelShown = input(false, "Show All Equal Low Price Labels?")
var isOnlyLastEqualLowPriceLabelShown = input(true, "Show Only Last Equal Low Price Label?")
var lastEqualLowIndex = int(na)
var lastEqualLowPrice = float(na)

// Minor highs (3 bar pattern)
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 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 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)
var lastMajorHighIndex2 = int(na)
var lastMajorHighPrice2 = float(na)

// Major Lows (5 par patterns)
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)
var lastMajorLowIndex2 = int(na)
var lastMajorLowPrice2 = float(na)

//
// 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)

// Equal highs (3 bar pattern)
isEqualHigh = (high[1] == high[2])
if isEqualHigh
    lastEqualHighIndex := bar_index-eqOff
    lastEqualHighPrice := high[eqOff]

plotshape(isEqualHigh, title="Equal Highs", style=shape.xcross, location=location.abovebar, offset=neqOff, color=color.black, transp=80, size = size.tiny)
alertcondition(high > lastMinorHighPrice, title="Chad's Equal High Breaks", message="Last equal high broke")

// Equal Lows (3 bar pattern)
isEqualLow = (low[1] == low[2])
if isEqualLow
    lastEqualLowIndex := bar_index-eqOff
    lastEqualLowPrice := low[eqOff]

plotshape(isEqualLow, title="Equal Lows", style=shape.xcross, location=location.belowbar, offset=neqOff, color=color.black, transp=80, size = size.tiny)
alertcondition(low < lastMinorLowPrice, title="Chad's Equal Low Breaks", message="Last equal low broke")

//  
// MINORS
//

// Minor highs (3 bar pattern)
testIfMinorHigh(i) => (high[i+1] < high[i]) and (high[i-1] < high[i])

isMinorHigh = testIfMinorHigh(miOff) 
if isMinorHigh
    lastMinorHighIndex := bar_index-miOff
    lastMinorHighPrice := high[miOff]

plotshape(isMinorHigh, title="Minor Highs", style=shape.triangleup, location=location.abovebar, offset=nmiOff, color=color.black, transp=80, size = size.tiny) 
alertcondition(high > lastMinorHighPrice, title="Chad's Minor High Breaks", message="Last minor high broke")

// Minor lows (3 bar pattern)
testIfMinorLow(i) => (low[i+1] > low[i]) and (low[i-1] > low[i])

isMinorLow = testIfMinorLow(miOff) 
if isMinorLow
    lastMinorLowIndex := bar_index-miOff
    lastMinorLowPrice := low[miOff]

plotshape(isMinorLow, title="Minor Lows", style=shape.triangledown, location=location.belowbar, offset=nmiOff, color=color.black, transp=80, size = size.tiny) 
alertcondition(low < lastMinorLowPrice, title="Chad's Minor Low Breaks", message="Last minor low broke")

//
// MAJORS
//
// Major Highs (5 par patterns)
isMajorHigh = testIfMinorHigh(maOff) and (high[maOff+2] < high[maOff]) and (high[maOff-2] < high[maOff])
if isMajorHigh
    lastMajorHighIndex2 := lastMajorHighIndex
    lastMajorHighIndex := bar_index-maOff
    lastMajorHighPrice2 := lastMajorHighPrice
    lastMajorHighPrice := high[maOff]

plotshape(isMajorHigh, title="Major Highs", style=shape.circle, location=location.abovebar, offset=nmaOff, color=color.black, transp=60, size=size.tiny) 
alertcondition(high > lastMajorHighPrice, title="Chad's Major High Breaks", message="Last major high broke")

// Major Lows (5 par patterns)
isMajorLow = testIfMinorLow(maOff) and (low[maOff+2] > low[maOff]) and (low[maOff-2] > low[maOff])
if isMajorLow
    lastMajorLowIndex2 := lastMajorLowIndex
    lastMajorLowIndex := bar_index-maOff
    lastMajorLowPrice2 := lastMajorLowPrice
    lastMajorLowPrice := low[maOff]

plotshape(isMajorLow, title="Major Lows", style=shape.circle, location=location.belowbar, offset=nmaOff, color=color.black, transp=60, size = size.tiny) 
alertcondition(low < lastMajorLowPrice, title="Chad's Major Low Breaks", message="Last major low broke")

// Market Structure
isCandleBull(i) => close[i] > open[i]
isCandleBear(i) => not isCandleBull(i)
isBullStructure() => lastMajorHighPrice > lastMajorHighPrice2 and lastMajorLowPrice > lastMajorLowPrice2
isBearStructure() => not isBullStructure()

// d(isBearStructure() ? 1 : 0)

if isCandleBull(1)
    lastBullCandleIndex := bar_index-1
    lastBullCandlePrice := open[1]

if isBullStructure() 
    // d(bar_index)
    bullMSB = line.new(x1=lastMajorLowIndex, y1=lastMajorLowPrice, x2=bar_index, y2=lastMajorLowPrice, extend=extend.right)
    line.delete(bullMSB[1])


// if isBearCandle(bar_index)
//     lastBearCandleIndex := bar_index
//     lastBearCandlePrice := close

// if(lastMajorLowPrice > lastMajorLowPricce2)
//     bullMSB = line.new(x1=lastMajorHighIndex, y1=lastMajorHighPrice, x2=bar_index, y2=lastMajorHighPrice, extend=extend.right)
//     line.delete(bullMSB[1])
// else
//     bullMSB = line.new(x1=lastMajorHighIndex2, y1=lastMajorHighPrice2, x2=bar_index, y2=lastMajorHighPrice2, extend=extend.right)
//     line.delete(bullMSB[1])

// if(lastMajorHighPrice < lastMajorHighPrice2)
//     // bearBreaker = line.new(x1=lastBullCandleIndex, y1=lastBullCandlePrice, x2=bar_index, y2=lastBullCandlePrice, extend=extend.right, color=color.red)
//     bearMSB = line.new(x1=lastMajorLowIndex, y1=lastMajorLowPrice, x2=bar_index, y2=lastMajorLowPrice, extend=extend.right)
//     line.delete(bearMSB[1])
// else
//     bearMSB = line.new(x1=lastMajorLowIndex2, y1=lastMajorLowPrice2, x2=bar_index, y2=lastMajorLowPrice2, extend=extend.right)
//     line.delete(bearMSB[1])

Overview

Chad's Swing Points (@tradeprophet) detects equal highs and lows, three-bar minor swings, and five-bar major fractals similar to Williams fractals. Users choose whether each group shows every price label or only the latest one. Markers plot above or below price, and the script defines alert conditions for breaks. The author notes likely repainting, especially for alerts. The listing is unfinished, so later swing logic may be incomplete.

Details

Published by

TPCharts on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Support & resistance

Markets

Any symbol

Timeframes

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 All Equal High Price Labels?boolfalseisAllEqualHighPriceLabelShown
Show Only Last Equal High Price Label?booltrueisOnlyLastEqualHighPriceLabelShown
Show All Equal Low Price Labels?boolfalseisAllEqualLowPriceLabelShown
Show Only Last Equal Low Price Label?booltrueisOnlyLastEqualLowPriceLabelShown
Show All Minor High Price Labels?boolfalseisAllMinorHighPriceLabelShown
Show Only Last Minor High Price Label?booltrueisOnlyLastMinorHighPriceLabelShown
Show All Minor Low Price Labels?boolfalseisAllMinorLowPriceLabelShown
Show Only Last Minor Low Price Label?booltrueisOnlyLastMinorLowPriceLabelShown
Show All Major High Price Labels?boolfalseisAllMajorHighPriceLabelShown
Show Only Last Major High Price Label?booltrueisOnlyLastMajorHighPriceLabelShown
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

948 stars

Moving Average Channel plots separate simple moving averages for upper and lower bands on the price chart. It fills the space between bands with semi-transparent color and colors bars green above the upper band, red below the lower band, or gray in between. Us

Indicator v4 Moving averagesSupport & resistance
Updated 10 days ago · GPL-3.0 GitHub repository of Moving Average Channel

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
330 stars

This indicator monitors multiple cryptocurrency symbols for trading signals. It calculates and plots entry prices, take profit, and stop loss levels for each symbol including BTCUSDT, ETHUSDT, BNBUSDT and others. Price crossovers trigger buy, sell or close ale

Indicator v5 Support & resistanceScreeners & dashboards
Updated 2 months ago · None stated GitHub repository of Multi Alert Long/Short [Alorse]

This overlay indicator draws a fixed-range volume profile on the price chart, splitting traded activity into up and down volume at each price level. It also plots a sentiment profile, a developing point of control, and value-area high and low around a configur

Indicator v5 VolumeSupport & resistance
Updated 2 months ago · MIT GitHub repository of Volume Profile and Indicator by DGT

BZ-tracker

by Allen1212
303 stars

The BZ-tracker indicator marks ARK Invest buy and sell transactions on stock charts with labels. It plots green labels for purchases and red labels for sales, each annotated with a multiplier such as X1 or X2 to show the number of ARK ETFs trading the stock on

Indicator v4 Support & resistanceScreeners & dashboards
Updated 2 years ago · None stated GitHub repository of BZ-tracker

Function - Linear Regression

by ricardosantos79
261 stars

This indicator fits a linear regression through stored pivot highs and lows and draws the resulting channel on the price chart. A function returns predicted values, maximum and minimum deviations, and the average absolute deviation. Confirmed two-bar pivots up

Indicator v5 TrendSupport & resistance
Updated 4 years ago · None stated GitHub repository of Function - Linear Regression

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