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

Re: [amibroker] Re: Need help with the following code



PureBytes Links

Trading Reference Links

You have a number of areasd which will calculate using no variable value
In this period = 0;
Detrender=(.25*Smoother+.75*Ref(Smoother,-2) -.75*Ref(Smoother,-4)-
.25*Ref(Smoother,-6))*(.046*Ref(period,-1)+.332);
I1 and Q1 have been defined as 0 in
 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);
even though you ahve shown before that I2=I1-jQ;
I2=.15*I2+.85*Ref(I2,-1); you cannot define a variable using its own
previous values, you must do this within a loop. you could define a new
variable like
I2a=.15*I2+.85*Ref(I2,-1);

-- 
Cheers
Graham
AB-Write >< Professional AFL Writing Service
Yes, I write AFL code to your requirements
http://www.aflwriting.com

On 23/12/06, jeffro861 <jhend746@xxxxxxxxxxxxx> wrote:
>
> Thanks for your help Graham...
> Could you elaborate on the third part please?  I believe I also
> needed to switch my arctan calculation from radians to degrees so on
> the numerator I put 6.283185307
>
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, Graham <kavemanperth@xxx> wrote:
> >
> > 3 things about the code
> >        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]);
> >
> > You are using else if for the first Period check and period is not
> > calculated if the first condition        if (Im[i] != 0 AND Re[i] !
> = 0) is
> > not true, so it is only ever using the initiated value of period
> from before
> > the loop
> > Also your last Period calculation is missing the array identifier
> so period
> > is not always passed to outside the loop except for the last value
> of the
> > array
> > Try this
> >
> >        if (Im[i] != 0 AND Re[i] != 0)
> > Period[i]=(360/atan(Im[i]/Re[i]));
> >
> >        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[i] =.2*Period[i]+(.8*Period[i-1]);
> >
> > The 3rd is that you calculation for Re and Im should be inside the
> loop as
> > you are trying to reference a periovus value of the variables in
> their own
> > calcualtions, this also occurs for a few other variables. You have
> to
> > remember that tradestation is based on looping for its basic
> coding method.
> > This is different to AB whihch calculates each variable for each
> bar, TS
> > calculates each bar for each variable
> > --
> > Cheers
> > Graham
> > AB-Write >< Professional AFL Writing Service
> > Yes, I write AFL code to your requirements
> > http://www.aflwriting.com
> >
> > On 23/12/06, jeffro861 <jhend746@xxx> wrote:
> > >
> > > 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();
> > >
> > >
> > >
> > > 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
>
>
>
>

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