Jump to content
Medved Trader Forums

Parabolic SAR calculation


hackedtrade

Recommended Posts

Hi Jerry,
 
I was curious if you could share the code for the Parabolic SAR indicator that Medved Trader uses.  I've been trying to duplicate it in Python referencing the online wiki page for the indicator as well as ohter sources, but it never seems to match up correctly with how Medved Trader displays it.  If you don't want to share, then I understand - I figured I would at least ask.  Thanks
Link to comment
Share on other sites

(Almost) none of our implementations will be secret, except ones that are not "public domain", in fact, almost all will be open code as soon as we do the custom indicator support (so that people can look at existing implementations to create their own).

 

I will give you the algorithm in a bit.

Link to comment
Share on other sites

direction length - how many candle are in the current direction period

Current Direction - can be up or down


do this for each candle:

if direction is up
  if candle high > intra high
    intra high = candle high
    increase step by step increment up to step max

  SAR = SAR + step * (intra high - SAR)

  if SAR > candle low   // switch directions
      direction = down
      SAR = intra high
      step = step increment // initialize step
      intra low = intra high
      direction length = 0
  else if direction length>=1 and SAR > low of one candle back
      SAR = low of one candle back
  else if direction length>=2 and SAR > low of two candles back
      SAR = low of two candles back

else if direction is down
  if candle low < intra low
    intra low = candle low
    increase step by step increment up to step max

  SAR = SAR - step * (SAR - intra low)

  if SAR < candle high  // switch directions
      direction = up
      SAR = intra low
      step = step increment // initialize step
      intra high = intra low
      direction length = 0
  else if direction length>=1 and SAR < high of one candle back
      SAR = high of one candle back
  else if direction length>=2 and SAR < high of two candles back
      SAR = high of two candles back

direction length = direction length + 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...