Price Percent Change (O/C)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LedzZz

//@version=5
indicator("Percent Change (LedzZz)")

// ====================================================================================================
// ----------------------------------------------------------------------------------------------------
// INPUT-CHOICE => Method of Percent to calculate
var Method_A = "Close Vs Open"
var Method_B = "High vs Low"
var Method_C = "Last Close vs Curent Open"
method = input.string( title="type", defval=Method_A, options=[Method_A,Method_B,Method_C])

// declaring the proper final number for the selected Method, f=final, i=initial.
// for example for option C: final price => "open",  initial price => "yesterdays close" 
price_f = (Method_B == method) ? high : ((Method_C == method) ? open : close )
price_i = (Method_B == method) ? low  : ((Method_C == method) ? close[1] : open )

// addition factor required for Method_B, due to high and low doesn't indicate if its a green day or red day. 
hi_lo_factor = (Method_B != method)?1:(close>open)?1:-1

// Percent change based on the selected method.
perChange_MOD_A = (price_f-price_i)/price_i* 100 *hi_lo_factor 

// INPUT Minimum Percent TO SHOW
min_Percent = input.float(title="Min Percent Move (%)",  minval = 0, maxval = 100, defval = 0)
to_show_factor = math.abs(perChange_MOD_A) > min_Percent? 1 : 0

// Applying to show factor to percentage
perChange_MOD_B = perChange_MOD_A * to_show_factor

// Bar Color
plotStyle = plot.style_columns
plotColor = ( perChange_MOD_B > 0 ? color.green : color.red ) 

plot(perChange_MOD_B,style=plotStyle,color= plotColor)  

// horizontal refrence lines.
horLineColor = color.new(color.olive,1) 
plot(4,style=plot.style_line,color= horLineColor) 
plot(2,style=plot.style_line,color= horLineColor)
plot(1,style=plot.style_line,color= horLineColor)
  
plot(-1,style=plot.style_line,color= horLineColor) 
plot(-2,style=plot.style_line,color= horLineColor) 
plot(-4,style=plot.style_line,color= horLineColor) 
