% Price change (by OP)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © OrganicPunch

//@version=5
indicator("% Price Change [OrganicPunch]", "% Price Change [OP]")

// To visually evaluate the % change in price between two candles

pc_ema_lenght = input.int(7, title="Price Change EMA", minval=1)
pc_display_toggle = input.bool(false, "Two-side display")
pc_price_increase = (close - close[1]) / close[1] * 100
pc_price_decrease = (close[1] - close) / close * 100
pc_price_up = close > close[1] 
pc_price_change = pc_price_up ? pc_price_increase : pc_price_decrease
pc_price_change2 = pc_price_up ? pc_price_increase : -pc_price_decrease
pc_price_toggle = pc_display_toggle ? pc_price_change2 : pc_price_change
pc_color = pc_price_up ? color(color.green) : color(color.red)
pc_ema = ta.ema(pc_price_toggle, pc_ema_lenght)

plot(pc_price_toggle, "Price Change 1", pc_color, linewidth=2, style=plot.style_circles) 
plot(pc_price_toggle, "Price Change 2", pc_color, linewidth=1, style=plot.style_histogram)    
plot(pc_ema, "Price Change EMA", color.yellow)
   
hline(0, "Zero line", color(color.gray), linestyle=hline.style_solid)

