//+------------------------------------------------------------------+ //| FX Sniper's T3 CCI.mq4 | //| | //| | //+------------------------------------------------------------------+ #property copyright "FX Sniper: T3-CCI :-)" #property link " " // #property copyright "MQL4->MQL5: Copyright © 2011 " #property link " " //--- indicator settings #property indicator_separate_window #property indicator_buffers 3 #property indicator_plots 3 #property indicator_color1 Black #property indicator_color2 Green #property indicator_color3 Red #property indicator_type1 DRAW_LINE #property indicator_type2 DRAW_HISTOGRAM #property indicator_type3 DRAW_HISTOGRAM #property indicator_label1 "FXST3CCI" //--- input parameters input int CCI_Period=5; input int T3_Period=5; input double b=0.618; //--- indicator buffers double cciBuffer[]; double cciHupBuffer[]; double cciHdnBuffer[]; //--- double e1,e2,e3,e4,e5,e6; double c1,c2,c3,c4; double n,w1,w2,b2,b3; //--- handles int cciHandle; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,cciBuffer,INDICATOR_DATA); SetIndexBuffer(1,cciHupBuffer,INDICATOR_DATA); SetIndexBuffer(2,cciHdnBuffer,INDICATOR_DATA); //--- name for Dindicator subwindow label IndicatorSetString(INDICATOR_SHORTNAME,"FXST3CCI("+string(CCI_Period)+","+string(T3_Period)+","+string(b)+")"); //--- variable reset b2=b*b; b3=b2*b; c1=-b3; c2=(3*(b2+b3)); c3=-3*(2*b2+b+b3); c4=(1+3*b+b3+3*b2); n=T3_Period; //--- if(n<1) n=1; else n=1+0.5*(n-1); w1=2/(n+1); w2=1-w1; //--- get handles cciHandle=iCCI(NULL,0,CCI_Period,PRICE_TYPICAL); if(cciHandle==INVALID_HANDLE) { Print("Error | Индикатор CCI. Не удалось создать хэндл индикатора. СТОП, error ",GetLastError()); return(-1); } //--- OnInit done return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &Time[], const double &Open[], const double &High[], const double &Low[], const double &Close[], const long &TickVolume[], const long &Volume[], const int &Spread[]) { //--- check for data if(rates_totalrates_total || prev_calculated<0) to_copy=rates_total; else { to_copy=rates_total-prev_calculated; if(prev_calculated>0) to_copy++; } //--- get cciBuffer if(IsStopped()) return(0); //Checking for stop flag if(CopyBuffer(cciHandle,0,0,to_copy,cciBuffer)<=0) { Print("Error | Индикатор CCI. Getting cciBuffer is failed. СТОП, error ",GetLastError()); return(0); } //--- int pos,i; if(prev_calculated==0) pos=0; else pos=prev_calculated-1; //--- calculate for(i=pos;i=0) cciHupBuffer[i]=cciBuffer[i]; else cciHupBuffer[i]=0.0; // if(cciBuffer[i]<0) cciHdnBuffer[i]=cciBuffer[i]; else cciHdnBuffer[i]=0.0; } //--- OnCalculate done. Return new prev_calculated. return(rates_total); } //+------------------------------------------------------------------+