calculate parabolic SAR

Version 1.0.0.0 (3,13 KB) von natanel
calculate Parabolic SAR (SAR - stop and reverse)
837 Downloads
Aktualisiert 5. Nov 2012

Lizenz anzeigen

PARABOLICSAR - calculated parabolic SAR for specific hugh and low

INPUT:
high - high values vector
low - low values vector
AFstart - start value for Wilderes acceleration factor (typical 0.02)
AFmax - max value for Wilderes acceleration factor (typical 0.2)
AFdelta - delta value for Wilderes acceleration factor (typical 0.02)

OUTPUT:
SAR - output vector of parabolc SAR
turnPoints - turn places in SAR vector
longSort - long=1, sort=-1

EXAMPLE:
% read JNJ stock data
url2Read = 'http://ichart.finance.yahoo.com/table.csv?s=JNJ&a=0&b=12&c=2006&d=9&e=23&f=2007&g=w&ignore=.csv';
s=urlread( url2Read);
% changing the format of s f
s=strread(s,'%s','delimiter',',');
s=reshape(s,[],length(s)/7)';
% calc SAR
dateNum = datenum(s(2:end,1));
open = str2double(s(2:end,2));
high = str2double(s(2:end,3));
low = str2double(s(2:end,4));
close = str2double(s(2:end,5));
[SAR,turnPoints,longSort]=parabolicSAR( high,low);

% plot
figure(1)
title('parabolic SAR: JNJ');
xlabel('date');
ylabel('price');

ylim = [min(high) max(high)];
set( gca,'ylim',ylim);

hold on;
% plot stock;
plot(dateNum,high,'b','LineWidth',2);
% plot turn points
line([dateNum(turnPoints) dateNum(turnPoints)]', [ ones(length(turnPoints),1)*ylim ]','Color',[0 0 0]);

% plot SAR long in green
index=find(longSort==1);
plot(dateNum(index),SAR(index),'.g');
% plot SAR short in red
index=find(longSort==-1);
plot(dateNum(index),SAR(index),'.r');
hold off;
legend('stock','turn points');
datetick(gca,'x',20);

INFO:
The parabolic study is a “true reversal” indicator in that it is always in the market. Whenever a position is closed-out, it is also reversed. T
he point at which a position is reversed is called a Stop and Reverse (SAR). A
lthough stops are plotted for each bar, a trade is reversed only when the SAR is penetrated by a price.

Formula:
SARt+1=SARt+AF*(EPtrade-SARt)

Where:
SARt+1 = next periods SAR
SARt = current SAR
AF = begins at .02 and increases by .02 to a maximum of .20
EP = extreme price (high if long; low if short)

The initial SAR or SIP (SAR Initial Point) of a long move is found by looking for the first bar with a higher high and a higher low than the previous bar.
The converse of this is used to find the SIP for a short move.
The acceleration factor changes as the trade progresses, starting at .02 and increasing in increments of .02 for each bar in which a new extreme occurs.

see, J. Welles Wilder, Jr., New Concepts in Technical Trading Systems, McLeansville, NC: Trend Research, 1978, pp. 9-22.

$License: BSD (use/copy/change/redistribute on own risk, mention the
author) $
History:
001: 01-May-2006 ,Natanel Eizenberg, First version.
002: 04-Nov-2012, Natanel Eizenberg, prepare for file exchange

Zitieren als

natanel (2024). calculate parabolic SAR (https://www.mathworks.com/matlabcentral/fileexchange/38906-calculate-parabolic-sar), MATLAB Central File Exchange. Abgerufen .

Kompatibilität der MATLAB-Version
Erstellt mit R2006b
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS Linux
Kategorien
Mehr zu Transaction Cost Analysis finden Sie in Help Center und MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Veröffentlicht Versionshinweise
1.0.0.0