In pinescript we have in-built function for calculation of Parabolic SAR value. The parabolic SAR is used to identify direction of asset and is also used as stop-loss when you have taken a position in the direction of trade. Below is the chart showing parabolic SAR on "GOOG" Daily Chart. When the value of parabolic sar is below the price, the trend is considered bullish. A change from bearish to bullish sar is considered and buy signal and change from bullish to bearish sar is considered sell signal.
As you know functions are like black box which take input and provide output, you need not worry about real calculation part. The function used in pinescript for calculation of parabolic SAR is known as sar(). The two brackets after the name of sar signify that it is a function. All the inputs to the function is provided inside these brackets and are separated by commas. The input to any function is known as parameter.
Syntax of Parabolic SAR
The syntax of sar function is as under :
mySAR = sar(start, inc, max)
The input supported by sar() are :
start : The default value of start is 0.02
increment : The default value of start is 0.02
maximum : The default value of start is 0.20
Code for implementing Parabolic SAR
The below code will change the colour of SAR to red on SAR being bearish or green on being bullish
//@version=4 study(title="Parabolic SAR", shorttitle="SAR", overlay=true) mySAR = sar(0.02, 0.02,0.2) myColor = mySAR < low?color.green:color.red plot(mySAR, "ParabolicSAR", style=plot.style_cross, color=myColor) |
Below is the result produced by the SAR indicator.