Parabolic SAR Code

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #59394 quote
    tom123
    Participant
    Junior

    Hi all,

    I was wondering if anyone has the code for the Parabolic SAR indicator and is willing to share? I know the indicator is accessible through calling SAR but I would like the code behind it.

    Thanks!

    #59397 quote
    AVT
    Participant
    Senior
    #59421 quote
    supertiti
    Participant
    Master

    Hi Tom,

    Here you have the code of SAR from an Italian forum :

    have a nice day

    // SAR - Parabolic SAR        11.11.13
    
    // Questo codice vi propone l’algoritmo per la riproduzione del Parabolic SAR
    // Parametri
    // increment (increment = 0.02)   
    // initial (initial = 0.02)               
    // limite (limite = 0.2)                 
    
    IF BARINDEX < 2 THEN
         parabolic = LOW
         islong = 1
         af = limite
         hp = HIGH
         lp = LOW
    ELSE
         IF islong THEN
              parabolic = parabolic + af * (hp - parabolic)
              parabolic = MIN(parabolic, LOW[1])
              parabolic = MIN(parabolic, LOW[2])
         ELSE
              parabolic=parabolic + af * (lp - parabolic)
              parabolic=MAX(parabolic, HIGH[1])
              parabolic=MAX(parabolic, HIGH[2])
         ENDIF
         
         reverse = 0
         
         IF islong THEN
              IF LOW < parabolic THEN
                   islong = 0
                   reverse = 1
                   parabolic = hp
                   lp = LOW
                   af = initial
              ENDIF
         ELSE
              IF HIGH > parabolic THEN
                   islong = 1
                   reverse =1
                   parabolic = lp
                   hp = HIGH
                   af = initial
              ENDIF
         ENDIF
         
         IF NOT reverse THEN
              IF islong THEN
                   IF HIGH > hp THEN
                        hp = HIGH
                        af = af + increment
                        af = MIN (af,limite)
                   ENDIF
              ELSE
                   IF LOW < lp THEN
                        lp = LOW
                        af = af + increment
                        af = MIN (af,limite)
                   ENDIF
              ENDIF
         ENDIF
         
    ENDIF
    ////////////////////////////////////////////////////////////////
    
    RETURN parabolic as " parabolic " 
    
    tom123, Nicolas and ginko thanked this post
    #59429 quote
    bolsatrilera
    Participant
    Master

    Here you have another  code of SAR

    REM SAR
    
    
    if barindex < 2 then
    
    facteur = 0.02
    tmpSAR = low
    extreme = low
    tendance = 1
    
    else
    if tendance[ 1 ] = 1 then
    extreme = max( extreme[ 1 ], high )
    
    if tmpSAR[1] > low then
    tendance = -1
    facteur = 0.02
    tmp = max(high,high[1])
    tmpSAR = max(extreme, tmp)
    extreme = low
    else
    if extreme > extreme[1] and facteur <0.2 then
    facteur = facteur+0.02
    endif
    tmpSAR = tmpSAR[1]+facteur*(extreme-tmpSAR[1])
    tmp = min(low,low[1])
    tmpSAR = min(tmpSAR,tmp)
    endif
    else
    extreme = min( extreme[ 1 ], low )
    
    if tmpSAR[1] <high then
    tendance = 1
    facteur = 0.02
    tmp = min(low,low[1])
    tmpSAR = min(extreme,tmp)
    extreme = high
    else
    if extreme < extreme[1] and facteur <0.2 then
    facteur = facteur+0.02
    endif
    tmpSAR = tmpSAR[1]+facteur*(extreme-tmpSAR[1])
    tmp = max(high,high[1])
    tmpSAR = max(tmpSAR,tmp)
    endif
    endif
    
    endif
    if tmpSAR>=tmpSAR[1] then
    col=1
    else
    col=-1
    endif
    
    return tmpSAR[1] coloured by col as "SAR"
    
    tom123 and Nicolas thanked this post
    #75515 quote
    Real Pro
    Participant
    Average

    Thanks for sharing this.  I’m having difficulty when adjusting the 3 variables of initial, increment and limite.  I want the pSAR to be highly sensitive (ie. change from under to over at the slightest provocation), but it seems PRT has a lower limit on such a display.  Is this correct?  Is there a way to get around this limitation?  Regards.

    #75568 quote
    Nicolas
    Keymaster
    Master

    I’m not aware of any limitations. Did you try to adjust the increment and initial variables with lower values, and with 3 decimals?

    #75570 quote
    Real Pro
    Participant
    Average

    Thank you, yes I tried adjusting them several times.  Someone explained to me that it’s possible PRT used a slightly different code for the SAR.  There are a few different ones around.  I’m trying to replicate what I have on another platform.  If I can get the code for it, I’m hoping you or someone else might be able to translate it for me.  Is there a place where I can request a translation please?

    #75584 quote
    Nicolas
    Keymaster
    Master

    If the code is not copyright protected, you can freely create a new topic following this procedure (for MT4 code conversion or any other trading platform):

    Free Conversion of MT4 Indicators (MQL4)

    #75758 quote
    Real Pro
    Participant
    Average

    I’ve asked the author and he’s strict with sharing his work.  So I can’t do that.

    But I wonder if you’d help.  I’ve tried modifying both of the codes above to achieve a greater responsiveness (ie. a choppier pSAR) and can’t get that happening.

    #75765 quote
    Nicolas
    Keymaster
    Master

    Sure I could help, did you try the settings below?

    parabolic-sar-fast-settings.png parabolic-sar-fast-settings.png
    #75769 quote
    Real Pro
    Participant
    Average

    Thanks.  Yes I tried the built in parameters, but I can’t get it responsive enough.  The change from above to below and vice versa take too long.  I need it much tighter to the price action.

    #75772 quote
    Nicolas
    Keymaster
    Master

    ok, but that’s already very fast with the settings I gave in the last post. Since I have no clue of what you expect to be more responsive, could you please share with me some screenshots of the other indicator you talked about? Thank you.

    #75785 quote
    Real Pro
    Participant
    Average

    I just want it to be a bit faster, like so:

    x-3.jpg x-3.jpg
    #75846 quote
    Nicolas
    Keymaster
    Master

    A very different kind of SAR, a very different indicator. I’d like to help but it seems that is has been a lot customized in its code and how could we know what changed were made?

    #174047 quote
    rochnickols
    Participant
    New

    Please see in next post the code from the ‘SAR ATD’ indicator in French.
    Actually this indicator is not OK, because the SAR should not reverse if touched but not crossed at the close of the period.
    See this example were the SAR reverses whereas it should not.
    [attachment file=”SARCross&Reverse.png”]
    Can anyone help provide the right code modification to get this result?

    Best regards

    SARCrossReverse.png SARCrossReverse.png
Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.

Parabolic SAR Code


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
tom123 @tom123 Participant
Summary

This topic contains 16 replies,
has 2 voices, and was last updated by robertogozzi
4 years, 6 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 01/13/2018
Status: Active
Attachments: 3 files
Logo Logo
Loading...