Trend flip labels
A green label prints under price when the line climbs above its trailing stop, and a red one prints over price when it drops below. Each label sits at the 14-bar extreme, so it never covers the candles it describes.
Live demo
Every candle color, line segment and label below comes from the indicator's own formulas. Switch markets, change the timeframe or open the settings and watch it react.
Preparing the chart
Live Binance market data, refreshed every 15 seconds. For education only, not financial advice.
Drag to pan. Click the chart, then scroll to zoom.
BTC/USDT right now, exactly as the indicator's table reads it.
Reading every timeframe
How it works
Step through the pipeline on the most recent bars of the live chart. Every line here is computed with the same formulas as the Pine Script, so you can see exactly what each stage removes.
BTC/USDT · 1h · last 120 bars
Loading live bars
What you see on the chart
One line, two colors and a label only when the trend actually turns. Everything else is optional and switches on from the indicator's inputs.
A green label prints under price when the line climbs above its trailing stop, and a red one prints over price when it drops below. Each label sits at the 14-bar extreme, so it never covers the candles it describes.
A compact table in the top-right corner reports the trend on five timeframes you choose, 5 minutes to 1 day by default. This one is live.
| Time Frame | Signal |
| 5 | … |
| 15 | … |
| 60 | … |
| 240 | … |
| 1D | … |
| Note | Mid-trend signals disabled, 'Ranging' signals won't appear. |
When the line's slope points against its trend, bars turn gray to flag a choppy phase. A fresh label prints the moment the chop resolves back into the trend.
Volume is ranked against the last 33 bars and smoothed with a 4-bar Hull average. Heavy volume makes the line and candles solid, quiet volume fades them.
Gradient bands sit two average candle bodies from the line, measured over 100 bars, showing how much room the trend has before it gets tested.
Candles take on the trend color, so direction is readable at a glance even when the line sits behind price.
Pick any of them in TradingView's alert dialog to get notified on a flip without watching the chart. Choppy Market fires only while Mid-Trend Signals is on.
Settings
These are the defaults the indicator ships with. Try any of them on the live chart first, then copy the values into TradingView.
Get started
Paste the source into the Pine Editor for this exact version, or add AlgoAlpha's published copy straight from TradingView's community library.
Use the copy button on this page. It copies the complete source, license header included.
On any TradingView chart, open the Pine Editor. Depending on your layout it sits in the bottom panel or in the toolbar on the right.
From the editor's script menu choose Create new, then Indicator. Select all of the template code and paste the script over it.
Press Ctrl + S (or Cmd + S on a Mac) to save it to your account, then click Add to chart.
Option 1
Copy the full Pine Script v6 code, then follow the four steps.
Option 2
Open the Indicators menu on your chart, search for Smoothed Gaussian Trend Filter and pick the one by AlgoAlpha.
View the script page(opens in a new tab)Each TradingView plan limits how many indicators fit on one chart. If you are at the limit, remove one before adding this.
Source
Released by AlgoAlpha under the Mozilla Public License 2.0. You can read, use and adapt every line. Keep the license header when you share it.
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © AlgoAlpha//@version=6indicator("Smoothed Gaussian Trend Filter [AlgoAlpha]", "AlgoAlpha - Smoothed Gaussian Trend", overlay = true) periodInput = input.int(15, title="Gaussian Length", tooltip="Period used to calculate the Gaussian alpha.", group = "Gaussian Filter Settings")polesInput = input.int(3, title="Poles", minval=1, maxval=4, tooltip="Order of the Gaussian filter, affects smoothness.", group = "Gaussian Filter Settings")linreglen = input.int(22, title="Smoothing Length", tooltip="Length for linear regression smoothing applied on the gaussian line.", group = "Smoothing Settings")linregoffset = input.int(7, title="Flatten Multiplier", tooltip="Offset for flattening the output, making it less wavey.", group = "Smoothing Settings") en_table = input.bool(true, title="Enable Table", tooltip="Enables/Disables the table.", group = "Extra Timeframes")table_size = input.string("Tiny", title="Table Size", options = ["Tiny", "Small", "Medium", "Large"], tooltip="Size of the table.", group = "Extra Timeframes")t1 = input.timeframe("5", "Time frame 1", group = "Extra Timeframes")t2 = input.timeframe("15", "Time frame 2", group = "Extra Timeframes")t3 = input.timeframe("60", "Time frame 3", group = "Extra Timeframes")t4 = input.timeframe("240", "Time frame 4", group = "Extra Timeframes")t5 = input.timeframe("1D", "Time frame 5", group = "Extra Timeframes") vol_int = input.bool(true, title="", tooltip="Highlight based on volume intensity.", group = "Appearance", inline = "vol")vol_filt = input.int(70, title="Volume Intensity Highlighting Strength", minval=1, maxval=99, tooltip="Adjusts sensitivity to volume changes.", group = "Appearance", inline = "vol")mid_trnd_sig = input.bool(false, title=" Mid-Trend Signals", tooltip="Enable additional buy/sell signals during trends.", group = "Appearance")bands = input.bool(false, title=" Trailing Bands", tooltip="Enables/Disables Trend Bands", group = "Appearance")barcol = input.bool(true, title=" Bar Color", tooltip="Enables/Disables Candle Colouring", group = "Appearance")green = input.color(#00ffbb, title="Bullish Color", tooltip="Color for bullish signals and indicators.", group = "Appearance")red = input.color(#ff1100, title="Bearish Color", tooltip="Color for bearish signals and indicators.", group = "Appearance") calcGaussianAlpha(_length, _order) => freq = (2.0 * math.pi) / _length factorB = (1.0 - math.cos(freq)) / (math.pow(1.414, (2.0 / _order)) - 1.0) alphaVal = -factorB + math.sqrt(factorB * factorB + 2.0 * factorB) alphaVal gaussianSmooth(dataIn, filterLevel, alphaCoeff) => var float runningFilterValue = 0.0 oneMinusAlpha = 1.0 - alphaCoeff alphaSquared = alphaCoeff * alphaCoeff alphaCubed = alphaCoeff * alphaCoeff * alphaCoeff alpha4 = alphaCoeff * alphaCoeff * alphaCoeff * alphaCoeff omaSquared = oneMinusAlpha * oneMinusAlpha omaCubed = omaSquared * oneMinusAlpha oma4 = omaCubed * oneMinusAlpha if filterLevel == 1 runningFilterValue := alphaCoeff * dataIn + oneMinusAlpha * nz(runningFilterValue[1]) else if filterLevel == 2 runningFilterValue := alphaSquared * dataIn + 2.0 * oneMinusAlpha * nz(runningFilterValue[1]) - omaSquared * nz(runningFilterValue[2]) else if filterLevel == 3 runningFilterValue := alphaCubed * dataIn + 3.0 * oneMinusAlpha * nz(runningFilterValue[1]) - 3.0 * omaSquared * nz(runningFilterValue[2]) + omaCubed * nz(runningFilterValue[3]) else if filterLevel == 4 runningFilterValue := alpha4 * dataIn + 4.0 * oneMinusAlpha * nz(runningFilterValue[1]) - 6.0 * omaSquared * nz(runningFilterValue[2]) + 4.0 * omaCubed * nz(runningFilterValue[3]) - oma4 * nz(runningFilterValue[4]) runningFilterValue pine_supertrend(src, factor, atrPeriod) => atr = ta.atr(atrPeriod) upperBand = src + factor * atr lowerBand = src - factor * atr prevLowerBand = nz(lowerBand[1]) prevUpperBand = nz(upperBand[1]) lowerBand := lowerBand > prevLowerBand or src[1] < prevLowerBand ? lowerBand : prevLowerBand upperBand := upperBand < prevUpperBand or src[1] > prevUpperBand ? upperBand : prevUpperBand int _direction = na float superTrend = na prevSuperTrend = superTrend[1] if na(atr[1]) _direction := 1 else if prevSuperTrend == prevUpperBand _direction := src > upperBand ? -1 : 1 else _direction := src < lowerBand ? 1 : -1 superTrend := _direction == -1 ? lowerBand : upperBand [superTrend, _direction] tableSize(table_size) => switch table_size "Tiny" => size.tiny "Small" => size.small "Medium" => size.normal "Large" => size.large alphaValue = calcGaussianAlpha(periodInput, polesInput)gmaOutput = gaussianSmooth(close, polesInput, alphaValue)final = ta.linreg(gmaOutput, linreglen, linregoffset) [ST, dir] = pine_supertrend(final, 0.15, 21)trend = final > final[1] ? 1 : -1trend1 = final > ST ? 1 : -1ranging = (trend * trend1 < 0) z = 33s_vol = ta.hma((volume - ta.lowest(volume, z)) / (ta.highest(volume, z) - ta.lowest(volume, z)), 4)transparency_ = math.min(100 - s_vol * 100, vol_filt)dist = ta.sma(math.abs(close - open), 100) main = plot(final, color=ranging and mid_trnd_sig ? color.gray : trend1 > 0 ? color.new(green, vol_int ? transparency_ : 50) : color.new(red, vol_int ? transparency_ : 50), linewidth=3)bull = plot(trend1 > 0 ? final - dist * 2 : na, style=plot.style_linebr, color=color.new(green, 90), display = bands ? display.all : display.none)bear = plot(trend1 < 0 ? final + dist * 2 : na, style=plot.style_linebr, color=color.new(red, 90), display = bands ? display.all : display.none)fill(main, bull, final, final - dist * 2, color.new(ranging and mid_trnd_sig ? color.gray : green, vol_int ? transparency_ : 50), color.new(ranging and mid_trnd_sig ? color.gray : green, 93), display = bands ? display.all : display.none)fill(main, bear, final + dist * 2, final, color.new(ranging and mid_trnd_sig ? color.gray : red, 93), color.new(ranging and mid_trnd_sig ? color.gray : red, vol_int ? transparency_ : 50), display = bands ? display.all : display.none) h = math.max(ta.highest(14), ta.highest(final, 14), final + dist * 2)l = math.min(ta.lowest(14), ta.lowest(final, 14), final - dist * 2) plotshape(trend1 > 0 and (mid_trnd_sig ? not ranging and ranging[1] : trend1[1] < 0) ? l : na, title="Bullish Signal", style=shape.labelup, location=location.absolute, size=size.small, color=green)plotshape(trend1 < 0 and (mid_trnd_sig ? not ranging and ranging[1] : trend1[1] > 0) ? h : na, title="Bearish Signal", style=shape.labeldown, location=location.absolute, size=size.small, color=red) barcolor(barcol ? ranging and mid_trnd_sig ? color.gray : trend1 > 0 ? color.new(green, vol_int ? transparency_ : 50) : color.new(red, vol_int ? transparency_ : 50) : na, title = "Bar Coloring") s1 = request.security(syminfo.tickerid, t1, ranging and mid_trnd_sig ? 0 : trend1 > 0 ? 1 : -1)s2 = request.security(syminfo.tickerid, t2, ranging and mid_trnd_sig ? 0 : trend1 > 0 ? 1 : -1)s3 = request.security(syminfo.tickerid, t3, ranging and mid_trnd_sig ? 0 : trend1 > 0 ? 1 : -1)s4 = request.security(syminfo.tickerid, t4, ranging and mid_trnd_sig ? 0 : trend1 > 0 ? 1 : -1)s5 = request.security(syminfo.tickerid, t5, ranging and mid_trnd_sig ? 0 : trend1 > 0 ? 1 : -1) s1a = s1 == 1 ? "Bullish" : s1 == -1 ? "Bearish" : "Ranging"s2a = s2 == 1 ? "Bullish" : s2 == -1 ? "Bearish" : "Ranging "s3a = s3 == 1 ? "Bullish" : s3 == -1 ? "Bearish" : "Ranging"s4a = s4 == 1 ? "Bullish" : s4 == -1 ? "Bearish" : "Ranging"s5a = s5 == 1 ? "Bullish" : s5 == -1 ? "Bearish" : "Ranging" if barstate.islast and en_table var data_table = table.new(position=position.top_right, columns=2, rows=mid_trnd_sig ? 6 : 7, bgcolor=chart.bg_color, border_width=1, border_color=chart.fg_color, frame_color=chart.fg_color, frame_width=1) table.cell(data_table, text_halign=text.align_center, column=0, row=0, text="Time Frame", text_color=chart.fg_color, text_size=tableSize(table_size)) table.cell(data_table, text_halign=text.align_center, column=1, row=0, text="Signal", text_color=chart.fg_color, text_size=tableSize(table_size)) table.cell(data_table, text_halign=text.align_center, column=0, row=1, text=t1, text_color=chart.fg_color, text_size=tableSize(table_size)) table.cell(data_table, text_halign=text.align_center, column=1, row=1, text=s1a, text_color=chart.fg_color, bgcolor=s1a == "Bullish" ? color.new(green, 70) : s1a == "Bearish" ? color.new(red, 70) : color.new(color.gray, 70), text_size=tableSize(table_size)) table.cell(data_table, text_halign=text.align_center, column=0, row=2, text=t2, text_color=chart.fg_color, text_size=tableSize(table_size)) table.cell(data_table, text_halign=text.align_center, column=1, row=2, text=s2a, text_color=chart.fg_color, bgcolor=s2a == "Bullish" ? color.new(green, 70) : s2a == "Bearish" ? color.new(red, 70) : color.new(color.gray, 70), text_size=tableSize(table_size)) table.cell(data_table, text_halign=text.align_center, column=0, row=3, text=t3, text_color=chart.fg_color, text_size=tableSize(table_size)) table.cell(data_table, text_halign=text.align_center, column=1, row=3, text=s3a, text_color=chart.fg_color, bgcolor=s3a == "Bullish" ? color.new(green, 70) : s3a == "Bearish" ? color.new(red, 70) : color.new(color.gray, 70), text_size=tableSize(table_size)) table.cell(data_table, text_halign=text.align_center, column=0, row=4, text=t4, text_color=chart.fg_color, text_size=tableSize(table_size)) table.cell(data_table, text_halign=text.align_center, column=1, row=4, text=s4a, text_color=chart.fg_color, bgcolor=s4a == "Bullish" ? color.new(green, 70) : s4a == "Bearish" ? color.new(red, 70) : color.new(color.gray, 70), text_size=tableSize(table_size)) table.cell(data_table, text_halign=text.align_center, column=0, row=5, text=t5, text_color=chart.fg_color, text_size=tableSize(table_size)) table.cell(data_table, text_halign=text.align_center, column=1, row=5, text=s5a, text_color=chart.fg_color, bgcolor=s5a == "Bullish" ? color.new(green, 70) : s5a == "Bearish" ? color.new(red, 70) : color.new(color.gray, 70), text_size=tableSize(table_size)) if not mid_trnd_sig table.cell(data_table, text_halign=text.align_center, column=0, row=6, text="Note", text_color=chart.fg_color, text_size=tableSize(table_size)) table.cell(data_table, text_halign=text.align_center, column=1, row=6, text="Mid-trend signals disabled, 'Ranging' signals won't appear.", text_color=chart.fg_color, text_size=tableSize(table_size)) alertcondition(trend1 > 0 and (mid_trnd_sig ? not ranging and ranging[1] : trend1[1] < 0), title="Bullish Signal", message="Bullish signal triggered.")alertcondition(trend1 < 0 and (mid_trnd_sig ? not ranging and ranging[1] : trend1[1] > 0), title="Bearish Signal", message="Bearish signal triggered.")alertcondition(ranging and mid_trnd_sig, title="Choppy Market", message="Choppy market conditions detected.")The copy button always copies the full script, license header included, ready to paste into the Pine Editor.
Alerts
The script ships with three alert conditions, so you can step away from the screen and still catch every flip.
Fires when the trend flips up. With Mid-Trend Signals on, it fires instead when a choppy phase ends with the trend pointing up.
Alert message: Bullish signal triggered.
Fires when the trend flips down. With Mid-Trend Signals on, it fires instead when a choppy phase ends with the trend pointing down.
Alert message: Bearish signal triggered.
Fires while the line's slope disagrees with its trend. Only available when Mid-Trend Signals is turned on.
Alert message: Choppy market conditions detected.
FAQ
Short answers about cost, repainting, markets and the live demo on this page.
Yes. AlgoAlpha published it as an open-source script under the Mozilla Public License 2.0. You can use it, read every line and adapt it, as long as the license notice stays in the code.
Each value is calculated from the current bar and the bars before it, so closed bars keep their colors and labels. The bar that is still forming can change until it closes, like any live indicator, and the timeframe table follows the forming bar of each timeframe. Set alerts to Once Per Bar Close if you only want confirmed signals.
Any chart TradingView can draw, including crypto, stocks, forex, futures and indices, on any timeframe. Volume intensity reads the symbol's volume, so on an instrument without volume data you can switch that input off.
Gray only appears with Mid-Trend Signals turned on. It marks bars where the line's slope points against the trend, which usually means the market is moving sideways.
Yes. Time frame 1 to 5 in the Extra Timeframes group accept any TradingView timeframe, and Table Size scales the table from Tiny to Large. You can try both in the live settings on this page.
The page recreates the indicator's formulas and runs them on live Binance prices, with Kraken as a backup feed. Small differences from your TradingView chart can come from the data feed and from how much history each chart has loaded.
No. The indicator is a tool for reading trend, not a promise of future returns. Test it on your own markets, combine it with your own analysis and manage your risk.
Copy the script, paste it into the Pine Editor and you are one click away from seeing it on your own symbols.