Type : Indicator, Name : Cosine IFM
Inputs: Price((H+L)/2);
Vars: Imult(.635),
Qmult (.338),
S2(0),
S3(0),
count(0),
DeltaPhase(0),
InstPeriod(0),
Period(0);
If CurrentBar > 5 then begin
Value1 = Price — Price[7];
S2 = .2*(Value1[1] + Value1)*(Value1[1] + Value1) + .8*S2[1];
S3 = .2*(Value1[1] — Value1)*(Value1[1] — Value1) + .8*S3[1];
If S2 <> 0 then Value2 = (SquareRoot(S3 / S2));
If S3 <> 0 then DeltaPhase = 2* ArcTangent(Value2);
{Sum DeltaPhases to reach 360 degrees. The sum is the instantaneous period.}
InstPeriod = 0;
Value4 = 0;
For count = 0 to 50 begin
Value4 = Value4 + DeltaPhase[count];
If Value4 > 360 and InstPeriod = 0 then begin
InstPeriod = count -1;
end;
end;
{Resolve Instantaneous Period errors and smooth}
If InstPeriod = 0 then InstPeriod = InstPeriod[1];
Period = .25*InstPeriod + .75*Period[1];
Plot1(Period, «DC»);
end;