Glan Nilly candle Trend
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © fauxlife

//@version=5
indicator(title="Glan Nilly candle Trend", shorttitle="GNCT", overlay=true)

tUc = input(color.blue, "Up Trend Color")
tDc = input(color.red, "Down Trend Color")
gc = color.rgb(197, 198, 202)

//-------------Heiken Ashi Calculation-----------------//
//Open = (open of previous bar + close of previous bar)/2.
//Close = (open + high + low + close)/4.

abi(chap, rast) =>  high[chap] < high[rast] and low[chap] < low[rast]
ghermez(chap, rast) => high[chap] > high[rast] and low[chap] > low[rast]
outerbarabi(chap, rast) => high[chap] < high[rast] and low[chap] > low[rast] and close[rast] > close[chap]
outerbarghermez(chap, rast) => high[chap] < high[rast] and low[chap] > low[rast] and close[rast] < close[chap]

innerbar(chap, rast) => high[chap] > high[rast] and low[chap] < low[rast]

oneouterabi = innerbar(2, 1)  and abi(2, 0)
oneouterghermez = innerbar(2, 1)  and ghermez(2, 0)
oneouteroutabi = innerbar(2, 1)  and outerbarabi(2, 0)
oneouteroutghermez = innerbar(2, 1)  and outerbarghermez(2, 0)

twoouterabi = innerbar(3, 2)  and innerbar(3, 1) and abi(3, 0)
twoouterghermez = innerbar(3, 2)  and innerbar(3, 1) and ghermez(3, 0)
twoouteroutabi = innerbar(3, 2)  and innerbar(3, 1) and outerbarabi(3, 0)
twoouteroutghermez = innerbar(3, 2)  and innerbar(3, 1) and outerbarghermez(3, 0)

threeouterabi = innerbar(4, 3)  and innerbar(4, 2) and innerbar(4, 1) and abi(4, 0)
threeouterghermez = innerbar(4, 3)  and innerbar(4, 2) and innerbar(4, 1) and ghermez(4, 0)
threeouteroutabi = innerbar(4, 3)  and innerbar(4, 2) and innerbar(4, 1) and outerbarabi(4, 0)
threeouteroutghermez = innerbar(4, 3)  and innerbar(4, 2) and innerbar(4, 1) and outerbarghermez(4, 0)

fourouterabi = innerbar(5, 4)  and innerbar(5, 3) and innerbar(5, 2) and innerbar(5, 1) and abi(5, 0)
fourouterghermez = innerbar(5, 4)  and innerbar(5, 3) and innerbar(5, 2) and innerbar(5, 1) and ghermez(5, 0)
fourouteroutabi = innerbar(5, 4)  and innerbar(5, 3) and innerbar(5, 2) and innerbar(5, 1) and outerbarabi(5, 0)
fourouteroutghermez = innerbar(5, 4)  and innerbar(5, 3) and innerbar(5, 2) and innerbar(5, 1) and outerbarghermez(5, 0)

fiveouterabi = innerbar(6, 5)  and innerbar(6, 4) and innerbar(6, 3) and innerbar(6, 2) and innerbar(6, 1) and abi(6, 0)
fiveouterghermez = innerbar(6, 5)  and innerbar(6, 4) and innerbar(6, 3) and innerbar(6, 2) and innerbar(6, 1) and ghermez(4, 0)
fiveouteroutabi = innerbar(6, 5)  and innerbar(6, 4) and innerbar(6, 3) and innerbar(6, 2) and innerbar(6, 1) and outerbarabi(4, 0)
fiveouteroutghermez =innerbar(6, 5)  and innerbar(6, 4) and innerbar(6, 3) and innerbar(6, 2) and innerbar(6, 1) and outerbarghermez(4, 0)

inner2 = innerbar(2, 1) and innerbar(2, 0)
inner3 = innerbar(3, 2) and innerbar(3, 1) and innerbar(3, 0)
inner4 = innerbar(4, 3) and innerbar(4, 2) and innerbar(4, 1) and innerbar(4, 0)
inner5 = innerbar(5, 4) and innerbar(5, 3) and innerbar(5, 2) and innerbar(5, 1) and innerbar(5, 0)


col = inner2 ? gc : inner3 ? gc : inner4 ? gc : inner5 ? gc : fiveouterabi ? tUc : fiveouterghermez ? tDc : fiveouteroutabi ? tUc : fiveouteroutghermez ?
     tDc : fourouterabi ? tUc : fourouterghermez ? tDc : fourouteroutabi ? tUc : fourouteroutghermez ? tDc : threeouterabi ? tUc : threeouterghermez ? tDc :
     threeouteroutabi ? tUc : threeouteroutghermez ? tDc : twoouterabi ? tUc : twoouterghermez ? tDc : twoouteroutabi ? tUc : twoouteroutghermez ? tDc :
     oneouterabi ? tUc : oneouterghermez ? tDc : oneouteroutabi ? tUc : oneouteroutghermez ? tDc : abi(1, 0) ? tUc : ghermez(1, 0) ? tDc : outerbarabi(1, 0) ?
     tUc : outerbarghermez(1, 0) ? tDc : gc

barcolor(col, title="Bar Color")