P/L panel
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © nandawithu


//@version=4
study("P/L panel", overlay=true)


price=input(0.00,title="Entry Price",tooltip="Input ENTRY PRICE of position",confirm=true)
quantity=input(0,title="Qty ", tooltip='Input the QUANTITY'+ '\n' +'for Long enter + value'+ '\n' +'for Short enter - value',confirm=true)
tableposition=input("bottom_left",title="Table position", options=["top_left", "top_center", "top_right", "middle_left", "middle_center", "middle_right", "bottom_left", "bottom_center", "bottom_right"])


PNL= (close-price)*quantity

tabpos= tableposition== "top_left"? position.top_left:tableposition== "top_center"?position.top_center : tableposition== "top_right"? position.top_right : tableposition== "middle_left"? position.middle_left : tableposition== "middle_center"? position.middle_center : tableposition== "middle_right"? position.middle_right : tableposition== "bottom_left"? position.bottom_left : tableposition== "bottom_center"? position.bottom_center: tableposition== "bottom_right"? position.bottom_right: position.top_right

var testTable = table.new(position = tabpos, columns = 4, rows = 3, bgcolor = color.yellow,frame_color=color.black,border_color=color.black, border_width = 1, frame_width=1)
if barstate.islast
    table.cell(table_id = testTable, column = 0, row = 0, text = quantity>0?"Long":"Short")
    table.cell(table_id = testTable, column = 1, row = 0, text = 'Price: '+ tostring(round(price,2)) + '\n' + 'Qty: ' + tostring(abs(quantity)))
    
    table.cell(table_id = testTable, column = 0, row = 1, text = "Points")
    table.cell(table_id = testTable, column = 1, row = 1, text = (quantity>0 or quantity<0)?tostring(abs(round((close-price),2))):"0")
    
    table.cell(table_id = testTable, column = 0, row = 2, text = "P/L")
    table.cell(table_id = testTable, column = 1, row = 2, text = tostring(round(PNL,2)),bgcolor=PNL>0?color.green:PNL<0?color.red:na)



