hernandez
Pine Script Rookie
Pine Script Rookie
Posts: 1
Joined: December 23rd, 2021

Understanding a piece of code

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?

funkyjive
Pine Script Rookie
Pine Script Rookie
Posts: 1
Joined: January 4th, 2022

Re: Understanding a piece of code

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.

Return to “Pine Script Q&A”