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!
AVTParticipant
Senior
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 "
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"
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.
I’m not aware of any limitations. Did you try to adjust the increment and initial variables with lower values, and with 3 decimals?
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?
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)
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.
Sure I could help, did you try the settings below?
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.
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.
I just want it to be a bit faster, like so:
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?
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