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

Rãspuns: Rãspuns: [amibroker] Re: Ehler's formulas coded in AFL


  • To: <amibroker@xxxxxxxxxxxxxxx>
  • Subject: Răspuns: Răspuns: [amibroker] Re: Ehler's formulas coded in AFL
  • From: "MPLM (Intel EPSD) Razvan Andrei" <ra@xxxxxxxx>
  • Date: Fri, 29 Oct 2004 08:34:04 +0200

PureBytes Links

Trading Reference Links

hi,
It is about spacing and  wrapped lines.

SetBarsRequired(1000000,1000000);
freq =Param("Freq",40,3,100,1);
price=((H+L)/2);
alpha=Param("alpha",0.07,0,1,0.001);
BurstLength = 2*freq;
pi=4*atan(1);
RTD=180/pi;
DTR=pi/180;
SWcount=0;SWGate=0;Jcount=0;SWCycle=0;Cycle=0;I1=0;Q1=0;InstPeriod=0;
DeltaPhase=0;MedianDelta=0;DC=0;Value1=0;
DCPeriod=0;RealPart=0;ImagPart=0;DCPhase=0;MedianDelta=0;Smooth=0;
GraphXSpace=5;
//{ Sine wave Test}
SWcycle =  sin( Cum(1)*(360*DTR)/freq );
 for (j=0;j<BarCount;j++)
 {
 Jcount[j] = j % burstLength[j];

    if (SWcount[j]==1 AND Jcount[j] == 0)  SWcount[j] = 0;
               else
    if (SWcount[j]==0 AND Jcount[j]== 0)  SWcount[j] = 1;

    if (SWcount[j] ==0)   SWGate[j] = 1;
              else
              SWGate[j] = 0;


   SWGate[j] = SWcount[j] % 2 ;
   SWGen[j]  = SWCycle[j];// * SWGate[j];
   }
   //Plot(SWGen,"",2,1);

   //Select sinewave test pattern OR real prices
   Price = IIf(Param("Prices or test",1,1,2,1)==1,Price,SWGen);

   Smooth = (Price + 2*Ref(Price,-1) + 2*Ref(Price,-2) + Ref(Price,-3))/6;

   for(i=6;i<BarCount;i++)
   {
   Cycle[i]  = (1-0.5*alpha)^2*(Smooth[i] - 2*Smooth[i-1] +Smooth[i-2] +
2*(1-alpha)*Cycle[i-1] - (1-alpha)^2*Cycle[i-2]);

       //if (i < 7)  Cycle[i] = (Price[i] - 2*Price[i-1] + Price[i-2])/4;
        //Cycle[i] = Price[i];

   //Hilbert Transform}
     Q1[i] = (0.0962*Cycle[i] + 0.5769*Cycle[i-2] - 0.5769*Cycle[i-4] -
0.0962*Cycle[i-6]) * (0.5 + 0.08*InstPeriod[i-1]);
         I1[i] = Cycle[i-3];

    if (Q1[i] != 0 AND Q1[i-1] != 0) DeltaPhase[i] = (I1[i]/Q1[i] -
I1[i-1]/Q1[i-1]) / (1 + I1[i]*I1[i-1]/(Q1[i]*Q1[i-1]));
         if (DeltaPhase[i] < 0.1) DeltaPhase[i] = 0.1;
         if (DeltaPhase[i] > 1.1) DeltaPhase[i] = 1.1;
   }
   MedianDelta = Median(DeltaPhase , 5);

   //Plot(MedianDelta,"MedianDelta",2,8);
   //Plot(DeltaPhase,"DeltaPhase",3,8);
   //Plot(Q1,"Q1",4,8);Plot(I1,"I1",5,8);
   //Plot(Cycle,"Cycle",5,8);
   //Plot(Smooth,"Smooth",6,8);

   for(i=50;i<BarCount;i++)
   {

         if (MedianDelta[i] == 0) DC[i]=15;
         else
         DC[i] = (6.28318/MedianDelta[i]) + 0.5;

         InstPeriod[i] = 0.33*DC[i] + 0.67*InstPeriod[i-1];
         Value1[i] = 0.15*InstPeriod[i] + 0.85*Value1[i-1];

   //Plot(InstPeriod,"InstPeriod",2,8);
   //Plot(Value1,"Value1",3,8);
   //Plot(MedianDelta,"MedianDelta",4,8);

   //Compute Dominant Cycle Phase
         DCPeriod[i] = int(Value1[i]);
         //RealPart[i] = 0; ImagPart[i] = 0;
         for (Count1=0; Count1 < DCPeriod[i] ;Count1++)//DCPeriod-1
               {
                     RealPart[i] = RealPart[i] +
sin(360*DTR*Count1/DCPeriod[i]) *Cycle[i-Count1];
                     ImagPart[i] = ImagPart[i] + cos(360*DTR*Count1 /
DCPeriod[i]) * (Cycle[i-Count1]);
               }

         if (abs(ImagPart[i]) > 0.001) DCPhase[i] =
atan(RealPart[i]/ImagPart[i])*RTD;
         if (abs(ImagPart[i]) <= 0.001) DCPhase[i] = 90*sign(RealPart[i]);

            DCPhase[i] = DCPhase[i] + 90;
            if (ImagPart[i] < 0) DCPhase[i] = DCPhase[i] + 180;
            if (DCPhase[i] > 345) DCPhase[i] = DCPhase[i] - 360;

   }
         SineWave = sin(DCPhase*DTR);
         LeadSine = sin((DCPhase+45)*DTR);

   //Plot(DCPeriod,"DCPeriod",0,1);
   Plot(SineWave,"SineWave",colorGreen,1);
   Plot(LeadSine,"LeadSine",colorRed,1);

   Buy = Cross(Sinewave,LeadSine);
   Sell = Cross(LeadSine, Sinewave);
Razvan
  -----Mesaj original-----
  De la: sgoswami_41 [mailto:sgoswami_41@xxxxxxxxx]
  Trimis: 28 octombrie 2004 16:06
  Catre: amibroker@xxxxxxxxxxxxxxx
  Subiect: Răspuns: [amibroker] Re: Ehler's formulas coded in AFL




  Thanks Cris & Razvan,

  When I tried to Scan/Explore I got following message:

  Line 18, Column 11:
    DTR=pi/180;


  SWcount=0;SWGate=0;Jcount=0;SWCycle=0;Cycle=0;I1=0;Q1=0;InstPeriod=0;
  D

    eltaPhase
  ----------^

  Error 23.
  Syntax error

  Kindly help me as I am new to AFL.

  Regards


  --- In amibroker@xxxxxxxxxxxxxxx, "MPLM (Intel EPSD) Razvan Andrei"
  <ra@xxxx> wrote:
  > Thanks, Cris, for your help.
  > Razvan
  >   -----Mesaj original-----
  >   De la: Christoper [mailto:turkey@x...]
  >   Trimis: 26 octombrie 2004 23:12
  >   Catre: amibroker@xxxxxxxxxxxxxxx
  >   Subiect: [amibroker] Re: Ehler's formulas coded in AFL
  >
  >
  >
  >   Below is one I dug up from my library.
  >
  >   Later,
  >   Chris
  >
  >   --------------------------------
  >   /*
  >   >From Ehlers book: Cybernetic Analysis for Stocks and Futures
  >   */
  >
  >   SetBarsRequired(1000000,1000000);
  >   freq =Param("Freq",40,3,100,1);
  >   price=((H+L)/2);
  >   alpha=Param("alpha",0.07,0,1,0.001);
  >
  >   BurstLength = 2*freq;
  >   pi=4*atan(1);
  >   RTD=180/pi;
  >   DTR=pi/180;
  >
  >
  SWcount=0;SWGate=0;Jcount=0;SWCycle=0;Cycle=0;I1=0;Q1=0;InstPeriod=0;
  D
  >   eltaPhase=0;MedianDelta=0;DC=0;Value1=0;
  >
  DCPeriod=0;RealPart=0;ImagPart=0;DCPhase=0;MedianDelta=0;Smooth=0;
  >   GraphXSpace=5;
  >
  >   //{ Sine wave Test}
  >
  >   SWcycle =  sin( Cum(1)*(360*DTR)/freq );
  >   for (j=0;j<BarCount;j++)
  >   {
  >     Jcount[j] = j % burstLength[j];
  >
  >         if (SWcount[j]==1 AND Jcount[j] == 0)  SWcount[j] = 0;
  >               else
  >         if (SWcount[j]==0 AND Jcount[j]== 0)  SWcount[j] = 1;
  >
  >         if (SWcount[j] ==0)   SWGate[j] = 1;
  >               else
  >               SWGate[j] = 0;
  >
  >
  >   SWGate[j] = SWcount[j] % 2 ;
  >   SWGen[j]  = SWCycle[j];// * SWGate[j];
  >   }
  >   //Plot(SWGen,"",2,1);
  >
  >   //Select sinewave test pattern OR real prices
  >   Price = IIf(Param("Prices or test",1,1,2,1)==1,Price,SWGen);
  >
  >   Smooth = (Price + 2*Ref(Price,-1) + 2*Ref(Price,-2) + Ref(Price,-
  >   3))/6;
  >
  >   for(i=6;i<BarCount;i++)
  >   {
  >         Cycle[i]  = (1-0.5*alpha)^2*(Smooth[i] - 2*Smooth[i-1] +
  >   Smooth[i-2] + 2*(1-alpha)*Cycle[i-1] - (1-alpha)^2*Cycle[i-2]);
  >
  >         //if (i < 7)  Cycle[i] = (Price[i] - 2*Price[i-1] + Price
  [i-
  >   2])/4;
  >         //Cycle[i] = Price[i];
  >
  >   //Hilbert Transform}
  >         Q1[i] = (0.0962*Cycle[i] + 0.5769*Cycle[i-2] - 0.5769*Cycle
  [i-
  >   4] - 0.0962*Cycle[i-6]) * (0.5 + 0.08*InstPeriod[i-1]);
  >         I1[i] = Cycle[i-3];
  >
  >         if (Q1[i] != 0 AND Q1[i-1] != 0) DeltaPhase[i] = (I1[i]/Q1
  >   [i] - I1[i-1]/Q1[i-1]) / (1 + I1[i]*I1[i-1]/(Q1[i]*Q1[i-1]));
  >         if (DeltaPhase[i] < 0.1) DeltaPhase[i] = 0.1;
  >         if (DeltaPhase[i] > 1.1) DeltaPhase[i] = 1.1;
  >   }
  >   MedianDelta = Median(DeltaPhase , 5);
  >
  >   //Plot(MedianDelta,"MedianDelta",2,8);
  >   //Plot(DeltaPhase,"DeltaPhase",3,8);
  >   //Plot(Q1,"Q1",4,8);Plot(I1,"I1",5,8);
  >   //Plot(Cycle,"Cycle",5,8);
  >   //Plot(Smooth,"Smooth",6,8);
  >
  >   for(i=50;i<BarCount;i++)
  >   {
  >
  >         if (MedianDelta[i] == 0) DC[i]=15;
  >         else
  >         DC[i] = (6.28318/MedianDelta[i]) + 0.5;
  >
  >         InstPeriod[i] = 0.33*DC[i] + 0.67*InstPeriod[i-1];
  >         Value1[i] = 0.15*InstPeriod[i] + 0.85*Value1[i-1];
  >
  >   //Plot(InstPeriod,"InstPeriod",2,8);
  >   //Plot(Value1,"Value1",3,8);
  >   //Plot(MedianDelta,"MedianDelta",4,8);
  >
  >   //Compute Dominant Cycle Phase
  >         DCPeriod[i] = int(Value1[i]);
  >         //RealPart[i] = 0; ImagPart[i] = 0;
  >         for (Count1=0; Count1 < DCPeriod[i] ;Count1++)//DCPeriod-1
  >               {
  >                     RealPart[i] = RealPart[i] + sin
  >   (360*DTR*Count1/DCPeriod[i]) *Cycle[i-Count1];
  >                     ImagPart[i] = ImagPart[i] + cos
  >   (360*DTR*Count1 / DCPeriod[i]) * (Cycle[i-Count1]);
  >               }
  >
  >         if (abs(ImagPart[i]) > 0.001) DCPhase[i] = atan(RealPart
  >   [i]/ImagPart[i])*RTD;
  >         if (abs(ImagPart[i]) <= 0.001) DCPhase[i] = 90*sign
  (RealPart
  >   [i]);
  >
  >            DCPhase[i] = DCPhase[i] + 90;
  >            if (ImagPart[i] < 0) DCPhase[i] = DCPhase[i] + 180;
  >            if (DCPhase[i] > 345) DCPhase[i] = DCPhase[i] - 360;
  >
  >   }
  >         SineWave = sin(DCPhase*DTR);
  >         LeadSine = sin((DCPhase+45)*DTR);
  >
  >   //Plot(DCPeriod,"DCPeriod",0,1);
  >   Plot(SineWave,"SineWave",colorGreen,1);
  >   Plot(LeadSine,"LeadSine",colorRed,1);
  >   Title=" Ehlers Sinewave Indicator (Cybernetic Analysis for
  Stocks and
  >   Futures) by cs     \\c01Lead Sine "+LeadSine+"
  >   \\c00Sine "+sineWave+" ";
  >
  >   Buy = Cross(Sinewave,LeadSine);
  >   Sell = Cross(LeadSine, Sinewave);
  >   --- In amibroker@xxxxxxxxxxxxxxx, "ra_randrei" <ra@xxxx> wrote:
  >   >
  >   >
  >   > Hi,
  >   > I am now evaluating AmiBroker, moving from MetaStock, so I am
  new
  >   to
  >   > AFL. I am looking for Ehler's formulas coded in AFL. Yes, I
  know
  >   > that some are included in the indicators.dll, but I am not
  quite
  >   > sure that the results are accurate. Beside, I will learn much
  more
  >   > from seeing/trying AFL code than from just applying a
  function... I
  >   > found a previous post about Instantaneous Trendline, very
  useful
  >   > (Thanks Corey, AMA makes some sense for me now). I am looking
  now
  >   > for Sinewave, MAMA/FAMA and mainly Market Mode Indicator. More
  >   > details about Ehler's formulas can be found at:
  >   > http://www.mesasoftware.com/seminars.htm
  >   > also at:
  >   > http://www.mesasoftware.com/OWorld2000RocketScience.ppt
  >   > Sorry if you received this message twice...
  >   > Thanks,
  >   > Razvan
  >
  >
  >
  >
  >
  >   Check AmiBroker web page at:
  >   http://www.amibroker.com/
  >
  >   Check group FAQ at:
  > http://groups.yahoo.com/group/amibroker/files/groupfaq.html
  >
  >
  >         Yahoo! Groups Sponsor
  >               ADVERTISEMENT
  >
  >
  >
  >
  >
  > -------------------------------------------------------------------
  ---------
  > --
  >   Yahoo! Groups Links
  >
  >     a.. To visit your group on the web, go to:
  >     http://groups.yahoo.com/group/amibroker/
  >
  >     b.. To unsubscribe from this group, send an email to:
  >     amibroker-unsubscribe@xxxxxxxxxxxxxxx
  >
  >     c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms
  of Service.
  >
  >
  >
  > [Non-text portions of this message have been removed]








  Check AmiBroker web page at:
  http://www.amibroker.com/

  Check group FAQ at:
http://groups.yahoo.com/group/amibroker/files/groupfaq.html


        Yahoo! Groups Sponsor

        Get unlimited calls to

        U.S./Canada




----------------------------------------------------------------------------
--
  Yahoo! Groups Links

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

    b.. To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

    c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
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:
    http://docs.yahoo.com/info/terms/