logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
jhughey  
#1 Posted : Friday, May 1, 2009 10:00:13 AM(UTC)
jhughey

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/19/2008(UTC)
Posts: 19
Location: New York State

Was thanked: 2 time(s) in 1 post(s)
Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:6.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

Hello,


I am trying to reproduce the Parabolic SAR calculation, and I am having problems keeping track of the Next Extreme High/Low Point when it toggles Long/Short.

So far I am able to use Excel to correctly reproduce the tabulated SAR example in the Achelis’ book, “Technical Analysis from A to Z” (without typos); if

Ideally, I want the Next Extreme Point (NEP) to be the Highest High while SAR is Long, then toggle to be the Lowest Low while SAR is Short.

Here is a Next Extreme Point calculation using the Metastock SAR as a toggle.

Even if there is an alternative SAR calculation, I would really like to know why this does this not work, and how can I get it to work?


Thanks!

SARms := SAR(0.02,0.2);

{ Long / Short Toggles}

LONG := IF( SARms Low Ref(SARms,-1) Ref(High,-1) , 1 , 0);

SHORT := IF( SARms > High Ref(SARms,-1) Ref(Low,-1) , 1 , 0);

{ NEP is the Next Extreme Point }

NEP LONG Ref(NEP, -1) High , High , Ref(NEP,-1) NEP SHORT Ref(NEP, -1) Low , Low , Ref(NEP, -1) );

NEP;


wabbit  
#2 Posted : Friday, May 1, 2009 10:51:46 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Are you trying to reproduce SAR as a programming exercise?

Or, are you reproducing the SAR function because you weren't aware it is already built into MS?

Check out the SAR() function.



wabbit [:D]

jhughey  
#3 Posted : Saturday, May 2, 2009 5:35:48 PM(UTC)
jhughey

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/19/2008(UTC)
Posts: 19
Location: New York State

Was thanked: 2 time(s) in 1 post(s)
G'day Wabbit!

As a programming exercise, and yes, I am familiar with the sar() function. As a bit of background, I found that I could reproduce the SAR table described by Achelis in Excel, however if I compare it with the same parameters (0.02, 0.2) as the MS SAR indicator, they don't give the same results. The Excel SAR converges better. Anyway, that is another story. I need to translate the Excel work over to MS, and doing the toggle (as described) is one step towards that.

The purpose of the NEP is to have a starting point when SAR flips from long to short, or vice versa. For example, if I am going long with SAR, by keeping track of the highest high during this period, I have a starting point when it flips to going short. Keeping track of the lowest low during SAR short allows me a starting point when it flips to long. I do this easily in Excel, but it escapes me with MSFL.

Although I have been with MS as early as 1994, and have a long programming background, my MSFL is *very rusty. Suggestions are appreciated.

Thanks,

Joe


wabbit  
#4 Posted : Saturday, May 2, 2009 8:52:17 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
jhughey wrote:
SARms:=SAR(0.02,0.2);

{ Long / Short Toggles}
LONG := IF( SARms < Low AND Ref(SARms,-1) > Ref(High,-1) , 1 , 0);
SHORT := IF( SARms > High AND Ref(SARms,-1) < Ref(Low,-1) , 1 , 0);

{ NEP is the Next Extreme Point }
NEP := IF( LONG AND Ref(NEP, -1) < High , High , Ref(NEP,-1) );
NEP := IF( SHORT AND Ref(NEP, -1) > Low , Low , Ref(NEP, -1) );

NEP;


Hi Joe,

There are a couple of "issues" with your original code.

First is that you don't need to If(cond,1,0) as MS does this already when it returns values from comparison operations. Second, you cannot self-reference a variable by using Ref(); this is where PREV comes into play (read about how PREV works int he MS Users Manual or in any of the plethora of posts on the forum on the topic).

So, here's my take on the code you have so far...

Code:

SARms:=SAR(0.02,0.2);

{Long/Short Toggles}
long:=SARms<L and ref(SARms,-1)>ref(H,-1);
short:=SARms>H and ref(SARms,-1)<ref(L,-1);

{NEP is the Next Extreme Point}
NEP:=
if(long and H>prev, H,
if(short and L<prev, L, prev)
);

NEP;


jhughey wrote:
I found that I could reproduce the SAR table described by Achelis in Excel, however if I compare it with the same parameters (0.02, 0.2) as the MS SAR indicator, they don't give the same results. The Excel SAR converges better. Anyway, that is another story. I need to translate the Excel work over to MS, and doing the toggle (as described) is one step towards that.

The purpose of the NEP is to have a starting point when SAR flips from long to short, or vice versa. For example, if I am going long with SAR, by keeping track of the highest high during this period, I have a starting point when it flips to going short. Keeping track of the lowest low during SAR short allows me a starting point when it flips to long. I do this easily in Excel, but it escapes me with MSFL.


Now, don't quote me on this as I haven't played with this indicator in MS for a long time, but I am pretty sure that MS uses CLOSE prices in its computation of SAR, so if in your Excel variant you are using HIGH and LOW prices, then your results will be different. Patrick did some work a while ago to include a HIGH/LOW (?) variable setting SAR in the forum.dll so it might be worth a shot at having a look there? Patrick "lost access" to the source code for what was included in the forum.dll SAR function, so I haven't validated how it works.



Hope this helps.

wabbit [:D]

jhughey  
#5 Posted : Sunday, May 3, 2009 8:01:53 PM(UTC)
jhughey

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/19/2008(UTC)
Posts: 19
Location: New York State

Was thanked: 2 time(s) in 1 post(s)


Hi Wabbit,

Excellent! Thank you for your reply.

{ SAR’s Next Extreme Point}

SARms:=SAR(0.02,0.2);

{Are we long or short?}

long := SARms<L;

short := SARms>H;

{ Next Extreme Point}

NEP:=

If(long AND H>PREV, H,

If(short AND L<PREV, L, PREV)

);

NEP;

Thanks again!

(ps) I shall go back and check the Excel calculation of the SAR from the Achelis book. You are correct that this book's version is toggling the SAR when it crosses the High (when short) or the Low (when long), which generally looks better.
Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.