1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
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.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Show All Equal High Price Labels?
bool
false
isAllEqualHighPriceLabelShown
Show Only Last Equal High Price Label?
bool
true
isOnlyLastEqualHighPriceLabelShown
Show All Equal Low Price Labels?
bool
false
isAllEqualLowPriceLabelShown
Show Only Last Equal Low Price Label?
bool
true
isOnlyLastEqualLowPriceLabelShown
Show All Minor High Price Labels?
bool
false
isAllMinorHighPriceLabelShown
Show Only Last Minor High Price Label?
bool
true
isOnlyLastMinorHighPriceLabelShown
Show All Minor Low Price Labels?
bool
false
isAllMinorLowPriceLabelShown
Show Only Last Minor Low Price Label?
bool
true
isOnlyLastMinorLowPriceLabelShown
Show All Major High Price Labels?
bool
false
isAllMajorHighPriceLabelShown
Show Only Last Major High Price Label?
bool
true
isOnlyLastMajorHighPriceLabelShown
Show All Major Low Price Labels?
bool
false
isAllMajorLowPriceLabelShown
Show Only Last Major Low Price Label?
bool
true
isOnlyLastMajorLowPriceLabelShown
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.
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
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
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
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
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
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