Frog in Pan Indicator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jamiedubauskas

//@version=5
indicator(title = "Frog in Pan Indicator", shorttitle = "FIP Indicator", format = format.percent, precision = 4)

// input variable for the lookback
lookback = input.int(title = "Lookback Period", defval = 365, minval = 1, tooltip = "Lookback period for assesing how many days are positive and negative used for indicator")

// input variables to see what to show
show_pos = input.bool(title = "Show Positive Days Count?", defval = false)
show_neg = input.bool(title = "Show Negative Days Count?", defval = false)
show_fip = input.bool(title = "Show FIP Indicator?", defval = true)

// looping through the lookback and counting the number of positive days and negative days
num_pos = 0
num_neg = 0

for i = 0 to lookback
    if close[i] > open[i]
        num_pos += 1
    else if close[i] < open[i]
        num_neg += 1

// fip indicator
percent_pos = (num_pos / lookback) * 100
percent_neg = (num_neg / lookback) * 100
generic_momentum_sign = (close[1] >= close[lookback]) ? 1 : -1
fip = (generic_momentum_sign) * (percent_neg - percent_pos)

// showing variables for plotting
plot_pos = show_pos ? num_pos : na
plot_neg = show_neg ? num_neg : na
plot_fip = show_fip ? fip : na

// plotting indicator
plot(plot_pos, color = color.new(color.green,0))
plot(plot_neg, color = color.new(color.red,0))
plot(plot_fip, color = color.new(color.white,0))

// input variable to plot horizontal 0 line or not
show_hline = input.bool(title = "Show Horizontal 0-Line?", defval = true)
hline_val = show_hline ? 0 : na
hline(price = hline_val, title = "Zero Line", color = color.new(color.white, 50), linestyle = hline.style_dashed)


