Advanced Price Direction bar colors
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © eykpunter

//@version=5
indicator("Advanced Price Direction bar colors", overlay=true)

evaltttext="advanced price direction; evaluates n plus n bars lumped together e.g. if you enter 5 the script uses the last 5 bars as a set and the set before that, in total 10 bars."
//input set size
eval=input.int(12,"priceaction set size",1, tooltip=evaltttext)
mawish=input.bool(true, "show moving average with same lengths as priceaction")

//bar directions
//compounded bar by lumping together sets of bars
cl=math.avg(close,eval) //close of bars lumped together
pr=cl[eval]             //close of previous set of bars lumped together
op=math.avg(open,eval)  //open of bars lumped together
//evaluate compunded bar
up=cl>pr and cl>op      //up when close >previous close and close>open
dn=cl<pr and cl<op      //down when close<previous close and close<open
fa= not up and not dn   //falter when neither up nor down

isupfa = close > open and fa
isdownfa = close <= open and fa

barcolor(isupfa ? color.rgb(200, 200, 240) : isdownfa ? color.rgb(240,200,200) : na)

longma=mawish? ta.sma(close,eval): na
plot(longma,"ma length s setsize", color.green)







