Beginners who write complex programs from the beginning usually don't succeed.
You should first create a basic program and then add the function that you need.
For the time being, I made it possible to display the CCI of 5 minutes time frame.
//+------------------------------------------------------------------+ //| #MTF_CCI.mq4 | //|------------------------------------------------------------------+ #property strict #property indicator_separate_window #property indicator_plots 1 #property indicator_buffers 1 //#property indicator_color1 Yellow #property indicator_level1 0.0 #property indicator_level2 300.0 #property indicator_level3 -300.0 //--- plot M5 #property indicator_label1 "M5" #property indicator_type1 DRAW_LINE #property indicator_color1 clrLimeGreen #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //---- input parameters //input bool PeriodM1 = false; // 1 Minute input bool PeriodM5=false; // 5 Minutes //input bool PeriodM15 = false; // 15 Minutes //input bool PeriodM30 = false; // 30 Minutes //input bool PeriodH1 = false; // 1 Hour //input bool PeriodH4 = false; // 4 Hours //input bool PeriodD1 = false; // 1 Day input int PeriodsCCI=6; input ENUM_APPLIED_PRICE AppliedPrice=PRICE_CLOSE; // CCI Applied Price //double ExtMapBuffer1[]; //double M1Buffer[]; double M5Buffer[]; //double M15Buffer[]; //double M30Buffer[]; //double H1Buffer[]; //double H4Buffer[]; //double D1Buffer[]; //int shiftArray[indicator_plots]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //SetIndexBuffer(0,M1Buffer); SetIndexBuffer(0,M5Buffer); /* SetIndexBuffer(2,M15Buffer); SetIndexBuffer(3,M30Buffer); SetIndexBuffer(4,H1Buffer); SetIndexBuffer(5,H4Buffer); SetIndexBuffer(6,D1Buffer); SetIndexLabel(0,"RSI(M1)"); SetIndexLabel(1,"RSI(M5)"); SetIndexLabel(2,"RSI(M15)"); SetIndexLabel(3,"RSI(M30)"); SetIndexLabel(4,"RSI(H1)"); SetIndexLabel(5,"RSI(H4)"); SetIndexLabel(6,"RSI(D1)"); SetIndexEmptyValue(0,EMPTY_VALUE); SetIndexEmptyValue(1,EMPTY_VALUE); SetIndexEmptyValue(2,EMPTY_VALUE); SetIndexEmptyValue(3,EMPTY_VALUE); SetIndexEmptyValue(4,EMPTY_VALUE); SetIndexEmptyValue(5,EMPTY_VALUE); SetIndexEmptyValue(6,EMPTY_VALUE); if(PeriodM1) SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,clrRed); else SetIndexStyle(0,DRAW_NONE); if(PeriodM5) SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,clrOrange); else SetIndexStyle(1,DRAW_NONE); if(PeriodM15) SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1,clrGold); else SetIndexStyle(2,DRAW_NONE); if(PeriodM30) SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1,clrLime); else SetIndexStyle(3,DRAW_NONE); if(PeriodH1) SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,1,clrAqua); else SetIndexStyle(4,DRAW_NONE); if(PeriodH4) SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,1,clrBlue); else SetIndexStyle(5,DRAW_NONE); if(PeriodD1) SetIndexStyle(6,DRAW_LINE,STYLE_SOLID,1,clrPurple); else SetIndexStyle(6,DRAW_NONE); IndicatorSetDouble(INDICATOR_MINIMUM,NULL); IndicatorSetDouble(INDICATOR_MAXIMUM,NULL); IndicatorSetInteger(INDICATOR_LEVELS,3); IndicatorSetDouble(INDICATOR_LEVELVALUE,0,300.0); IndicatorSetDouble(INDICATOR_LEVELVALUE, 1, 0.0); IndicatorSetDouble(INDICATOR_LEVELVALUE,2,-300.0); IndicatorDigits((int)MarketInfo(Symbol(),MODE_DIGITS)); string timeFrames=NULL; if(PeriodM1) timeFrames += (PeriodM1 ? "M1" : NULL); if(PeriodM5) timeFrames += (timeFrames == NULL ? "M5" : ",M5"); if(PeriodM15) timeFrames += (timeFrames == NULL ? "M15" : ",M15"); if(PeriodM30) timeFrames += (timeFrames == NULL ? "M30" : ",M30"); if(PeriodH1) timeFrames += (timeFrames == NULL ? "H1" : ",H1"); if(PeriodH4) timeFrames += (timeFrames == NULL ? "H4" : ",H4"); if(PeriodD1) timeFrames += (timeFrames == NULL ? "D1" : ",D1"); ArrayInitialize(shiftArray,0); */ if(!PeriodM5) SetIndexStyle(0,DRAW_NONE); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 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 &tick_volume[], const long &volume[], const int &spread[]) { int i,y,limit=0; datetime TimeArray[]; if(rates_total <= PeriodsCCI) return(0); if(prev_calculated==0) limit=rates_total-PeriodsCCI; /*if(prev_calculated>0) { limit+=(PeriodD1 ? PERIOD_D1 :(PeriodH4 ? PERIOD_H4 :(PeriodH1 ? PERIOD_H1 :(PeriodM30 ? PERIOD_M30 :(PeriodM15 ? PERIOD_M15 :(PeriodM5 ? PERIOD_M5 : PERIOD_M1)))))); } for(int i=0; i<limit; i++) { M1Buffer[i] = (PeriodM1 ? getCCI(shiftArray, 0, PERIOD_M1, time[i]) : EMPTY_VALUE); M5Buffer[i] = (PeriodM5 ? getCCI(shiftArray, 1, PERIOD_M5, time[i]) : EMPTY_VALUE); M15Buffer[i] = (PeriodM15 ? getCCI(shiftArray, 2, PERIOD_M15, time[i]) : EMPTY_VALUE); M30Buffer[i] = (PeriodM30 ? getCCI(shiftArray, 3, PERIOD_M30, time[i]) : EMPTY_VALUE); H1Buffer[i] = (PeriodH1 ? getCCI(shiftArray, 4, PERIOD_H1, time[i]) : EMPTY_VALUE); H4Buffer[i] = (PeriodH4 ? getCCI(shiftArray, 5, PERIOD_H4, time[i]) : EMPTY_VALUE); D1Buffer[i] = (PeriodD1 ? getCCI(shiftArray, 6, PERIOD_D1, time[i]) : EMPTY_VALUE); }*/ if(PeriodM5 && Period()<=PERIOD_M5) { ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),PERIOD_M5); if(prev_calculated>0) limit=rates_total-prev_calculated+(PERIOD_M5/Period()); for(i=0,y=0; i<=limit; i++) { if(time[i]<TimeArray[y]) y++; M5Buffer[i]=iCCI(Symbol(),PERIOD_M5,PeriodsCCI,AppliedPrice,y); } } return(rates_total); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ /* double getCCI(int &_array[],int _ind,int _tf,datetime _time) { datetime TimeArray[]; int i,limit,y=0,counted_bars=IndicatorCounted(); ArrayCopySeries(TimeArray, MODE_TIME, Symbol(), NULL); limit= Bars-1; for(i=0,y=0;i<limit;i++) { if(Time[i]<TimeArray[y]) y++; ExtMapBuffer1[i]=iCCI(Symbol(),NULL,PeriodsCCI,PRICE_CLOSE,y); } return(0); } */ //+------------------------------------------------------------------+

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Dear Coders,
I am Newbie here, learning mql4 coding, today i have mixed some indicators and created a MTF CCI indicator, It's not showing any error or warnings, and also not loading in MT4
please rectify it.