Indicator · Pine Script v5 · On the chart

Median

by TWODS-CAPITAL

The Median indicator calculates the median of a selected source series such as the high-low average over a user-defined length and plots it as a red line on the price chart.

View on GitHub

GitHub stars37on the repository
Pine versionv5runs as is
Lines of code19
Settings4inputs
LicenceMIT
Last update3 years ago10 Feb 2023

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

19 lines of Pine Script v5 from Technical-Indicators/Technical Indicators are Here🤩/Median.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

Median.pine
//@version=5
indicator(title="Median", overlay=true, timeframe="", timeframe_gaps=true)
source = input(hl2, title="Median Source")
length = input(3, title="Median Length")
atr_length = input(14, title="ATR Length")
atr_mult = input(2, title="ATR Multiplier")

median = ta.percentile_nearest_rank(source, length, 50)
median_plot = plot(median, color=color.red, linewidth=3, title="Median")

atr_ = atr_mult * ta.atr(atr_length)

plot(median + atr_, color=color.lime, title="Upper Band")
plot(median - atr_, color=color.fuchsia, title="Lower Band")

median_ema = ta.ema(median, length)
ema_plot = plot(median_ema, color=color.blue, title="Median EMA")

fill(median_plot, ema_plot, color=median > median_ema ? color.new(color.lime, 10) : color.new(color.fuchsia, 10))

Overview

Median draws an EMA of the median as a blue line and fills the space between them, changing fill color based on which line is higher. Upper and lower bands are plotted around the median using ATR scaled by a multiplier. Inputs let users adjust the source, length, ATR length, and multiplier. The script draws all elements directly on the price chart.

Details

Published by

TWODS-CAPITAL on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Moving averages, Volatility & bands, Support & resistance

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
Median Sourcesourcehl2source
Median Lengthint3length
ATR Lengthint14atr_length
ATR Multiplierint2atr_mult
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

Snag - VWAP

by dearvn
257 stars

This indicator plots a custom Anchored Volume-Weighted Average Price (VWAP) directly on the price chart along with optional standard deviation bands. Users can anchor the VWAP to standard time periods like sessions, weeks, or months, or to corporate events suc

Indicator v5 Moving averagesVolatility & bands Repaints
Updated 6 weeks ago · None stated GitHub repository of Snag - VWAP

MA Envelope (MAE)

by mihakralj
99 stars

The MA Envelope indicator calculates upper and lower channel bands shifted by a user-defined percentage around a baseline moving average. It supports Simple Moving Average, Exponential Moving Average, and Weighted Moving Average calculation types. The script p

Indicator v6 Moving averagesSupport & resistance
Updated 4 weeks ago · Apache-2.0 GitHub repository of MA Envelope (MAE)

Moon Dev GEX Walls & Trap

by moondevonyt
92 stars

This indicator estimates gamma exposure levels and intraday context for index instruments like SPY and ES. It calculates VWAP with standard deviation bands as a gamma flip proxy, highlighting market regimes through background colors. It plots prior day high, l

Indicator v5 Support & resistanceSessions & time
Updated 8 weeks ago · Custom licence GitHub repository of Moon Dev GEX Walls & Trap
20 stars

This indicator calculates a base moving average (EMA, SMA, WMA, or HMA) and projects multiple symmetrical envelope bands around it directly on the price chart. Users can adjust the length, source, moving average type, and initial envelope multiplier. Additiona

Indicator v5 Moving averagesVolatility & bands
Updated 1 year ago · None stated GitHub repository of Multiple Moving Average Envelope

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