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]
|