Indicator · Pine Script v5 · On the chart

ATR% Multiple from 50-MA

by Fred6725· code credited to jeffsuntrading

Measures how far price has moved from its 50-period moving average in multiples of ATR percent, using daily data.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code53
Settings9inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago27 Dec 2024

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

53 lines of Pine Script v5 from ATR% multiple from 50-MA.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

ATR% multiple from 50-MA.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jeffsuntrading

//@version=5
indicator(title="ATR% multiple from 50-MA", overlay=true, max_labels_count = 500)

// 1) Inputs
atr_len     = input(14, title="ATR Length", tooltip="The number of daily bars used in the calculation of the ATR")
len         = input(50, title="MA length", tooltip="The lenght of the MA used for calculation")
thresold    = input(10, title = "Multiple ATR for detection", tooltip="Above this ATR multiple between close and MA50 Daily, the candles will be marked")
ShapeOrChar = input.string("tiny", title="Size of the Dot", options=["normal", "tiny"])
dotCol      = input(color.yellow, title = "Dots Color")
table       = input(true, title="Display Info Table", group = "table")
txt_col     = input(color.orange, title="Table Text Color", group = "table")
twt_ext     = input(color.red, title="Extended Text Color", group = "table")
tbl_size    = input.string(size.normal, title='Table Size', options=[size.tiny,size.small,size.normal, size.large])

// 2) Calculation
closeDa              = request.security(syminfo.tickerid, 'D', close)
highDa               = request.security(syminfo.tickerid, 'D', high)
atr                  = request.security(syminfo.tickerid, 'D', ta.atr(atr_len))
atrpercent           = (atr/closeDa) * 100
sma50                = request.security(syminfo.tickerid, 'D', ta.sma(close, len))
// Calulation using the daily close
percentGainFromSMA   = (closeDa/sma50 - 1) * 100
atrMultipleFromeSma  = percentGainFromSMA / atrpercent
// Here we will use another variable which does the same calculation as above but with the high of the candle instead of the close.
// This way, when the stocks is extended above an atr% multiple of 10 and is resold below this threshold, the dot on the screen remains.
percentGainFromSMAH  = (highDa/sma50 - 1) * 100
atrMultipleFromeSmaH = percentGainFromSMAH / atrpercent

// 3) Condition
bool cond = atrMultipleFromeSmaH >= thresold ? 1:0

// 4) Display
// The circle shape seems to big for me. I made that when the user selects the size it will choose the smallest size of the label or a char display.
// Shape Display
if(cond and ShapeOrChar == "normal")
    label.new(bar_index, high, yloc = yloc.abovebar, style=label.style_circle, size = size.tiny, color = dotCol)
// Char Display
plotchar(cond and ShapeOrChar == "tiny" ? close:na, char = "•", color = dotCol, size = size.small)


// 5) Display Table
tfDaily = timeframe.isdaily
table t = table.new(position.bottom_right, 2, 4, bgcolor=color.rgb(255,255,255,100))
if barstate.islast and timeframe.period != "W" and timeframe.period != "M" and table
    table.cell(t, 0, 0, "ATR% Multiple From MA  ", text_color=txt_col, text_size = tbl_size)
    table.cell(t, 1, 0, str.tostring(math.round(atrMultipleFromeSma, 2)), text_color=atrMultipleFromeSma>=thresold ? twt_ext:txt_col, text_size = tbl_size)
    table.cell(t, 0, 1, "% Gain From MA   ", text_color=txt_col, text_size = tbl_size)
    table.cell(t, 1, 1, str.tostring(math.round(percentGainFromSMA, 2)) + "%", text_color=txt_col, text_size = tbl_size)
    table.cell(t, 0, 2, "ATR %      ", text_color=txt_col, text_size = tbl_size)
    table.cell(t, 1, 2, str.tostring(math.round(atrpercent, 2), '0.00') + '%', text_color=txt_col, text_size = tbl_size)

Overview

A dot is plotted when the distance exceeds a chosen multiple, with ten as the default, and an optional info table shows the readings. Settings change the ATR length, moving average length, multiple, dot size and colours, and table colours and size. It is a screening aid for extended price moves, with no trade rules.

Details

Published by

Fred6725 on GitHub

Code credit

jeffsuntrading, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Volatility & bands, Mean reversion

Markets

Stocks

Timeframes

H4 and above

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
ATR Lengthint14atr_len
MA lengthint50len
Multiple ATR for detectionint10thresold
Size of the DotstringtinyShapeOrChar
Dots Colorcolorcolor.yellowdotCol
Display Info Tablebooltruetable
Table Text Colorcolorcolor.orangetxt_col
Extended Text Colorcolorcolor.redtwt_ext
Table Sizestringsize.normaltbl_size
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 trade entry and exit signals on the price chart by combining Bollinger Bands with optional filter conditions. It calculates standard Bollinger Bands along with RSI, Aroon, and moving average filters. Reversal signals trigger when price bre

Indicator v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner IND [Alorse]

TylerG FVG BB Reversal

by TradersPost
218 stars

This indicator identifies mean-reversion setups by combining Bollinger Bands with Fair Value Gaps (FVGs). It tracks FVGs that print outside the upper or lower Bollinger Bands and counts them toward an alert threshold. Signals trigger upon gap mitigation (by to

Indicator v6 SMC / ICT / price actionVolatility & bands
Updated 3 months ago · None stated GitHub repository of TylerG FVG BB Reversal
147 stars

This indicator combines Bollinger Bands, RSI, Stochastic RSI, and volume spike detection to identify mean-reversion conditions during range-bound market regimes. It calculates Bollinger Band width to identify low-volatility states and triggers buy or sell sign

Indicator v5 Oscillators & momentumVolatility & bands
Updated 6 weeks ago · MIT GitHub repository of BTC Dec 2025 — Range + Gamma Flush

Bollinger Bands

by be-thomas
65 stars

This indicator plots standard Bollinger Bands directly on the price chart using hardcoded settings of a 5-period length and a 4 standard deviation multiplier. It displays the middle basis line in blue, the upper and lower outer bands in green, and fills the ch

Indicator v4 Volatility & bandsMean reversion
Updated 5 days ago · GPL-3.0 GitHub repository of Bollinger Bands
55 stars

This Pine Script indicator overlays institutional liquidity levels on the price chart. It identifies order block levels using pivot highs and lows, then draws mean reversion lines from the 20 and 50 period simple moving averages, a volatility range midpoint pr

Indicator v6 Support & resistanceSMC / ICT / price action Repaints
Updated 6 months ago · Apache-2.0 GitHub repository of AAPL Institutional Liquidity Grid

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