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

[amibroker] Need help with the following code



PureBytes Links

Trading Reference Links

I got this from tradestation code as seen in the algorithm, but 
apparently it thinks Period[i]<6.  Does anybody have any clues?
TIA


_SECTION_BEGIN("Ehler's Dominant Cycle1");
//derived from 
http://www.mesasoftware.com/Seminars/TAG22RocketScience.ppt#294,12,Cy
cle Period Code (cont)

SetBarsRequired(200,0);
P=(H+L)/2;

{Period=0; jI=0;jQ=0;I1=0;I2=0;Q2=0;Q1=0; X1=0;X2=0;Y1=0;Re=0;Im=0;
 }
//Smooth with less than one lag
Smoother=(4*P+3*Ref(P,-1) +2*Ref(P,-2) +4*Ref(P,-3))/10; 

//detrend with linear phase
Detrender=(.25*Smoother+.75*Ref(Smoother,-2) -.75*Ref(Smoother,-4)-
.25*Ref(Smoother,-6))*(.046*Ref(period,-1)+.332);

//Compute InPhase and Quadrature components
jI=.25*I1+.75*Ref(I1,-2) -.75*Ref(I1,-4)-.25*Ref(I1,-6);
jQ=.25*Q1+.75*Ref(Q1,-2) -.75*Ref(Q1,-4)-.25*Ref(Q1,-6);

//Phasor addition to equalize amplitude due to quadrature 
calculations (and 3 bar averaging)
I2=I1-jQ;
Q2=Q1+jI;

//Smoothe the I and Q components before applying the discriminator
I2=.15*I2+.85*Ref(I2,-1);
Q2=.15*Q2+.85*Ref(Q2,-1);

//Homodyne Discriminator
	//Complex Conjugate Multiply
	X1=I2*Ref(I2,-1);
	X2=I2*Ref(Q2,-1);
	Y1=Q2*Ref(Q2,-1);
	Y2=Q2*Ref(I2,-1);
	Re=X1+Y1;
	Im=X2-Y2;
//Smooth to remove undesired cross products
	Re=.2*Re+.8*Ref(Re,-1);
	Im=.2*Im+.8*Ref(Im,-1);
	//Compute cycle period
   	for(i=1;i<BarCount;i++)
	{
	if (Im[i] != 0 AND Re[i] != 0)
	Period[i]=(360/atan(Im[i]/Re[i])); 
	else if (Period[i]>(1.5*(Period[i-1])))
	Period[i]=(1.5*(Period[i-1])); 
	else if (Period[i]<(.67*Period[i-1])) 
	Period[i]=(.67*(Period[i-1]));
	else if (Period[i]<6)
	Period[i]=6;
	else if (Period[i]>50) 
   Period[i]=50;
   Period=.2*Period[i]+(.8*Period[i-1]);
   }
   Plot(Period,"CyclePeriod",colorRed,styleLine);
_SECTION_END();


Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.15.26/598 - Release Date: 12/22/2006 3:22 PM