3commas GRID bot Visualisation
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © @Crypto_BitCoinTrader based @ChrisKaye indicator

//@version=5
indicator(title="3commas GRID bot Visualisation", shorttitle="Grid bot", overlay=true, max_lines_count=100)

float HighPrice=input.float(50000.00, "Upper Price")
float LowPrice=input.float(40000.00, "Lower Price")
int n=input.int(10, "Number of grids (max 100)", minval=2, maxval=100)
n -= 1
step=(HighPrice-LowPrice)/n
maxprofitprc = (step*100)/HighPrice
minprofitprc = (step*100)/LowPrice

UpColor = color.green
DownColor = color.red

var downline = line.new(bar_index, LowPrice, bar_index, LowPrice, extend=extend.right, color = DownColor, width=4)
var upline = line.new(bar_index, HighPrice, bar_index, HighPrice, extend=extend.right, color = UpColor, width=4)


var GridTable = table.new(position = position.top_right, columns = 4, rows = 2, bgcolor = color.white, border_width = 1)
curr = syminfo.currency
table.set_border_color(table_id = GridTable, border_color=color.black)
table.cell(table_id = GridTable, column = 0, row = 0, text = "Qty lines")
table.cell(table_id = GridTable, column = 0, row = 1, text = str.tostring(n+1))
table.cell(table_id = GridTable, column = 1, row = 0, text = "Qty cells")
table.cell(table_id = GridTable, column = 1, row = 1, text = str.tostring(n))
table.cell(table_id = GridTable, column = 2, row = 0, text = "Step grid")
table.cell(table_id = GridTable, column = 2, row = 1, text = str.tostring(step, "#.######## ") + curr)
table.cell(table_id = GridTable, column = 3, row = 0, text = "Profit")
table.cell(table_id = GridTable, column = 3, row = 1, text = str.tostring(maxprofitprc, "#.####") + "% - " + str.tostring(minprofitprc, "#.####") + "%")

line hiLine = na
label metka = na

if barstate.isrealtime
    for i = 1 to n+1
        if LowPrice<close
            hiLine := line.new(bar_index[1], LowPrice, bar_index, LowPrice, extend=extend.both, color=DownColor)
        else 
            hiLine := line.new(bar_index[1], LowPrice, bar_index, LowPrice, extend=extend.both, color=UpColor)
        LowPrice += step