Lines and Table for risk management
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TaTaTaCrypto

//@version=5

indicator(title="Lines for Take Profit and Stop Loss", overlay=true)

//Input options
leverage = input.int(1, "Leverage")
percent = input.float(0.5,'Stepsize (x Leverage)')

f1 = (100-(percent*1*leverage))/100
f2 = (100-(percent*2*leverage))/100
f3 = (100-(percent*3*leverage))/100
f4 = (100+(percent*1*leverage))/100
f5 = (100+(percent*2*leverage))/100
f6 = (100+(percent*3*leverage))/100

//horizontal lines -  empty line variables
var line l985 = na
var line l99 = na
var line l995 = na
var line l0 = na
var line l1005 = na
var line l101 = na
var line l1015 = na

table panel = table.new(position.top_right, 2, 8,frame_width=1, border_width=1, border_color=color.new(color.white, 100))
if barstate.islast
    l985 := line.new(x1=bar_index[1], y1=close*f3, x2=bar_index, y2=close*f3, width=1, extend=extend.both)
    l99 := line.new(x1=bar_index[1], y1=close*f2 , x2=bar_index, y2=close*f2, width=1, extend=extend.both)
    l995 := line.new(x1=bar_index[1], y1=close*f1, x2=bar_index, y2=close*f1, width=1, extend=extend.both)
    l0 := line.new(x1=bar_index[1], y1=close*1, x2=bar_index, y2=close*1, width=1, extend=extend.both)
    l1005 := line.new(x1=bar_index[1], y1=close*f4, x2=bar_index, y2=close*f4, width=1, extend=extend.both)
    l101 := line.new(x1=bar_index[1], y1=close*f5, x2=bar_index, y2=close*f5, width=1, extend=extend.both)  
    l1015 := line.new(x1=bar_index[1], y1=close*f6, x2=bar_index, y2=close*f6, width=1, extend=extend.both)
    line.set_color(id=l985,     color=color.gray)
    line.set_style(id=l985,     style=line.style_solid)
    line.set_color(id=l99,      color=color.gray)
    line.set_style(id=l99,      style=line.style_solid)
    line.set_color(id=l995,     color=color.gray)
    line.set_style(id=l995,     style=line.style_solid)
    line.set_color(id=l0,       color=color.gray)
    line.set_style(id=l0,       style=line.style_dashed)
    line.set_color(id=l1005,    color=color.gray)
    line.set_style(id=l1005,    style=line.style_solid)
    line.set_color(id=l101,     color=color.gray)
    line.set_style(id=l101,     style=line.style_solid)
    line.set_color(id=l1015,    color=color.gray)
    line.set_style(id=l1015,    style=line.style_solid)
    table.cell(panel, 0, 0, "Leverage X "+str.tostring(leverage), bgcolor =color.white)
    table.cell(panel, 0, 3, "+"+str.tostring(percent*1*leverage)+"%", bgcolor =color.white)
    table.cell(panel, 0, 2, "+"+str.tostring(percent*2*leverage)+"%", bgcolor = color.white)
    table.cell(panel, 0, 1, "+"+str.tostring(percent*3*leverage)+"%", bgcolor = color.white)
    table.cell(panel, 0, 4, "Price",  bgcolor = color.white)
    table.cell(panel, 0, 5, "-"+str.tostring(percent*leverage)+"%",  bgcolor = color.white)
    table.cell(panel, 0, 6, "-"+str.tostring(percent*2*leverage)+"%"  ,bgcolor = color.white)
    table.cell(panel, 0, 7, "-"+str.tostring(percent*3*leverage)+"%",  bgcolor = color.white)
    table.cell(panel, 1, 1, str.tostring(close*f6,'#.####'), bgcolor = #fcfcfc)
    table.cell(panel, 1, 2, str.tostring(close*f5,'#.####'), bgcolor = #fcfcfc)
    table.cell(panel, 1, 3, str.tostring(close*f4,'#.####'),  bgcolor = #fcfcfc)
    table.cell(panel, 1, 4, str.tostring(close,'#.####'),  bgcolor = #fcfcfc)
    table.cell(panel, 1, 5, str.tostring(close*f1,'#.####'),  bgcolor = #fcfcfc)
    table.cell(panel, 1, 6, str.tostring(close*f2,'#.####'),  bgcolor = #fcfcfc)
    table.cell(panel, 1, 7, str.tostring(close*f3,'#.####'),  bgcolor = #fcfcfc)
    table.merge_cells(panel,0,0,1,0) 


// end of script here