//+------------------------------------------------------------------+ //| Cycle_Ind.mq4 V20060519 | //| Cycle Indicator | //| Copyright © 2006, Toyolab FX | //| http://forex.toyolab.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, Toyolab FX" #property link "http://forex.toyolab.com/" #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Blue //---- extern var extern int BarsCount = 500; //---- Indicator buffers double Buf0[]; //---- Temporary buffers double Smooth[]; double Detrender[]; double Q1[]; double I1[]; //---- constants #define C0 0.0962 #define C1 0.5769 #define C2 0.0750 #define C3 0.5400 #define PI 3.1416 //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicator 0 SetIndexBuffer(0,Buf0); SetIndexLabel(0,"Cycle"); if(BarsCount == 0) BarsCount = Bars-250; SetIndexDrawBegin(0,Bars-BarsCount); BarsCount += 250; //---- Hidden buffer IndicatorBuffers(5); SetIndexBuffer(1,Smooth); SetIndexBuffer(2,Detrender); SetIndexBuffer(3,Q1); SetIndexBuffer(4,I1); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator start function | //+------------------------------------------------------------------+ int start() { double Q2[2], I2[2], Period_[2], Re1[2], Im1[2]; for(int i=BarsCount-1;i>=0;i--) { Smooth[i] = iMA(NULL,0,4,0,MODE_LWMA,PRICE_MEDIAN,i); Detrender[i] = (C0*(Smooth[i]-Smooth[i+6]) + C1*(Smooth[i+2]-Smooth[i+4]))*(C2*Period_[1] + C3); Q1[i] = (C0*(Detrender[i]-Detrender[i+6]) + C1*(Detrender[i+2]-Detrender[i+4]))*(C2*Period_[1] + C3); I1[i] = Detrender[i+3]; double jI = (C0*(I1[i]-I1[i+6]) + C1*(I1[i+2]-I1[i+4]))*(C2*Period_[1] + C3); double jQ = (C0*(Q1[i]-Q1[i+6]) + C1*(Q1[i+2]-Q1[i+4]))*(C2*Period_[1] + C3); I2[0] = (I1[i] - jQ + 4*I2[1])/5; Q2[0] = (Q1[i] + jI + 4*Q2[1])/5; Re1[0] = (I2[0]*I2[1] + Q2[0]*Q2[1] + 4*Re1[1])/5; Im1[0] = (I2[0]*Q2[1] - Q2[0]*I2[1] + 4*Im1[1])/5; if(Im1[0] != 0 && Re1[0] != 0) Period_[0] = PI*2/MathArctan(Im1[0]/Re1[0]); if(Period_[0] > 3*Period_[1]/2) Period_[0] = 3*Period_[1]/2; if(Period_[0] < 2*Period_[1]/3) Period_[0] = 2*Period_[1]/3; if(Period_[0] < 6) Period_[0] = 6; if(Period_[0] > 50) Period_[0] = 50; Period_[0] = (Period_[0] + 4*Period_[1])/5; Buf0[i] = (Period_[0] + 2*Buf0[i+1])/3; Q2[1] = Q2[0]; I2[1] = I2[0]; Re1[1] = Re1[0]; Im1[1] = Im1[0]; Period_[1] = Period_[0]; } return(0); } //+------------------------------------------------------------------+