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

[amibroker] Var IAF Re: DIMITRIS- Question



PureBytes Links

Trading Reference Links

Dimitris,

It does not seem to make a big difference with a variable IAF.

Peter

// Initialize IAF Array
X=(DEMA(StochD(40),20)-50)/50; 
IAF=0.05*(1.1+abs(X));

function SARafl( Cvar, Hvar, Lvar, MaxAF )
{
	//IAF = 0.02;       // acceleration factor
	//MaxAF = 0.02;     // max acceleration

	psar = Cvar;		// initialize
	long = 1;        // assume long for initial conditions
	af = IAF[ 0 ];         // init acelleration factor
	ep = Lvar[ 0 ];   // init extreme point
	hp = Hvar [ 0 ];
	lp = Lvar [ 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 ( Lvar [ i ] < psar [ i ]  )
			{
				long = 0; reverse = 1; // reverse
position to Short
				psar [ i ] =  hp;       // SAR is Hvar
point in prev trade
				lp = Lvar [ i ];
				//af = IAF;
				af = IAF[ i ];
			}
		}
		else
		{
			if ( Hvar [ i ] > psar [ i ]  )
			{
				long = 1; reverse = 1;        //reverse
position to long
				psar [ i ] =  lp;
				hp = Hvar [ i ];
				//af = IAF;
				af = IAF[ i ];
			}
		}

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

			}
		}
	}
	return psar;
}

Plot( Close, "Price", colorBlack, styleCandle );
Plot( SARafl(C,H,L,0.02), "SAR", colorRed, styleDots | styleNoLine |
styleThick );

Filter=1;
AddColumn(SAR(.02,.02),"SAR");
AddColumn(SARafl(C,H,L,0.02),"SARafl");
AddColumn(iaf,"IAF");

-----Original Message-----
From: DIMITRIS TSOKAKIS [mailto:TSOKAKIS@xxxxxxxxx] 
Sent: Friday, May 02, 2003 2:57 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Re: DIMITRIS- Question

Peter,
Tough question [I hope the same for the answer...].
To use  realistic examples, the 

X=(DEMA(StochD(40),20)-50)/50;// the divergence of the smoothed 
stochastics from the average line
IAF=0.05*(1.1+X);Plot(IAF,"",4,1);

can make IAF vary from 0.01 [bearish] to 0.1[bullish]
For an alternative, the

X=(DEMA(StochD(40),20)-50)/50;
IAF=0.05*(1.1-X);Plot(IAF,"",4,1);

can make IAF vary from 0.01 [bullish] to 0.1 [bearish].
You can also arrange IAF to be fast at the end of the trend [bullish 
OR bearish] and slow during the trend with the simple alternative

X=(DEMA(StochD(40),20)-50)/50;
IAF=0.05*(1.1+abs(X));Plot(IAF,"",4,1);

this would keep you close to the main curve at decision points 
and far from the main curve when it is better to go with the trend 
and wait.
This is an initial example to control the SAR exits according to the 
market behavior and SAR may be *any* indicator companion.
The last 3 years we saw fast uptrends and prolonged downtrends, an 
opposite to the 98-99 days. 
It does not make sense to use *always* the same IAF because you do 
not have functions to do the right thing.
On the other side, the use of variable parameters  is the next, 
advanced, T/A step.
Bullish, congestive and bearish phase can be [and should always be] 
just numbers.
[It is the basic Pythagorean principle, true the last 2500 years]
A good trend detector may give you these numbers.
A good T/A software should help you to introduce these numbers 
everywhere, get the refined results, apply them to the market and 
catch the bird.
Without variable parameters we shall be permanent victims of the 
whipsaws [and I do not like it !!!]
Thanks for the creative communication.
Dimitris Tsokakis 

--- In amibroker@xxxxxxxxxxxxxxx, "bluesinvestor" <investor@xxxx> 
wrote:
> Dimitris,
> 
> IAF and AF are not variable in the code I provided, although they 
could
> be.  But what type of array(s) would be passed for that 
information?  Or
> would they be calculated on the fly?
> 
> Regards,
> Peter
> 
> -----Original Message-----
> From: DIMITRIS TSOKAKIS [mailto:TSOKAKIS@x...] 
> Sent: Friday, May 02, 2003 1:29 PM
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: [amibroker] Re: DIMITRIS- Question
> 
> Peter,
> thank you for the effort.
> The question for SAR is in variable IAF and/or AF.
> This will make the initial SAR more flexible.
> Is it possible through your code ?
> As for the variable inputs, we can simply have a SAR of any 
indicator 
> with a simple H,L replacement : 
> Example [the MeanCMO and its SAR companion]
> 
> m25=Foreign("~sumCMO25","C");// after creating the ~sumCMO25 in AA
> m=Foreign("~count","v");
> meanCMO25=m25/m;
> DD=DEMA(MEANCMO25,15);
> H=dd;L=dd;// the replacement
> cc=SAR(0.01,0.2 );
> This 0.01 works well for the N100 database, it would be better to 
> vary from 0.01 to 0.08 according to the trend evolution.
> The same for 0.2, it would be better to go up to 0.8 sometimes.
> Dimitris Tsokakis
> --- In amibroker@xxxxxxxxxxxxxxx, "bluesinvestor" <investor@xxxx> 
> wrote:
> > Hello Dimitris,
> > 
> > A little modification from Tomasz original code and 'kitakste 
edho'
> > (excuse my lousy Greek ;)
> > 
> > Regards,
> > Peter
> > 
> > function SARafl( Cvar, Hvar, Lvar, IAF, MaxAF )
> > {
> > 	//IAF = 0.02;       // acceleration factor
> > 	//MaxAF = 0.02;     // max acceleration
> > 
> > 	psar = Cvar;		// initialize
> > 	long = 1;        // assume long for initial conditions
> > 	af = IAF;         // init acelleration factor
> > 	ep = Lvar[ 0 ];   // init extreme point
> > 	hp = Hvar [ 0 ];
> > 	lp = Lvar [ 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 ( Lvar [ i ] < psar [ i ]  )
> > 			{
> > 				long = 0; reverse = 1; // reverse
> > position to Short
> > 				psar [ i ] =  hp;       // SAR is Hvar
> > point in prev trade
> > 				lp = Lvar [ i ];
> > 				af = IAF;
> > 			}
> > 		}
> > 		else
> > 		{
> > 			if ( Hvar [ i ] > psar [ i ]  )
> > 			{
> > 				long = 1; reverse = 
> 1;        //reverse
> > position to long
> > 				psar [ i ] =  lp;
> > 				hp = Hvar [ i ];
> > 				af = IAF;
> > 			}
> > 		}
> > 
> > 		if ( reverse == 0 )
> > 		{
> > 			if ( long )
> > 			{
> > 				if ( Hvar [ i ] > hp ) 
> > 				{
> > 					hp = Hvar [ i ]; 
> > 					af = af + IAF; 
> > 					if( af > MaxAF ) af = MaxAF; 
> > 				}
> >              
> > 				if( Lvar[ i - 1 ] < psar[ i ] ) psar[ 
> i
> > ] = Lvar[ i - 1 ];
> > 				if( Lvar[ i - 2 ] < psar[ i ] ) psar[ 
> i
> > ] = Lvar[ i - 2 ];
> > 			}
> > 	       else
> > 			{
> > 				if ( Lvar [ i ] < lp )  
> > 				{ 
> > 					lp = Lvar [ i ]; 
> > 					af = af + IAF; 
> > 					if( af > MaxAF ) af = MaxAF; 
> > 				}	
> > 				
> > 				if( Hvar[ i - 1 ] > psar[ i ] ) psar[ 
> i
> > ] = Hvar[ i - 1 ];
> > 				if( Hvar[ i - 2 ] > psar[ i ] ) psar[ 
> i
> > ] = Hvar[ i - 2 ];
> > 
> > 			}
> > 		}
> > 	}
> > 	return psar;
> > }
> > 
> > Plot( Close, "Price", colorBlack, styleCandle );
> > Plot( psar, "SAR", colorRed, styleDots | styleNoLine | 
styleThick );
> > 
> > Filter=1;
> > AddColumn(SAR(.02,.02),"SAR");
> > AddColumn(SARafl(C,H,L,0.02,0.02),"SARafl");
> > 
> > -----Original Message-----
> > From: DIMITRIS TSOKAKIS [mailto:TSOKAKIS@x...] 
> > Sent: Friday, May 02, 2003 3:40 AM
> > To: amibroker@xxxxxxxxxxxxxxx
> > Subject: [amibroker] Re: DIMITRIS- Question
> > 
> > Wally,
> > You may go to
> > http://groups.yahoo.com/group/amibroker/message/38370
> > http://groups.yahoo.com/group/amibroker/message/38424
> > for the two alternatives.[I hope enough explained].
> > I try to introduce variable smoothing to an already useful trend 
> > detector, the DEMA(StochD(40),20).
> > It has nothing to do with PSAR, it is a stand-alone indicator.
> > Since it is quite smooth, I use 3-bars peak to signal the change 
of 
> > the direction.
> > DT
> > PS. We will follow a similar procedure, when PSAR will accept 
> > variable parameters, to improove PSAR results.
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "netbull2000" 
<netbull2000@xxxx> 
> > wrote:
> > > I read in one of the messages here that you came up with some 
new 
> > > trend indicator that seems to be better than PSAR. Could you 
> please 
> > > point me to your relevant message concerning this indicator. I 
am 
> > > interested in this as PSAR is about the only indicator I have 
> some 
> > > respect for.
> > > 
> > > Thanks...
> > > Wally
> > 
> > 
> > 
> > Send BUG REPORTS to bugs@xxxx
> > Send SUGGESTIONS to suggest@xxxx
> > -----------------------------------------
> > 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 
> > 
> > Your use of Yahoo! Groups is subject to
> > http://docs.yahoo.com/info/terms/
> 
> 
> 
> Send BUG REPORTS to bugs@xxxx
> Send SUGGESTIONS to suggest@xxxx
> -----------------------------------------
> 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 
> 
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/



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 

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



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Rent DVDs Online - Over 14,500 titles.
No Late Fees & Free Shipping.
Try Netflix for FREE!
http://us.click.yahoo.com/YoVfrB/XP.FAA/uetFAA/GHeqlB/TM
---------------------------------------------------------------------~->

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 

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