thank you for the detailed explanation, so the code if !IsNaN(close) and IsNaN(close[-1]) returns either 0 or 1, in this case since there's only one last bar, so the "highest" value is 1, then the code process the second line with the close price of last bar.
I wrote another similar code with labels to show the value of the variables, both "MA" and "something" and returning the same value, how come when I plot something, it does not give me the same results as MA? I don't see any lines being plotted unless I add highestall(something);
almost, but no.
it evaluates the if-then and sends that result on to highestall.
highestall( )
on every bar, what is in the parenthesis is evaluated.
every time highestall( ) is evaluated,
it creates a temporary array of all the values for the variable or formula.
highestall(close)
for every bar on the chart, this will look at all of the close values from all the bars, and find the highest close price.
when the code
if ( !IsNaN(close) and IsNaN(close[-1]) )
is true ( 1 )
then the middle parameter of the if-then , the average, is processed.
if the first line is false, then the 3rd parameter of the if-then is processed.
the result of the if-then is passed on to the highestall. either the average at the last bar or a nan value.
so for each pass over the bars, highestall will produce the same number, in all bars
Last edited: