Coding and using Parabolic SAR in PineScript

 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.


Parabolic SAR produces false signal when price of scrip is moving sideways with no clear direction. Recommended to use moving averages along with SAR to only trade in trending markets.

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.



Resources

Highest Rated Udemy Course on PineScript - Grab your Seat Now 

Udemy Discount Coupon Code : UDEMY-JAN23 (Valid upto 30th Nov 2023)

Learn more about coding on tradingview in PineScript through Books on pinescript available on amazon and kindle.


200+ pages book100 pages book200+ pages book


Point and Figure Charts : A Time-Tested Tool for Technical Analysis

In the dynamic world of financial markets, investors and traders constantly seek tools that can provide valuable insights into market trends...