JS Bull/Bear Power
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © lizardojohnsonc

//@version=4
study("JS Bull/Bear Power", overlay = true, precision=0, max_labels_count= 10)




average_price = ema(close,2)
bear = (high - (open>close? open:close))
bull = ((open < close? open:close)-low)
barlenght = close > open ? close - open : open - close

sumbarlenght = sum(barlenght,60)
sumbull = ((sum(bear,60))/sumbarlenght)*100
sumbear = ((sum(bull,60))/sumbarlenght)*100


//bullPower =       ((high - average_price)/average_price)*1000
//bearPower =       ((low - average_price)/average_price)*1000


bullPower_converted = tostring(floor(sumbull))
bearPower_converted = tostring(floor(sumbear))

bull_label = label.new(x=bar_index, y=na, text=bullPower_converted, yloc=yloc.abovebar, textcolor=color.white, style=label.style_none, size=size.normal)
bear_label = label.new(x=bar_index, y=na, text=bearPower_converted, yloc=yloc.belowbar, textcolor=color.white, style=label.style_none, size=size.normal)
