Indicator · Pine Script v6 · Own pane

Grid Bot [Grid Range Plugin] Two Moving Averages

by cullyk· code credited to Copyright

This indicator calculates grid range boundaries for the Grid Bot system using two moving averages.

View on GitHub

Repaints

GitHub stars2on the repository
Pine versionv6current
Lines of code88
Settings16inputs
LicenceMIT
Last update8 months ago25 Feb 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

88 lines of Pine Script v6 from plugins/Grid Bot [Grid range plugin] Two Moving Avarages [psyll].pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

Grid Bot [Grid range plugin] Two Moving Avarages [psyll].pine
//@version=6
// Author: Psyll.com
// Email: info@psyll.com
// Website: https://psyll.com
// Copyright: Copyright © 2025 psyll.com. All rights reserved.
indicator('Grid Bot [Grid range plugin] Two Moving Avarages [psyll]', overlay = false)
ma(ma_type, ma_source, ma_length) =>
    float result = 0
    if ma_type == 'EMA'
        result := ta.ema(ma_source, ma_length)
        result
    if ma_type == 'SMA'
        result := ta.sma(ma_source, ma_length)
        result
    if ma_type == 'WMA'
        result := ta.wma(ma_source, ma_length)
        result
    if ma_type == 'HMA'
        result := ta.hma(ma_source, ma_length)
        result
    if ma_type == 'RMA'
        result := ta.rma(ma_source, ma_length)
        result
    if ma_type == 'VWMA'
        result := ta.vwma(ma_source, ma_length)
        result
    if ma_type == 'DEMA'
        result := 2 * ta.ema(ma_source, ma_length) - ta.ema(ta.ema(ma_source, ma_length), ma_length)
        result
    if ma_type == 'TEMA'
        result := 3 * (ta.ema(ma_source, ma_length) - ta.ema(ta.ema(ma_source, ma_length), ma_length)) + ta.ema(ta.ema(ta.ema(ma_source, ma_length), ma_length), ma_length)
        result
    if ma_type == 'ZLEMA'
        result := ta.ema(ma_source + ma_source - ma_source[(ma_length - 1) / 2], ma_length)
        result
    result
decimal_places = 0
tick_size = syminfo.mintick
while tick_size < 1
    tick_size := tick_size * 10
    decimal_places := decimal_places + 1
    decimal_places
settings_group = 'Settings #################################################'
ma_type = input.string('SMA', 'Type', options = ['SMA', 'EMA', 'WMA', 'HMA', 'RMA', 'VWMA', 'DEMA', 'TEMA', 'ZLEMA'], group = settings_group, display = display.none)
fastLength = input(10, title = 'Fast EMA Length', group = settings_group, display = display.none)
slowLength = input(20, title = 'Slow EMA Length', group = settings_group, display = display.none)
source = input.source(defval = close, title = 'Source', group = settings_group, display = display.none)
deviations = input(2.0, title = 'Number of Deviations', group = settings_group, display = display.none)
offset = input.float(1, 'Offset', group = settings_group, display = display.none)
width_min = input.float(0, 'Min width', group = settings_group, display = display.none)
width_max = input.float(99999, 'Max width', group = settings_group, display = display.none)
width_min_half = width_min / 2
width_max_half = width_max / 2
tf_group = 'Timeframe ###############################################'
tf_confirmation_wait = input.bool(defval = true, title = 'Wait for confirm', group = tf_group, inline = tf_group, display = display.none)
tf_no_repaint_security = input.bool(defval = true, title = 'No repaint', group = tf_group, inline = tf_group, display = display.none)
tf_barmerge_lookahead = input.bool(defval = false, title = 'Lookahead', group = tf_group, inline = tf_group, display = display.none)
tf_barmerge_gaps = input.bool(defval = false, title = 'Gaps', group = tf_group, inline = tf_group, display = display.none)
tf_type = input.string(title = 'Type', options = ['Static', 'Custom'], defval = 'Static', group = tf_group, display = display.none)
tf_static = input.timeframe(defval = '', title = 'Static', group = tf_group, display = display.none)
tf_custom = str.tostring(input.int(1, 'Custom', group = tf_group, display = display.none))
tf_type_value = switch tf_type
    'Static' => tf_static
    'Custom' => tf_custom
tf_security(source) =>
    request.security(syminfo.tickerid, tf_type_value, tf_no_repaint_security ? source[barstate.isrealtime ? 1 : 0] : source, gaps = tf_barmerge_gaps ? barmerge.gaps_on : barmerge.gaps_off, lookahead = tf_barmerge_lookahead ? barmerge.lookahead_on : barmerge.lookahead_off)[tf_no_repaint_security ? barstate.isrealtime ? 0 : 1 : 0]
display_group = 'Display ##################################################'
price_color = input.color(color.black, 'Candles color', display = display.none, group = display_group)
// Plot pricecandle
plotcandle(open, high, low, close, color = price_color, bordercolor = price_color, wickcolor = price_color, display = display.pane)
fastEMA = tf_security(ma(ma_type, source, fastLength))
slowEMA = tf_security(ma(ma_type, source, slowLength))
combinedEMA = (fastEMA + slowEMA) / 2
priceDeviation = deviations * tf_security(ta.stdev(combinedEMA, slowLength))
grid_high = combinedEMA + priceDeviation + offset
grid_low = combinedEMA - priceDeviation - offset
grid_middle = (grid_high + grid_low) / 2
if grid_high - grid_low < width_min
    grid_high := grid_middle + width_min_half
    grid_low := grid_middle - width_min_half
    grid_low
if grid_high - grid_low > width_max
    grid_high := grid_middle - width_max_half
    grid_low := grid_middle + width_max_half
    grid_low
plot(grid_high, 'High', color.green, display = display.all)
plot(grid_middle, 'Middle', color.silver, display = display.pane)
plot(grid_low, 'Low', color.red, display = display.all)

Overview

Grid Bot [Grid Range Plugin] Two Moving Averages supports nine different moving average types, including SMA, EMA, HMA, DEMA, TEMA, and ZLEMA, across customizable fast and slow periods. Users can configure deviation multipliers, minimum and maximum width boundaries, and offsets. Plotted in a separate pane, it provides dynamic boundary inputs for grid trading strategies. It also features multi-timeframe functionality with configurable security options for confirmation and repainting controls.

Details

Published by

cullyk on GitHub

Code credit

Copyright, as written in the script's header

Draws

Separate pane below the chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Settings

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

SettingTypeDefaultVariable
TypestringSMAma_type
Fast EMA Lengthint10fastLength
Slow EMA Lengthint20slowLength
Sourcesourceclosesource
Number of Deviationsfloat2.0deviations
Offsetfloat1offset
Min widthfloat0width_min
Max widthfloat99999width_max
Wait for confirmbooltruetf_confirmation_wait
No repaintbooltruetf_no_repaint_security
Lookaheadboolfalsetf_barmerge_lookahead
Gapsboolfalsetf_barmerge_gaps
Show all 16 settings
SettingTypeDefaultVariable
TypestringStatictf_type
Statictimeframetf_static
Customint1Custom
Candles colorcolorcolor.blackprice_color
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

BTC Multiples

by readysetcryptocodes
43 stars

BTC Multiples calculates and displays Bitcoin macro valuation metrics in a separate pane, including the Mayer Multiple, Stock-to-Flow Multiple, Difficulty Multiple, and Puell Multiple. Each valuation multiple features configurable overvalued and undervalued th

Indicator v4 Moving averagesSupport & resistance
Updated 2 years ago · None stated GitHub repository of BTC Multiples

MACD Breakout

by jerryinyang
5 stars

MACD Breakout builds a higher-timeframe MACD from preset fast and slow lengths using SMA or EMA, and marks support and resistance zones from histogram sensitivity. Optional filters require zero-line agreement, higher-timeframe direction, and linear-regression

Indicator v4 Oscillators & momentumMoving averages
Updated 2 years ago · None stated GitHub repository of MACD Breakout

Noob's Indicators

by InNoobWeTrust
4 stars

This Pine Script indicator plots multiple exponential moving averages in a separate pane for technical analysis. It calculates Elliott wave EMAs using Fibonacci wave counts of 34 and 89, plus 200-session and golden ratio lines. Additional Pythagorean cloud lev

Indicator v5 Moving averagesSupport & resistance
Updated 2 days ago · None stated GitHub repository of Noob's Indicators

Cipher B

by diehardyearone
3 stars

Cipher B is a multi-indicator plotting WaveTrend oscillator lines and signals alongside Stochastic RSI, MFI area with color bars, and buy sell marks. It draws all elements in a separate pane. WaveTrend calculates using SMMA and EMA on source like ohlc4 with ad

Indicator v6 Oscillators & momentumMoving averages
Updated 1 year ago · None stated GitHub repository of Cipher B
3 stars

This indicator demonstrates debugging visualization patterns for Pine Script. It plots value tracking with mean, min, and max reference lines, condition markers using shapes and arrows, historical comparisons with standard deviation bands, multi-series overlay

Indicator v5 Moving averagesVolatility & bands
Updated 7 months ago · None stated GitHub repository of Debugging Visualization Patterns

This indicator renders Ichimoku cloud components consisting of conversion line, base line, leading span A and leading span B. It tracks Tenkan-Kijun crosses and assigns a numeric score to each based on whether the cross occurs below, inside or above the Kumo c

Indicator v5 Moving averagesSupport & resistance
Updated 5 months ago · None stated GitHub repository of Ichimoku Cloud Weight Original

More Moving averages scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers