Code Library / Grid Trading

Pine Script Grid Level Visualizer

Visualize grid trading levels on TradingView charts.

Language: Pine Script · Category: Grid Trading · Tags: grid, Pine Script, visualization, levels, TradingView

Source code

//@version=5
indicator("Grid Levels", overlay=true)
gridPct=input.float(0.5,"Grid %%"); levels=input.int(5,"Levels")
base=ta.sma(close,50); step=base*gridPct/100
for i=1 to levels
    line.new(bar_index-50,base+step*i,bar_index,base+step*i,color=color.red,style=line.style_dashed)
    line.new(bar_index-50,base-step*i,bar_index,base-step*i,color=color.green,style=line.style_dashed)
plot(base,"Base",color.yellow,2)

How to use this snippet

This is a building block, not a finished trading system. Paste it into your own Pine Script project, compile it, and test it on a demo account with your broker's real spreads before relying on it. You can convert it to MQL4 or MQL5 with the Pine Script converter.

Related snippets