1

I'm trying to code a the parabolic sar algorithm and am stuck on a few things:

Rising SAR
----------

Prior SAR: The SAR value for the previous period. 

Extreme Point (EP): The highest high of the current uptrend. 

Acceleration Factor (AF): Starting at .02, AF increases by .02 each time the extreme point makes a new high. AF can reach a maximum of .20, no matter how long the uptrend extends.

Current SAR = Prior SAR + Prior AF(Prior EP - Prior SAR) 

Falling SAR
-----------

Prior SAR: The SAR value for the previous period. 

Extreme Point (EP): The lowest low of the current downtrend. 

Acceleration Factor (AF): Starting at .02, AF increases by .02 each time the extreme point makes a new low. AF can reach a maximum of .20, no matter how long the downtrend extends.

Current SAR = Prior SAR - Prior AF(Prior SAR - Prior EP) 

When it reverses from Rising SAR to Falling SAR (or vice versa) I'm not sure what to reset the following variables to:

  • EP
  • Prior SAR

Also when starting the algrotihm what should the starting Prior SAR and EP be?

2
  • Is the content in the code block actually code? If so, what language is it? Or if it's actually a quote, where's it from?
    – Nat
    Mar 9, 2018 at 13:51
  • 1
    It's the description of how to calculate the SAR Mar 9, 2018 at 15:01

1 Answer 1

3

If you haven't already done so, Google it. There are Excel spreadsheets and You Tube videos out there that explain Parabolic SAR construction.

I have some 25+ year old software and books from back in the day when I thought that indicators like this were the Holy Grail. They include Parabolic SAR and for resets it is stated as:

** On the positive side, for new buy signals, the initial SAR price is equal to the lowest price recorded during the previously closed short position.

On the negative side, for new short sell signals, the initial SAR price is equal to the highest price recorded during the previously closed short position.

On both the long side and the short side, SAR must lie at or outside the latest two periods' high-low price ranges and never inside these ranges. If in a long position and SAR is greater than the two most recent lows, then reset SAR to the lower of those two lows. If in a short position and SAR is lower than the two most recent highs, then reset SAR to the higher of those two highs. **

From the examples shown, when starting the algorithm, it uses the most recent low for an uptrend and the most recent high for a downtrend.

Hope that helps.

EDIT: See if this helps: https://www.tradinformed.com/2015/01/21/calculate-psar-indicator-revised/

2
  • Thank you! I googled for 2 days before asking here and couldn't find anything that descriptive. I guess now my only thing I need to figure out is how calculate whether my dataset is starting in an uptrend or down trend. It's easy to see with your eyes but hard to translate that to code.
    – Deekor
    Mar 9, 2018 at 15:01
  • I just Googled it and there are also links that provide a downloadable Excel spreadsheet. Whether they're reliable, I dunno :->) Mar 9, 2018 at 15:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .