Professional Documents
Culture Documents
Adaptive Cybercycle
Adaptive Cybercycle
//| AdaptiveCyberCycle.mq5 |
//| |
//| Adaptive Cyber Cycle |
//| |
//| Algorithm taken from book |
//| "Cybernetics Analysis for Stock and Futures" |
//| by John F. Ehlers |
//| |
//| contact@mqlsoft.com |
//| http://www.mqlsoft.com/ |
//+------------------------------------------------------------------+
//---- author of the indicator
#property copyright "Coded by Witold Wozniak"
//---- author of the indicator
#property link "www.mqlsoft.com"
//---- indicator version
#property version "1.00"
//---- drawing the indicator in a separate window
#property indicator_separate_window
//---- two buffers are used for calculation and drawing the indicator
#property indicator_buffers 2
//---- two plots are used
#property indicator_plots 2
//+----------------------------------------------+
//| Cycle indicator drawing parameters |
//+----------------------------------------------+
//---- drawing the indicator 1 as a line
#property indicator_type1 DRAW_LINE
//---- red color is used as the color of the indicator line
#property indicator_color1 Red
//---- the indicator 1 line is a continuous curve
#property indicator_style1 STYLE_SOLID
//---- indicator 1 line width is equal to 1
#property indicator_width1 1
//---- displaying the indicator label
#property indicator_label1 "Adaptive Cyber Cycle"
//+----------------------------------------------+
//| Trigger indicator drawing parameters |
//+----------------------------------------------+
//---- drawing the indicator 2 as a line
#property indicator_type2 DRAW_LINE
//---- blue color is used for the indicator signal line
#property indicator_color2 Blue
//---- the indicator 2 line is a continuous curve
#property indicator_style2 STYLE_SOLID
//---- indicator 2 line width is equal to 1
#property indicator_width2 1
//---- displaying the indicator label
#property indicator_label2 "Trigger"
//+----------------------------------------------+
//| Horizontal levels display parameters |
//+----------------------------------------------+
#property indicator_level1 0.0
#property indicator_levelcolor Gray
#property indicator_levelstyle STYLE_DASHDOTDOT
//+----------------------------------------------+
//| Indicator input parameters |
//+----------------------------------------------+
input double Alpha=0.07; // Indicator ratio
input int Shift=0; // Horizontal shift of the indicator in bars
//+----------------------------------------------+
//---- declaration of dynamic arrays that
//---- will be used as indicator buffers
double CycleBuffer[];
double TriggerBuffer[];
//---- declaration of integer variables for the indicators handles
int CP_Handle;
//---- declaration of the integer variables for the start of data calculation
int min_rates_total;
//---- declaration of dynamic arrays that
//---- will be used as ring buffers
int Count[];
double Smooth[],Price[];
//+------------------------------------------------------------------+
//| Recalculation of position of the newest element in the array |
//+------------------------------------------------------------------+
void Recount_ArrayZeroPos(int &CoArr[]) // return the current value of the price
series by the link
{
//----
int numb,Max1,Max2;
static int count=1;
Max2=7;
Max1=Max2-1;
count--;
if(count<0) count=Max1;
MaxBar=rates_total-min_rates_total-3;
Price[bar0]=(high[bar]+low[bar])/2.0;
Smooth[bar0]=(Price[bar0]+2.0*Price[bar1]+2.0*Price[bar2]+Price[bar3])/6.0;
if(bar<=MaxBar)
{
//--- copy newly appeared data in the array
if(CopyBuffer(CP_Handle,0,bar,1,period)<=0) return(0);
CycleBuffer[bar]=K0*(Smooth[bar0]-K1*Smooth[bar1]+Smooth[bar2])
+K2*CycleBuffer[bar+1]-K3*CycleBuffer[bar+2];
}
else CycleBuffer[bar]=(Price[bar0]-2.0*Price[bar1]+Price[bar2])/4.0;
TriggerBuffer[bar]=CycleBuffer[bar+1];
if(bar>0) Recount_ArrayZeroPos(Count);
}
//----
return(rates_total);
}
//+------------------------------------------------------------------+