Hi Charlton
I tend to agree with your last comment.
In case this becomes of use later, the following is a working version of code that calculates and plots the current Dominant Cycle (DC) period on whatever chart timeframe its applied to:
************************************
Inputs:
Price ((H+L)/2);
Vars:
Smooth(0),
Detrender(0),
I1(0),
Q1(0),
JI(0),
JQ(0),
I2(0),
Q2(0),
Re(0),
Im(0),
Period(0),
SmoothPeriod(0);
If Currentbar > 5 then begin
Smooth = (4*Price+3*Price[1]+2*Price[2]+Price[3])/10;
Detrender=(0.0962*smooth+0.5769*smooth[2]-0.5769*smooth[4]-0.0962*smooth[6])*(0.075*Period[1]+0.54);
{compute inphase and quadrature components}
Q1 = (0.0962*Detrender + 0.5769*Detrender[2] - 0.5769*Detrender[4] - 0.0962*Detrender[6])*(0.075*Period[1] + 0.54);
I1 = Detrender[3];
{advance the phase of I1 and Q1 by 90 degrees}
JI = (0.0962*I1 + 0.5769*I1[2] - 0.5769*I1[4] -
0.0962*I1[6])*(0.075*period[1] + 0.54);
JQ = (0.0962*Q1 + 0.5769*Q1[2] - 0.5769*Q1[4] -
0.0962*Q1[6]) * (0.075*Period[1] + 0.54);
{phasor addition for 3 bar averaging}
I2 = I1 - JQ;
Q2 = Q1 + JI;
{smooth the I and Q components before applying}
I2 = 0.2*I2 + 0.8*I2[1];
Q2 = 0.2*Q2 + 0.8*Q2[1];
{homodyne Discriminator}
Re = I2*I2[1] + Q2*Q2[1];
Im = I2*Q2[1] - Q2*I2[1];
Re = 0.2*Re + 0.8*Re[1];
Im = 0.2*Im + 0.8*Im[1];
If Im <> 0 and Re <> 0 then Period =
360/ArcTangent(Im/Re);
If Period > 1.5*Period[1] then period =
1.5*Period[1];
If period < 0.67*Period[1] then Period =
0.67*Period[1];
If Period < 6 then Period = 6;
If Period >50 then Period = 50;
Period = 0.2*Period + 0.8*Period[1];
SmoothPeriod = 0.33*Period + 0.67*SmoothPeriod[1];
Plot1 (SmoothPeriod,"DC");
End;
************************************************
Apologies if this is something everyone already has.
Cheers
Steve