[GTH] Revenue
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © gehteha

//@version=5
indicator(title="[GTH] Revenue", precision=0)
r1 = request.financial(syminfo.tickerid, "TOTAL_REVENUE", "FQ")
r2 = request.financial(syminfo.tickerid, "SALES_ESTIMATES", "FQ")


col_p = input.color(title="Postive Surprise", defval=color.green)
col_n = input.color(title="Negative Surprise", defval=color.red)
h_off = input.int(title="Horizontal Offset", defval=0)

col = r1 > r2 ? col_p : col_n

plotcandle(r1,r1,r2,r2, title="Revenue", color = col, wickcolor=#00000000, bordercolor=col, editable=false)
plot(r1, title="Reported Revenue", color=color.black, linewidth=3)
//plot(r3, title="Total Revenue, last Twelve Trailing Months", color=color.blue, linewidth=3) 

float diff = r1-r1[1]
perc = r1 != r1[1] ? (r1/r1[1])-1 : na

bool plot_perc = r1 != r1[1] ? true : false

if plot_perc
    label.new(bar_index + h_off , r1, str.tostring(str.format("{0,number,percent}", math.abs(perc))), color = diff>0 ? col_p : col_n, style = diff>0 ? label.style_label_down : label.style_label_up, textcolor=color.white)