Advanced Price Direction Algorithm
// 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")
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,"sets of ## bars to appraise UpDownFalt",1, tooltip=evaltttext)

//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

//example output if used as an indicator of its own
fill(hline(0),hline(1),color=up?color.new(color.blue,50):dn?color.new(color.red,50):color.new(color.yellow,50),title="UpDownFalt blue red yellow")



