[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: Metastock vs Amibroker



PureBytes Links

Trading Reference Links




 

hello,
 
I want to know if someone has found usefull this 
variation of SAR with the volatility
the code comes from a modification of Tomasz' 
SAR.
 
stephane
 
 
 

 
IAF = 0.02; 
// acceleration factor
MaxAF = 0.2; 
// max acceleration
psar = Close; // 
initialize
long = 1; <FONT 
color=#008000 size=1>// assume long for initial conditions<FONT 
size=1>
af = IAF; // init acelleration 
factor
ep = Low[ 0 ]; 
// init extreme point
hp = High [ 0 
];
lp = Low [ 0 
];
Inc=ATR(<FONT 
color=#ff00ff size=1>10);<FONT color=#800000 
size=1>
for( i = <FONT color=#ff00ff 
size=1>2; i < BarCount; i++ )
{
if ( long )
{
psar [ i ] = psar [ i-1 
] + af * ( hp - psar [ i-1 
] );
}
else
{
psar [ i ] = psar [ i-1 
] + af * ( lp - psar [ i-1 
] );
}
reverse = 0;
//check for reversal<FONT 
size=1>
if ( long )
{
if ( Low 
[ i ] < psar [ i ] )
{
long = 0; 
reverse = 1; 
// reverse position to Short<FONT 
size=1>
psar [ i ] = hp; // SAR is High point in 
prev trade
lp = Low [ i ];
af = IAF;
}
}
else
{
if ( High 
[ i ] > psar [ i ] )
{
long = 1; 
reverse = 1; 
//reverse position to long<FONT 
size=1>
psar [ i ] = lp;
hp = High [ i ];
af = IAF;
}
}
if ( reverse == 
0 )
{
if ( long )
{
if ( Inc [ i ] 
> Inc [ i-1 ] ) 
{
hp = High [ i ]; 
af = af + IAF; 
if( af > 
MaxAF ) af = MaxAF; 
}

if( Low[ 
i - 1 ] < psar[ i ] ) 
psar[ i ] = Low[ i - 1<FONT 
size=1> ];
if( Low[ 
i - 2 ] < psar[ i ] ) 
psar[ i ] = Low[ i - 2<FONT 
size=1> ];
if(Inc [ i ] 
<= Inc [ i-1 ] ) 
{
psar[i]=psar[i-1];
}

}
else
{
if ( Inc [ i ] 
> Inc [ i-1 ] ) 
{ 
lp = Low [ i ]; 
af = af + IAF; 
if( af > 
MaxAF ) af = MaxAF; 
} 

if( High[ 
i - 1 ] > psar[ i ] ) 
psar[ i ] = High[ i - 1<FONT 
size=1> ];
if( High[ 
i - 2 ] > psar[ i ] ) 
psar[ i ] = High[ i - 2<FONT 
size=1> ];
if(Inc [ i ] 
<= Inc [ i-1 ] ) 
{
psar[i]=psar[i-1];
}
}
}
}
Plot( Close, <FONT color=#ff00ff 
size=1>"Price", colorBlack, styleCandle 
);
Plot( psar, <FONT color=#ff00ff 
size=1>"SAR", colorGreen, styleDots | 
styleNoLine | styleThick );
Plot(SAR<FONT 
size=1>(0.02,<FONT 
color=#ff00ff size=1>0.2),<FONT color=#ff00ff 
size=1>"",colorRed,<FONT color=#ff00ff 
size=1>8+16<FONT 
size=1>);


Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html








Yahoo! Groups Sponsor


  ADVERTISEMENT 












Yahoo! Groups Links
To visit your group on the web, go to:http://groups.yahoo.com/group/amibroker/ 
To unsubscribe from this group, send an email to:amibroker-unsubscribe@xxxxxxxxxxxxxxx 
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.