PureBytes Links
Trading Reference Links
|
Hi Cliff,
Parabolic SAR formula in AmiBroker was written according to the
article "The Parabolic Trading System" by Thom Hartle,
Stocks & Commodities V. 11:11(477-479).
I checked the output of AmiBroker's SAR against the output of
leading T/A software packages and it matches exactly.
>From what I see in your code there are some differencies
to the SAR definitions, for example:
> psar [ i ] = Math.max ( psar [ i ], high [ i ], high [ i- 1 ] );
Here you ensure that SAR of today is not lower than a high of today or a high of yesterday,
while original SAR specification requires that:
"SAR of *tommorrow* can never be below today's or yesterday's high price"
So you can see 3 days span:
SAR[ i ] = MAX( SAR[ i ], high[ i - 1], high[ i - 2 ] );
instead of 2 days in your formula
Also AmiBroker does not assume going long at a setup stage - instead
it checks for current trend and sets up accordingly.
Speed: yes you can expect JScript/VBScript code to be at least 10 times slower
than pure AFL code. Reasons: built-in AFL functions are written in C++ and
compiled to a native x86 CPU code and AFL executor operates on the whole arrays
instead of iterating thru elements.
However AFL formulas with JScript/VBScript embedded are still *a lot* faster than
some other product using PREV :-)
Cliff: if this explanation is not enough for you please contact me privately
at: tj@xxxx
Best regards,
Tomasz Janeczko
===============
AmiBroker - the comprehensive share manager.
http://www.amibroker.com
----- Original Message -----
From: <cliffelion@xxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Saturday, May 26, 2001 11:30 PM
Subject: [amibroker] Re: Need help with analysis/commentary
> Dear Tomasz,
>
> I apologize for taking so much of your time with this but I think
> that there is still a problem with this analysis.
>
> After working with the version that you corrected it appeared that
> the model was accurate, but I cannot always generate accurate
> buy/sell orders using the commentary for actual trading.
>
> Being unable to figure this out I coded the SAR using jscript
> (attached below).
>
> This was an interesting experience because when I compared it to
> bigcharts and some other charing services I found they were all
> slightly different (by visual inspection). In fact I think that the
> bigcharts SAR may be incorrect (not just different parameters). This
> jscript SAR does appear to match the SAR on barcharts.com
>
> The jscript version also correlates well with the SAR indicator built
> into ami with one small difference. I use the SAR value calculated
> using values from dayN on dayN (this value is used for trading on day
> N+1). The ami built in indicator plots the value calculated for dayN
> on day N+1 - therefore the value is not available on dayN to enter
> orders for dayN+1.
>
> For example:
> In the case of EXPE on 5/22/01 the built in SAR has already reversed
> (I'm not sure why) - the jscript SAR has not reversed and can still
> be used to provide the [stop] order for the trade on the next day
> (5/23/01). On 5/23 the SAR is pierced and it reverses.
>
> As far as I can tell this is correct - but I would be interested in
> your comment! Also the jscript version runs much more slowly than the
> predefined function.
>
> Best Regards
>
> Cliff Elion
>
>
> /**********BEGIN Parabolic SAR Indicator****************/
> EnableScript ( "jscript" );
> psar = low;
>
> <%
> AF = 0.02; //acceleration factor
> MAX = 0.2; //max acceleration
>
> close = VBArray ( AFL ( "close" ) ).toArray();
> high = VBArray ( AFL ( "high" ) ).toArray();
> low = VBArray ( AFL ( "low" ) ).toArray();
> psar = VBArray ( AFL ( "psar" ) ).toArray();
>
> psar [ 0 ] = close [ 0 ]; //initialize
> long = 1; //assume long for initial
> conditions
> af = AF; //init acelleration factor
> ep = low[ 0 ]; //init extreme point
> hp = high [ 0 ];
> lp = low [ 0 ];
>
> for ( i=1; i<close.length; i++ )
> {
> reverse = 0;
> //check for reversal
> if ( long )
> {
> if ( low [ i ] < psar [ i-1 ] )
> {
> long = 0; reverse = 1; //reverse position
> to short
> psar [ i ] = hp; //sar is high
> point in prev trade
> lp = low [ i ];
> af = AF;
> }
> }
> else
> {
> if ( high [ i ] > psar [ i-1 ] )
> {
> long = 1; reverse = 1; //reverse position to
> long
> psar [ i ] = lp;
> hp = high [ i ];
> af = AF;
> }
> }
>
> if ( reverse == 0 )
> {
> if ( long )
> {
> if ( high [ i ] > hp ) { hp = high [ i ]; af += AF; af =
> Math.min ( af, MAX ); }
> psar [ i ] = psar [ i-1 ] + af * ( hp - psar [ i-1 ] );
> psar [ i ] = Math.min ( psar [ i ], low [ i ], low [ i-
> 1 ] );
> }
> else
> {
> if ( low [ i ] < lp ) { lp = low [ i ]; af = af + AF;
> af = Math.min ( af, MAX ); }
> psar [ i ] = psar [ i-1 ] + af * ( lp - psar [ i-1 ] );
> psar [ i ] = Math.max ( psar [ i ], high [ i ], high [ i-
> 1 ] );
> }
> }
> }
>
> AFL.Var ( "psar" ) = psar;
> %>
>
> graph0 = close;
> graph0Style = 64 +32 ;
> //graph0Style = 128 +32 ;
> graph0barcolor=1;
> graph1 = psar;
> graph1Style = 8 + 16 + 32;
> graph1color = 8;
>
> title=name() + " - sar = "+writeval(psar);
> /**********END Parabolic SAR Indicator****************/
>
>
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>
|