PureBytes Links
Trading Reference Links
|
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****************/
|