Mesa Sine Wave

#1
What about this sine wave. I read about it. They say its work on short term market movements.

I want to know how to use this wave. Can somebody help me?

Is there a afl formula written for mesa sine wave? If so pls share..
 
#3
Try this:)


_SECTION_BEGIN("sinewave");
SetBarsRequired(100000,100000);
pi=4*atan(1);
RTD=180/pi;
DTR=pi/180;
SetOption( "initialequity", 50000 ); /* starting capital */
//PositionSize = -10; /* trade size will be 10% of available equty */


function CyclePeriod(array, alpha)
// Figure 9.4 on p. 111
{
smooth = (array + 2*Ref(array, -1) + 2*Ref(array, -2) + Ref(array, -3))/6;

for(i = 0; i < 7; i++) {
cycle=array; // Initialize early values and as array
InstPeriod = 0; // Initialize early values and as array
DeltaPhase = 0;
cycle=0;
Period=0;
}

for(i = 6; i < BarCount; i++)
{
cycle = (1 - .5*alpha)*(1 - .5*alpha)*(smooth - 2*smooth[i-1] + smooth[i-2]) + 2*(1 - alpha)*cycle[i-1] - (1 - alpha)*(1 - alpha)*cycle[i-2];
Q1 = (.0962*cycle + .5769*cycle[i-2] -.5769*cycle[i-4] - .0962*cycle[i-6])*(.5 + .08*InstPeriod[i-1]);
I1 = cycle[i-3];

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

//----- Speed up the median calculation by placing it inline
mlen = 5;
for(k = mlen - 1; k >= 0; k--) {temparray[k] = DeltaPhase[i + k - (mlen - 1)];}
temp=0;
for(k = mlen - 1; k > 0; k--)
{for (j = mlen - 1; j > 0; j--)
{if (temparray[j-1] > temparray[j])
{
temp = temparray[j-1];
temparray[j-1] = temparray[j];
temparray[j] = temp;
}
}
}
MedianDelta = temparray[mlen - 1 - (mlen / 2)];
if(MedianDelta == 0) DC = 15;
else DC = 6.28318/MedianDelta + .5;

InstPeriod = .33*DC + .67*InstPeriod[i-1];
Period = .15*InstPeriod + .85*Period[i-1];

//Compute Dominant Cycle Phase
DCPeriod = int(Period);
RealPart = 0; ImagPart = 0;

for (Count1=0; Count1 < DCPeriod ;Count1++) {
if ((i-Count1) > 0) {
RealPart = RealPart + sin(360*DTR*Count1/DCPeriod) * Cycle[i-Count1];
ImagPart = ImagPart + cos(360*DTR*Count1/DCPeriod) * Cycle[i-Count1];
}
}

if (abs(ImagPart) > 0.001) {
DCPhase = atan(RealPart/ImagPart)*RTD;
};

if (abs(ImagPart) <= 0.001) {
DCPhase = 90*sign(RealPart);
};

DCPhase = DCPhase + 90;
if (ImagPart < 0) DCPhase = DCPhase + 180;
if (DCPhase > 315) DCPhase = DCPhase - 360;
}
return DCPhase;
}


Med = (H+L)/2;

// CyclePeriod
CP = CyclePeriod(Med, .07);
SineWave = sin(CP*DTR);
LeadSine = sin((CP+45)*DTR);


Buy =Cross(Sinewave,LeadSine);
Sell =Cross(LeadSine, Sinewave);

Plot(SineWave , "SineWave ", colorBlue, styleLine);
Plot(LeadSine , "LeadSine ", colorRed, styleLine);
_SECTION_END();
 

Similar threads