Indicator · Pine Script v5 · On the chart

Grid Bot Simulator

by regalouisei· code credited to mvs1231 || xxattaxx || DisDev

Calculates evenly spaced grid levels across a user-defined price range bounded by upper and lower limits.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code131
Settings9inputs
LicenceNone statedfile: MPL-2.0
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

131 lines of Pine Script v5 from pinescript/editors_picks/grid-bot-simulator.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

grid-bot-simulator.pine
//@version=5

//------------------------------------------------------------------------------------------------<>
//      This source code is subject to the terms of the Mozilla Public License 2.0 
//      https://mozilla.org/MPL/2.0/ 
//      ©mvs1231 || xxattaxx || DisDev
//      Updated 01/17/2022: Pinescript v5: 
//          Price Selectors--Converted color transparences to prevent deprecation warning
indicator('Grid Bot Simulator', shorttitle='GridBotDir', overlay=true)
//-----<Inputs>-----------------------------------------------------------------------------------<> 
UpperLimit = input.price(50000.0, 'Upper Limit', confirm=true)
LowerLimit = input.price(43000.0, 'Lower Limit', confirm=true)
No_Grids = input(10, 'Number of Grids(10)') + 1
Dir = input.string('neutral', 'Market Direction', options=['up', 'neutral', 'down'])
SS = input.string('small', 'Signal Size', options=['small', 'large'])
ShowGrids = input(true, 'Show Grids')
HighLight = input(true, 'Highlight Trade Zones')
ShowCurrent = input(false, 'Show Only Current Grids')
Extremes = input(true, 'High/Low for signals')
//-----<Variables>--------------------------------------------------------------------------------<>
LastSignal = 0
LastSignal_Index = 0
LastSignal_Time = time
SignalLine = 0.0
CurrentGrid = 0.0
Buy = false
Sell = false
Direction = Dir == 'up' ? 1 : Dir == 'down' ? -1 : 0
//-----<Colors>-----------------------------------------------------------------------------------<>
RedGrid = color.new(color.red, 50)
GreenGrid = color.new(color.green, 40)
Crimson = #DC143C
LimeGreen = #32CD32
//-----<Calculate Grids>--------------------------------------------------------------------------<>
GridRange = UpperLimit - LowerLimit
GridInterval = GridRange / (No_Grids - 1)
//-----<Grid Array>-------------------------------------------------------------------------------<>
a_grid = array.new_float(No_Grids)
for x = 0 to No_Grids - 1 by 1
    array.set(a_grid, x, LowerLimit + GridInterval * x)
//-----<Get Array Function>-----------------------------------------------------------------------<>
Get_Array_Values(ArrayName, index) =>
    value = array.get(ArrayName, index)
    value
//-----<Calculate Signals>------------------------------------------------------------------------<>
Get_BuyLine_Index() =>
    Index = 0
    BuyValue = 0.0
    for x = 0 to No_Grids - 1 by 1
        BuyValue := LowerLimit + GridInterval * x
        if Extremes
            Index := high[1] > BuyValue and low <= BuyValue ? x : Index
            Index
        else
            Index := close[1] > BuyValue and close <= BuyValue ? x : Index
            Index
Get_SellLine_Index() =>
    Index = 0
    SellValue = 0.0
    for x = 0 to No_Grids - 1 by 1
        SellValue := LowerLimit + GridInterval * x
        if Extremes
            Index := low[1] < SellValue and high >= SellValue ? x : Index
            Index
        else
            Index := close[1] < SellValue and close >= SellValue ? x : Index
            Index
BuyLine_Index = Get_BuyLine_Index()
SellLine_Index = Get_SellLine_Index()
//-----<Signals>----------------------------------------------------------------------------------<>
Buy := BuyLine_Index > 0 ? true : Buy
Sell := SellLine_Index > 0 ? true : Sell
//No repeat trades at current level                                                                                     
if Extremes
    Buy := low >= SignalLine[1] - GridInterval ? false : Buy
    Sell := high <= SignalLine[1] + GridInterval ? false : Sell
    Sell
else
    Buy := close >= SignalLine[1] - GridInterval ? false : Buy
    Sell := close <= SignalLine[1] + GridInterval ? false : Sell
    Sell
//No trades outside of grid limits
Buy := close >= UpperLimit ? false : Buy
Buy := close < LowerLimit ? false : Buy
Sell := close <= LowerLimit ? false : Sell
Sell := close > UpperLimit ? false : Sell
//Direction Filter (skip one signal if against market direction)
Buy := Direction == -1 and low >= SignalLine[1] - GridInterval * 2 ? false : Buy
Sell := Direction == 1 and high <= SignalLine[1] + GridInterval * 2 ? false : Sell
//-----<Trackers>---------------------------------------------------------------------------------<>
LastSignal := Buy ? 1 : Sell ? -1 : LastSignal[1]
LastSignal_Index := Buy ? BuyLine_Index : Sell ? SellLine_Index : LastSignal_Index[1]
LastSignal_Time := Buy or Sell ? time : LastSignal_Time[1]
SignalLine := LowerLimit + GridInterval * LastSignal_Index
//-----<Plot Grids>-------------------------------------------------------------------------------<>
for i = 1 to No_Grids - 1 by 1
    Array_Value = Get_Array_Values(a_grid, i)
    ClosestGrid = Array_Value - close
    color linecolor = ClosestGrid > 0 ? RedGrid : ClosestGrid < 0 ? GreenGrid : na
    linecolor := i == LastSignal_Index ? na : linecolor
    if ShowGrids
        if ShowCurrent
            LineAbove = line.new(x1=LastSignal_Time, y1=SignalLine + GridInterval, x2=time + 1000000, y2=SignalLine + GridInterval, color=color.red, width=1, extend=extend.left, xloc=xloc.bar_time)
            LineBelow = line.new(x1=LastSignal_Time, y1=SignalLine - GridInterval, x2=time + 1000000, y2=SignalLine - GridInterval, color=color.green, width=1, extend=extend.left, xloc=xloc.bar_time)
            LineBelow
        else
            color colCurrent = LastSignal == 1 ? color.new(color.green, 95) : color.new(color.red, 95)
            GridLines = line.new(x1=time, y1=Array_Value, x2=time[1], y2=Array_Value, color=linecolor, width=1, extend=extend.right, xloc=xloc.bar_time)
            //draw line before latest signal
            CurrentLine = line.new(x1=LastSignal_Time, y1=SignalLine, x2=LastSignal_Time - 100000, y2=SignalLine, color=colCurrent, width=1, extend=extend.right, xloc=xloc.bar_time)
            CurrentLine
UL = ShowGrids and not ShowCurrent
plot(UL ? UpperLimit : na, color=close >= UpperLimit ? color.green : color.red, linewidth=3)
plot(UL ? LowerLimit : na, color=close <= LowerLimit ? color.red : color.green, linewidth=3)
//Lines One Above & One Below
LineAbove = SignalLine == UpperLimit ? SignalLine : SignalLine + GridInterval
LineBelow = SignalLine == LowerLimit ? SignalLine : SignalLine - GridInterval
a = plot(LineAbove, color=color.new(color.red, 100), style=plot.style_circles)
b = plot(LineBelow, color=color.new(color.green, 100), style=plot.style_circles)
boxColor = LastSignal == -1 ? color.new(color.green, 90) : color.new(color.red, 90)
boxColor := HighLight ? boxColor : na
fill(a, b, color=color.new(boxColor, 90))
//-----<Plot Signals>-----------------------------------------------------------------------------<>
plotchar(Buy and SS == 'small', 'Buy', color=color.new(LimeGreen, 0), size=size.tiny, location=location.belowbar, char='▲')
plotchar(Sell and SS == 'small', 'Sell', color=color.new(Crimson, 0), size=size.tiny, location=location.abovebar, char='▼')
plotchar(Buy and SS == 'large', 'Buy', color=color.new(LimeGreen, 0), size=size.small, location=location.belowbar, char='▲')
plotchar(Sell and SS == 'large', 'Sell', color=color.new(Crimson, 0), size=size.small, location=location.abovebar, char='▼')
//-----<Alerts>-----------------------------------------------------------------------------------<>
alertcondition(condition=Buy, title='buy', message='buy')
alertcondition(condition=Sell, title='sell', message='sell')
//------------------------------------------------------------------m-i-s-s--y-o-u-,-d-a-d--------<>

Overview

Grid Bot Simulator triggers simulated buy signals when price drops across a grid level and sell signals when price crosses upward through a level, evaluated via bar extremes or closing prices. User inputs adjust the price boundary, number of grid divisions, directional market bias, and chart appearance options. Plots grid lines, highlighted trade zones, and signal markers directly on the price chart.

Details

Published by

regalouisei on GitHub

Code credit

mvs1231 || xxattaxx || DisDev, as written in the script's header

Draws

On the price chart

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
Upper Limitprice50000.0UpperLimit
Lower Limitprice43000.0LowerLimit
Number of Grids(10)int10No_Grids
Market DirectionstringneutralDir
Signal SizestringsmallSS
Show GridsbooltrueShowGrids
Highlight Trade ZonesbooltrueHighLight
Show Only Current GridsboolfalseShowCurrent
High/Low for signalsbooltrueExtremes
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

257 stars

This indicator plots auto trade signals for E-mini S&P 500 futures on the price chart. It computes an EMA200 filter along with day ETH RTH session levels and percentage-based entry zones. Signals trigger CALL or PUT cases when price crosses defined thresholds

Indicator v6 TrendSupport & resistance
Updated 7 weeks ago · None stated GitHub repository of Auto Trade Futures ES
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
9 stars

This indicator plots an anchored MIDAS support and resistance curve from launch-anchored volume-weighted price on the price chart. It adds two configurable volume-weighted standard-deviation, ATR, or hybrid bands and a topfinder or bottomfinder accelerated exh

Indicator v6 Mean reversionSupport & resistance Repaints
Updated 3 days ago · MIT GitHub repository of MIDAS 2.0 [WavesUnchained]

VWAP Trader NXi

by eddiebelaval
7 stars

VWAP Trader NXi calculates a daily session-anchored Volume Weighted Average Price along with two custom standard deviation bands on the main price chart. It plots the core VWAP, Value Area bands, outer extension zones with background shading, and the previous

Indicator v5 VolumeVolatility & bands
Updated 3 months ago · None stated GitHub repository of VWAP Trader NXi
5 stars

Calculates daily classical pivot points from the previous day's high, low, and close to identify intraday reversal setups within a defined trading session. Long signals fire when price comes within a configurable tick proximity to S1 and prints a bullish recla

Indicator v5 Support & resistanceMean reversion
Updated 5 months ago · Custom licence GitHub repository of Path C — Pivot-Point Bounce (Demo)
5 stars

This indicator implements Tom DeMark's TD Sequential methodology on the price chart to detect trend exhaustion and reversal zones. It counts the Setup phase of nine consecutive bars comparing closes to four bars prior, tracks setup perfection, and advances int

Indicator v6 TrendMean reversion
Updated 1 year ago · None stated GitHub repository of TD Sequential - Official DeMark

More Support & resistance 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