HILOCLOP Analysis
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dt440032

//@version=5
indicator("HILOCLOP Analysis", overlay = false)

//Inputs-User Controllable
len = input(100, "Sample Length")
raw = input(true, 'Raw Up', tooltip="Shows the # of Higher 'High, Low, Open, Close' of the Sample")
raw1 = input(true, 'Raw Dn', tooltip="Shows the # of Lower 'High, Low, Open, Close' of the Sample")
hiclop = input(true, 'HICLOP', tooltip="HICLOP Analysis Color Scheme, Uncheck for Trend Analysis")
analysis = input(false, 'Analysis Up V Dn', tooltip="Shows the # of Occurences of where a Higher or Lower 'High, Low, Open, Close' all occured at once in the Sample")
analysis1 = input(false, 'Analysis High V Low', tooltip="Shows the # of Occurences of where there were more Higher Highs then Higher Lows in the Sample and Vice Versa")
analysis2 = input(false, 'Analysis Open V Close', tooltip="Shows the # of Occurences of where there were more Higher Closes then Higher Opens in the Sample and Vice Versa")

//Root Calculations
high1 = high[1]
low1 = low[1]
open1 = open[1]
close1 = close[1]

uptrend = high1 < high
uptrend1 = low1 < low
uptrend2 = open1 < open
uptrend3 = close1 < close

dntrend = high1 > high
dntrend1 = low1 > low
dntrend2 = open1 > open
dntrend3 = close1 > close

//Raw Forms
cnt = math.sum(uptrend ? 1 : 0, len)
cnt1 = math.sum(uptrend1 ? 1 : 0, len)
cnt2 = math.sum(uptrend2 ? 1 : 0, len)
cnt3 = math.sum(uptrend3 ? 1 : 0, len)

cnt4 = math.sum(dntrend ? 1 : 0, len)
cnt5 = math.sum(dntrend1 ? 1 : 0, len)
cnt6 = math.sum(dntrend2 ? 1 : 0, len)
cnt7 = math.sum(dntrend3 ? 1 : 0, len)

color1 = cnt > cnt[1] ? color.white:color.black
color2 = cnt1 > cnt1[1] ? color.blue:color.black
color3 = cnt2 > cnt2[1] ? color.red:color.black
color4 = cnt3 > cnt3[1] ? color.orange:color.black

color9= cnt4 > cnt4[1] ? color.rgb(0, 169, 31):color.black
color10 = cnt5 > cnt5[1] ? color.rgb(0, 169, 31):color.black
color11 = cnt6 > cnt6[1] ? color.rgb(0, 169, 31):color.black
color12 = cnt7 > cnt7[1] ? color.rgb(0, 169, 31):color.black

col1 = hiclop ? color1:color9
col2 = hiclop ? color2:color10
col3 = hiclop ? color3:color11
col4 = hiclop ? color4:color12

plot(raw? cnt:na, color = col1, title = "HighU")
plot(raw? cnt1:na, color = col2, title = "LowU")
plot(raw? cnt2:na, color = col3, title = "OpenU")
plot(raw? cnt3:na, color = col4, title = "CloseU")

color5= cnt4 > cnt4[1] ? color.white:color.black
color6 = cnt5 > cnt5[1] ? color.blue:color.black
color7 = cnt6 > cnt6[1] ? color.red:color.black
color8 = cnt7 > cnt7[1] ? color.orange:color.black

color13= cnt4 > cnt4[1] ? color.rgb(255, 0, 0):color.black
color14 = cnt5 > cnt5[1] ? color.rgb(255, 0, 0):color.black
color15 = cnt6 > cnt6[1] ? color.rgb(255, 0, 0):color.black
color16 = cnt7 > cnt7[1] ? color.rgb(255, 0, 0):color.black

col5 = hiclop ? color5:color13
col6 = hiclop ? color6:color14
col7 = hiclop ? color7:color15
col8 = hiclop ? color8:color16

plot(raw1? cnt4:na, color = col5, title = "HighD")
plot(raw1? cnt5:na, color = col6, title = "LowD")
plot(raw1? cnt6:na, color = col7, title = "OpenD")
plot(raw1? cnt7:na, color = col8, title = "CloseD")

//Analysis
up = cnt > cnt[1] and cnt1 > cnt1[1] and cnt2 > cnt2[1] and cnt3 > cnt3[1]
cnt8 = math.sum(up ? 1 : 0, len)
dn = cnt4 > cnt4[1] and cnt5 > cnt5[1] and cnt6 > cnt6[1] and cnt7 > cnt7[1]
cnt9 = math.sum(dn ? 1 : 0, len)
up1 = cnt > cnt1
cnt10 = math.sum(up1 ? 1 : 0, len)
dn1 = cnt < cnt1
cnt11 = math.sum(dn1 ? 1 : 0, len)
up2 = cnt3 > cnt2
cnt12 = math.sum(up2 ? 1 : 0, len)
dn2 = cnt3 < cnt2
cnt13 = math.sum(dn2 ? 1 : 0, len)

plot(analysis? cnt8:na, color = cnt8 > cnt8[1] ? color.rgb(0, 255, 229):color.rgb(0, 0, 0, 100), title = "All Up", style= plot.style_circles, linewidth = 3)
plot(analysis? cnt9:na, color = cnt9 > cnt9[1] ? color.rgb(255, 0, 72):color.rgb(0, 0, 0, 100), title = "All Dn", style= plot.style_circles, linewidth = 3)
plot(analysis1? cnt10:na, color = cnt > cnt1 ? color.rgb(0, 255, 229):color.rgb(0, 0, 0, 100), title = "High Over Low", style= plot.style_circles, linewidth = 3)
plot(analysis1? cnt11:na, color = cnt1 > cnt ? color.rgb(255, 0, 72):color.rgb(0, 0, 0, 100), title = "Low Over High", style= plot.style_circles, linewidth = 3)
plot(analysis2? cnt12:na, color = cnt3 > cnt2 ? color.rgb(0, 255, 229):color.rgb(0, 0, 0, 100), title = "Close Over Open", style= plot.style_circles, linewidth = 3)
plot(analysis2? cnt13:na, color = cnt2 > cnt3 ? color.rgb(255, 0, 72):color.rgb(0, 0, 0, 100), title = "Open Over Close", style= plot.style_circles, linewidth = 3)


