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

RE: [amibroker] SAR more reliable



PureBytes Links

Trading Reference Links

Here is the variable SAR code.  You have to look very closely and watch all
of the subscripts and temporary variables in order to make the substitution
you want.

Ken

/////////////////////////////////
// Parabolic SAR re-implemented in
// native AFL.
//
// Example of for/if/else control statements
//
// Requires:
// AmiBroker 4.31.1 
// 
// Written by: Tomasz Janeczko

IAF = 0.04;       // acceleration factor
MaxAF = 0.2;     // max acceleration

psar = Close;		// initialize
long = 1;        // assume long for initial conditions
af = IAF;         // init acelleration factor
ep = Low[ 0 ];   // init extreme point
hp = High [ 0 ];
lp = Low [ 0 ];

for( i = 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
	if ( long )
	{
		if ( Low [ i ] < psar [ i ]  )
		{
			long = 0; reverse = 1; // reverse position to Short
			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
			psar [ i ] =  lp;
			hp = High [ i ];
			af = IAF;
		}
	}

	if ( reverse == 0 )
	{
		if ( long )
		{
			if ( High [ i ] > hp ) 
			{
				hp = High [ i ]; 
				af = af + IAF; 
				if( af > MaxAF ) af = MaxAF; 
			}
             
			if( Low[ i - 1 ] < psar[ i ] ) psar[ i ] = Low[ i -
1 ];
			if( Low[ i - 2 ] < psar[ i ] ) psar[ i ] = Low[ i -
2 ];
		}
       else
		{
			if ( Low [ i ] < lp )  
			{ 
				lp = Low [ i ]; 
				af = af + IAF; 
				if( af > MaxAF ) af = MaxAF; 
			}	
				
			if( High[ i - 1 ] > psar[ i ] ) psar[ i ] = High[ i
- 1 ];
			if( High[ i - 2 ] > psar[ i ] ) psar[ i ] = High[ i
- 2 ];

		}
	}
}

Plot( Close, "Price", colorBlack, styleLine );
Plot( psar, "SAR", colorRed, styleDots | styleNoLine | styleThick ); 

-----Original Message-----
From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf
Of ikodu.takana
Sent: Tuesday, June 12, 2007 1:02 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] SAR more reliable

Hello,

is it possible to plot a SAR signal computed from an EMA(close,5) for
instance instead of the standard close - that would make the SAR much more
reliable against market noises.

from that link ( http://www.amibroker.com/library/detail.php?id=268 ) i
tried to replace the line :

psar = Close;		// initialize
with
psar = EMA(Close,5);		// initialize

or
psar = (C + H + L)/3;		// initialize

but that made strange results or even bugged the code

If someone can explain to me the right solution

thanks



Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to SUPPORT {at}
amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
 
Yahoo! Groups Links






Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/