Page 1 of 1

Understanding a piece of code

Posted: Thu Dec 23, 2021 5:28 pm
by hernandez
Hello, I'm trying to understand what does this piece of code in ordert to do the same thing in metatrader 4

Code: Select all

up=src-(Multiplier*atr)

upPlot1 = plot(up, style=plot.style_linebr, linewidth=2, color=color.green)
upPlot2 = plot(up[1], style=plot.style_linebr, linewidth=2, color=color.red)

up1 = nz(up[1],up)

upPlot3 = plot(up1, style=plot.style_linebr, linewidth=2, color=color.purple)
This piece of code generates the following lines

Image

the red line is exactly equal to the purple one. How this purple line is generated?

Re: Understanding a piece of code

Posted: Tue Jan 04, 2022 11:36 pm
by funkyjive
The only difference between the purple line and the red line is that IF the value of src-(Multiplier*atr) for the period before (i.e. the day before the current candle if the chart was daily) -- if that value is NaN (not a number -- usually means division by zero occurred) -- then it will switch out plotting the previous period value for the current period value.

But given that the formula for it is src-(Multiplier*atr) I don't see how a NaN can ever occur -- thus purple would always be the same as red.

Hope this helps.

I am wondering if there is more code, because the actual formula src-(Multiplier*atr) is not obvious to me. I don't know what src is, unless it is in an older version of pine.

Just beginning myself.