Indicator · Pine Script v5 · Own pane

Q-Trend

by middlechild0· code credited to tarasenko_

Q-Trend is a trend-following indicator that calculates a dynamic trend line using price channels and an ATR volatility offset.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code81
Settings13inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago13 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

81 lines of Pine Script v5 from mt5/indicators/pine/q_trend.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

q_trend.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tarasenko_

//@version=5
indicator("Q-Trend", overlay = 1) 


// Inputs
src = input(close, "Source", group = "Main settings")
p = input.int(200, "Trend period", group = "Main settings", tooltip = "Changes STRONG signals' sensitivity.", minval = 1)
atr_p = input.int(14, "ATR Period", group = "Main settings", minval = 1)
mult = input.float(1.0, "ATR Multiplier", step = 0.1, group = "Main settings", tooltip = "Changes sensitivity: higher period = higher sensitivty.")
mode = input.string("Type A", "Signal mode", options = ["Type A", "Type B"], group = "Mode")
use_ema_smoother = input.string("No", "Smooth source with EMA?", options = ["Yes", "No"], group = "Source")
src_ema_period = input(3, "EMA Smoother period", group = "Source")
color_bars = input(true, "Color bars?", group = "Addons")
show_tl = input(true, "Show trend line?", group = "Addons")
signals_view = input.string("All", "Signals to show", options = ["All", "Buy/Sell", "Strong", "None"], group = "Signal's Addon")
signals_shape = input.string("Labels", "Signal's shape", options = ["Labels", "Arrows"], group = "Signal's Addon")
buy_col = input(color.green, "Buy colour", group = "Signal's Addon", inline = "BS")
sell_col = input(color.red, "Sell colour", group = "Signal's Addon", inline = "BS")




// Calculations
src := use_ema_smoother == "Yes" ? ta.ema(src, src_ema_period) : src // Source;

h = ta.highest(src, p) // Highest of src p-bars back;
l = ta.lowest(src, p) // Lowest of src p-bars back.
d = h - l

ls = "" // Tracker of last signal

m = (h + l) / 2 // Initial trend line;
m := bar_index > p ? m[1] : m

atr = ta.atr(atr_p)[1] // ATR;
epsilon = mult * atr // Epsilon is a mathematical variable used in many different theorems in order to simplify work with mathematical object. Here it used as sensitivity measure.

change_up = (mode == "Type B" ? ta.cross(src, m + epsilon) : ta.crossover(src, m + epsilon)) or src > m + epsilon // If price breaks trend line + epsilon (so called higher band), then it is time to update the value of a trend line;
change_down = (mode == "Type B" ? ta.cross(src, m - epsilon) : ta.crossunder(src, m - epsilon)) or src < m - epsilon // If price breaks trend line - epsilon (so called higher band), then it is time to update the value of a trend line.
sb = open < l + d / 8 and open >= l
ss = open > h - d / 8 and open <= h
strong_buy = sb or sb[1] or sb[2] or sb[3] or sb[4]
strong_sell = ss or ss[1] or ss[2] or ss[3] or ss[4]

m := (change_up or change_down) and m != m[1] ? m : change_up ? m + epsilon : change_down ? m - epsilon : nz(m[1], m) // Updating the trend line.

ls := change_up ? "B" : change_down ? "S" : ls[1] // Last signal. Helps avoid multiple labels in a row with the same signal;
colour = ls == "B" ? buy_col : sell_col // Colour of the trend line.
buy_shape   = signals_shape == "Labels" ? shape.labelup     : shape.triangleup
sell_shape  = signals_shape == "Labels" ? shape.labeldown   : shape.triangledown




// Plottings
plot(show_tl ? m : na, "trend line", colour, 3) // Plotting the trend line.

// Signals with label shape
plotshape(signals_shape == "Labels" and (signals_view == "All" or signals_view == "Buy/Sell") and change_up and ls[1] != "B" and not strong_buy, "Buy signal"       , color = colour, style = buy_shape , location = location.belowbar, size = size.normal, text = "BUY", textcolor = color.white)      // Plotting the BUY signal;
plotshape(signals_shape == "Labels" and (signals_view == "All" or signals_view == "Buy/Sell") and change_down and ls[1] != "S" and not strong_sell, "Sell signal"   , color = colour, style = sell_shape, size = size.normal, text = "SELL", textcolor = color.white)                                   // Plotting the SELL signal.
plotshape(signals_shape == "Labels" and (signals_view == "All" or signals_view == "Strong") and change_up and ls[1] != "B" and strong_buy, "Strong Buy signal"      , color = colour, style = buy_shape , location = location.belowbar, size = size.normal, text = "STRONG", textcolor = color.white)   // Plotting the STRONG BUY signal;
plotshape(signals_shape == "Labels" and (signals_view == "All" or signals_view == "Strong") and change_down and ls[1] != "S" and strong_sell, "Strong Sell signal"  , color = colour, style = sell_shape, size = size.normal, text = "STRONG", textcolor = color.white)                                 // Plotting the STRONG SELL signal.

// Signal with arrow shape
plotshape(signals_shape == "Arrows" and (signals_view == "All" or signals_view == "Buy/Sell") and change_up and ls[1] != "B" and not strong_buy, "Buy signal"       , color = colour, style = buy_shape , location = location.belowbar, size = size.tiny) // Plotting the BUY signal;
plotshape(signals_shape == "Arrows" and (signals_view == "All" or signals_view == "Buy/Sell") and change_down and ls[1] != "S" and not strong_sell, "Sell signal"   , color = colour, style = sell_shape, size = size.tiny)                               // Plotting the SELL signal.
plotshape(signals_shape == "Arrows" and (signals_view == "All" or signals_view == "Strong") and change_up and ls[1] != "B" and strong_buy, "Strong Buy signal"      , color = colour, style = buy_shape , location = location.belowbar, size = size.tiny) // Plotting the STRONG BUY signal;
plotshape(signals_shape == "Arrows" and (signals_view == "All" or signals_view == "Strong") and change_down and ls[1] != "S" and strong_sell, "Strong Sell signal"  , color = colour, style = sell_shape, size = size.tiny)                               // Plotting the STRONG SELL signal.

barcolor(color_bars ? colour : na) // Bar coloring


// Alerts
alertcondition(change_up and ls[1] != "B", "Q-Trend BUY", "Q-Trend BUY signal were given.") // Buy alert.
alertcondition(change_down and ls[1] != "S", "Q-Trend SELL", "Q-Trend SELL signal were given.") // Sell alert.
alertcondition((change_up and ls[1] != "B") or (change_down and ls[1] != "S"), "Q-Trend Signal", "Q-Trend gave you a signal!")
alertcondition(change_up and ls[1] != "B" and strong_buy, "Strong BUY signal", "Q-Trend gave a Strong Buy signal!")
alertcondition(change_down and ls[1] != "S" and strong_sell, "Strong SELL signal", "Q-Trend gave a Strong Sell signal!")

Overview

Q-Trend plots a colored trend line directly on the price chart, switching between bullish and bearish modes when price breaches the upper or lower volatility bounds. The script identifies standard and strong buy or sell signals, displaying them as labels or arrows. Users can customize the trend lookback period, ATR sensitivity, signal filtering modes, and optional source smoothing using an EMA.

Details

Published by

middlechild0 on GitHub

Code credit

tarasenko_, as written in the script's header

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Trend, Volatility & bands

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
Sourcesourceclosesrc
Trend periodint200p
ATR Periodint14atr_p
ATR Multiplierfloat1.0mult
Signal modestringType Amode
Smooth source with EMA?stringNouse_ema_smoother
EMA Smoother periodint3src_ema_period
Color bars?booltruecolor_bars
Show trend line?booltrueshow_tl
Signals to showstringAllsignals_view
Signal's shapestringLabelssignals_shape
Buy colourcolorcolor.greenbuy_col
Show all 13 settings
SettingTypeDefaultVariable
Sell colourcolorcolor.redsell_col
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

This indicator plots a Supertrend-based trend-following setup in a separate pane and skips conditions it treats as a sideways market. A volatility range is built from an ATR value, with RMA, SMA, EMA, or WMA smoothing, or from a fixed point distance. Optional

Indicator v5 TrendVolatility & bands
Updated 1 year ago · MPL-2.0 GitHub repository of Trend Following Setup - Sideways Market Skipper
147 stars

This indicator generates trade entry signals and target levels optimized for 1-hour timeframes, designed for external signal extraction. It calculates 7-period and 16-period EMAs alongside 10-period RSI and ATR filters. Long signals occur when the fast EMA cro

Indicator v5 TrendOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of Signal Strategy 100 Candles of 1H Timeframe

MultiIndicator

by capissimo
114 stars

MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator

This indicator plots an oscillator in a separate pane. It builds several SuperTrend series across a user-defined factor range and step, using ATR as the band width. On each bar it measures the distance between the close and each SuperTrend output, then groups

Indicator v5 TrendVolatility & bands
Updated 2 years ago · GPL-3.0 GitHub repository of AI SuperTrend Clustering Oscillator [LuxAlgo]

Choppiness Index

by mihakralj
99 stars

The script plots the Choppiness Index in a separate pane. It sums true range over a lookback and compares that sum with the highest-high to lowest-low range, then scales the result from 0 to 100. Lower readings indicate a trending market and higher readings in

Indicator v6 TrendVolatility & bands
Updated 4 weeks ago · Apache-2.0 GitHub repository of Choppiness Index

This indicator combines Chaikin Money Flow (CMF), a SuperTrend baseline, and an Average True Range (ATR) calculation inside a separate sub-pane. It calculates a standard 20-period CMF plotted as a line and colored histogram columns around a zero baseline, trac

Indicator v6 TrendVolume
Updated 6 months ago · Apache-2.0 GitHub repository of Institutional View: CMF & SuperTrend

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