Pip Value
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ashkanpower :)

//@version=5
indicator("Pip Value", overlay=true)

compact = input.bool(title="compact mode",defval=false)
pips = input.int(title="Pips",defval=10, minval=1)
lots = input.int(title="Micro Lots",defval=1, minval=1)
loss = input.float(title="Find Loss $",  defval=5, minval=1)
ratio = input.float(title="1:x", defval=2, minval=1, maxval=100)

cur = syminfo.currency
base = syminfo.basecurrency

baseusd = nz(request.security(base + "USD", timeframe.period, close, ignore_invalid_symbol=true), 1)

jpyFixer = base == "JPY" or cur == "JPY" ? 100 : 1


profit = math.round(pips * (0.1 * lots) / close * baseusd * jpyFixer, 2)

theLoss = 0.0
foundPips = 0

for p = 1 to 1000
    prof =  p * (0.1 * lots) / close * baseusd * jpyFixer
    if prof > theLoss and prof <= loss
        theLoss := prof
        foundPips := p

var lab = label.new(0 ,0, "")

var table riskTable = table.new(position.bottom_right , 1, 3, bgcolor = color.white, frame_width = 4, border_width = 0)
if barstate.islast
    
    str1 = ""
    str2 = ""
    
    str1 := str.tostring(profit) + "$ per " + str.tostring(pips) + " pip,s"
    str2 := "Use " + str.tostring(foundPips) + ":" + str.tostring(foundPips * ratio) + " pips for " + str.tostring(math.round(theLoss, 2)) + "$"
        
    table.cell(riskTable, 0, 0, str.tostring(lots / 100) + " lot,s", text_color = color.black, text_halign = text.align_left)
    table.cell(riskTable, 0, 1, str1, text_color = color.black, text_halign = text.align_left)
    table.cell(riskTable, 0, 2, str2, text_color = color.black, text_halign = text.align_left)

// if barstate.islast
//     label.delete(lab)
//     if compact == false
//         lab := label.new(bar_index + 30, low, , textcolor=color.black, style=label.style_label_center)
//     else
//         lab := label.new(bar_index + 30, low, str.tostring(profit) + "$   " + str.tostring(pips) + "p   " + str.tostring(lots / 100) + " l\n\n " + str.tostring(foundPips) + ":" + str.tostring(foundPips * ratio) + "   " + str.tostring(math.round(theLoss, 2)) + "$  R:R", textcolor=color.black, style=label.style_label_center)
//     label.set_color(lab, color.white)
    
    