Indicator · Pine Script v4 · On the chart

Bollinger Bands/MA Cross

by lehoa1806· code credited to xhoalee

This indicator overlays four simple moving averages and marks crosses between the short and basis averages on the price chart.

View on GitHub

GitHub stars4on the repository
Pine versionv4older, still runs
Lines of code45
Settings7inputs
LicenceGPL-3.0
Last update5 years ago23 Mar 2021

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

45 lines of Pine Script v4 from Bollinger_Bands-MA_Cross-Resistance_Support.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Bollinger_Bands-MA_Cross-Resistance_Support.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © xhoalee

//@version=4
study(shorttitle="BB/MA Cross", title="Bollinger Bands/MA Cross", overlay=true, resolution="")
shortLength = input(5, title="Short MA Length", minval=1)
baseLength = input(20, title="Bollinger Bands Length", minval=1)
longLength = input(100, title="Long MA Length", minval=1)
longerLength = input(200, title="\"Longer\" MA Length", minval=1)
src = input(close, title="Source")

// MA Cross
getMACross() =>
    shortLine = sma(src, shortLength)
    baseLine = sma(src, baseLength)
    longLine = sma(src, longLength)
    longerLine = sma(src, longerLength)
    [shortLine, baseLine, longLine, longerLine]
[shortLine, baseLine, longLine, longerLine] = getMACross()
plot(shortLine, title="Short", color = #228B22)
plot(baseLine, title="Basis", color = #0000FF)
plot(longLine, title="Long", color = #cc7a00)
plot(longerLine, title="Longer", color = #FF0000)
plot(cross(shortLine, baseLine) ? shortLine : na, style = plot.style_cross, linewidth = 4)


// Bollinger Bands
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
getBollingerBands(mult) =>
    basis = sma(src, baseLength)
    dev = mult * stdev(src, baseLength)
    upper = basis + dev
    lower = basis - dev
    [upper, lower]
[upper, lower] = getBollingerBands(mult)
p1 = plot(upper, "Upper", transp=90)
p2 = plot(lower, "Lower", transp=90)
fill(p1, p2, title = "Background", color=#A4A4A4, transp=50)

// Resistance, Support
lengthRS = input(title="Resistance/Support Length", defval=10, type=input.integer)
highRS = valuewhen(high >= highest(high, lengthRS), high, 0)
lowRS = valuewhen(low <= lowest(low, lengthRS), low, 0)
plot(title="Resistance", series=highRS ? highRS : na, color=highRS != highRS[1] ? na : color.olive, linewidth=2, transp=25, offset=0)
plot(title="Support", series=lowRS ? lowRS : na, color=lowRS != lowRS[1] ? na : color.maroon, linewidth=2, transp=25, offset=0)

Overview

Bollinger Bands/MA Cross also plots Bollinger Bands around the basis average using a standard-deviation multiplier and fills the band. Separate resistance and support lines mark the most recent highest high and lowest low over a chosen lookback, and those lines are hidden on the bar where the level changes. Lengths, source, band width, and the support-resistance lookback are adjustable. It does not generate trade entries or exits.

Details

Published by

lehoa1806 on GitHub

Code credit

xhoalee, as written in the script's header

Type

Indicator, Pine Script v4

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.

Topics

tradingview-pine-scriptstradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Short MA Lengthint5shortLength
Bollinger Bands Lengthint20baseLength
Long MA Lengthint100longLength
"Longer" MA Lengthint200longerLength
Sourcesourceclosesrc
StdDevfloat2.0mult
Resistance/Support Lengthint10lengthRS
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

Median

by TWODS-CAPITAL
37 stars

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. It draws an EMA of the median as a blue line and fills the space between them, changin

Indicator v5 Moving averagesVolatility & bands
Updated 3 years ago · MIT GitHub repository of Median
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