Migrate QQE ADV from MT4 to MT5, need help!
Hey everyone,
The QQE ADV is an awesome indicator to use when developing EA's. I have the mt5 version, but only the ex4 file, and with every update the indi won't work because it needs to be recompiled.
Anyways see attached for the mq4 file, I tried to convert but it won't work I just don't get the indicator to work! Not sure what to do with the iMAOnArray function being used
Any input would be greatly appreciated
Ok, I have tried my best and this is what I came up with, but it does not work:
//+------------------------------------------------------------------+ //| QQE ADV-New.mq5 | //| Copyright 2010, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2010, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property indicator_separate_window #property indicator_plots 2 #include <Mocke.mqh> #property indicator_buffers 2 #property indicator_color1 Navy #property indicator_style1 STYLE_SOLID #property indicator_width1 2 #property indicator_color2 Navy #property indicator_style2 STYLE_DOT input int SF = 1; input int RSI_Period = 8; input int DARFACTOR=3; int Wilders_Period; int StartBar; double TrLevelSlow[]; double AtrRsi[]; double MaAtrRsi[]; double Rsi[]; double RsiMa[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping Wilders_Period = RSI_Period * 2 - 1; if (Wilders_Period < SF) StartBar = SF; else StartBar = Wilders_Period; SetIndexBuffer(0, RsiMa,INDICATOR_DATA); SetIndexBuffer(1, TrLevelSlow,INDICATOR_DATA); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,StartBar); SetIndexBuffer(2, AtrRsi,INDICATOR_CALCULATIONS); SetIndexBuffer(3, MaAtrRsi,INDICATOR_CALCULATIONS); SetIndexBuffer(4, Rsi,INDICATOR_CALCULATIONS); ArraySetAsSeries(TrLevelSlow,true); ArraySetAsSeries(AtrRsi,true); ArraySetAsSeries(MaAtrRsi,true); ArraySetAsSeries(Rsi,true); ArraySetAsSeries(RsiMa,true); // IndicatorSetString(INDICATOR_SHORTNAME,StringConcatenate("QQE(", SF, ")")); //--- 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& tick_volume[], const long& volume[], const int& spread[]) { //--- int counted, i; double rsi0, rsi1, dar, tr, dv; if(Bars(_Symbol,0) <= StartBar) return (0); counted = IndicatorCountedMQL4(prev_calculated); if(counted < 1) for(i = Bars(_Symbol,0) - StartBar; i < Bars(_Symbol,0); i++) { TrLevelSlow[i] = 0.0; AtrRsi[i] = 0.0; MaAtrRsi[i] = 0.0; Rsi[i] = 0.0; RsiMa[i] = 0.0; } counted = Bars(_Symbol,0) - counted - 1; for (i = counted; i >= 0; i--) Rsi[i] = iRSIMQL4(_Symbol, 0, RSI_Period, PRICE_CLOSE, i); for (i = counted; i >= 0; i--) { RsiMa[i] = iMAOnArray(Rsi, 0, SF, 0, MODE_EMA, i); AtrRsi[i] = MathAbs(RsiMa[i + 1] - RsiMa[i]); } for (i = counted; i >= 0; i--) MaAtrRsi[i] = iMAOnArray(AtrRsi, 0, Wilders_Period, 0, MODE_EMA, i); i = counted + 1; tr = TrLevelSlow[i]; rsi1 = iMAOnArray(Rsi, 0, SF, 0, MODE_EMA, i); while (i > 0) { i--; rsi0 = iMAOnArray(Rsi, 0, SF, 0, MODE_EMA, i); dar = iMAOnArray(MaAtrRsi, 0, Wilders_Period, 0, MODE_EMA, i) * DARFACTOR; dv = tr; if (rsi0 < tr) { tr = rsi0 + dar; if (rsi1 < dv) if (tr > dv) tr = dv; } else if (rsi0 > tr) { tr = rsi0 - dar; if (rsi1 > dv) if (tr < dv) tr = dv; } TrLevelSlow[i] = tr; rsi1 = rsi0; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
And the functions:
double CopyBufferMQL4(int handle,int index,int shift) { double buf[]; switch(index) { case 0: if(CopyBuffer(handle,0,shift,1,buf)>0) return(buf[0]); break; case 1: if(CopyBuffer(handle,1,shift,1,buf)>0) return(buf[0]); break; case 2: if(CopyBuffer(handle,2,shift,1,buf)>0) return(buf[0]); break; case 3: if(CopyBuffer(handle,3,shift,1,buf)>0) return(buf[0]); break; case 4: if(CopyBuffer(handle,4,shift,1,buf)>0) return(buf[0]); break; default: break; } return(EMPTY_VALUE); } double iMAOnArray(double &array[], int total, int period, int ma_shift, int ma_method, int shift) { double buf[],arr[]; if(total==0) total=ArraySize(array); if(total>0 && total<=period) return(0); if(shift>total-period-ma_shift) return(0); switch(ma_method) { case MODE_SMA : { total=ArrayCopy(arr,array,0,shift+ma_shift,period); if(ArrayResize(buf,total)<0) return(0); double sum=0; int i,pos=total-1; for(i=1;i<period;i++,pos--) sum+=arr[pos]; while(pos>=0) { sum+=arr[pos]; buf[pos]=sum/period; sum-=arr[pos+period-1]; pos--; } return(buf[0]); } case MODE_EMA : { if(ArrayResize(buf,total)<0) return(0); double pr=2.0/(period+1); int pos=total-2; while(pos>=0) { if(pos==total-2) buf[pos+1]=array[pos+1]; buf[pos]=array[pos]*pr+buf[pos+1]*(1-pr); pos--; } return(buf[shift+ma_shift]); } case MODE_SMMA : { if(ArrayResize(buf,total)<0) return(0); double sum=0; int i,k,pos; pos=total-period; while(pos>=0) { if(pos==total-period) { for(i=0,k=pos;i<period;i++,k++) { sum+=array[k]; buf[k]=0; } } else sum=buf[pos+1]*(period-1)+array[pos]; buf[pos]=sum/period; pos--; } return(buf[shift+ma_shift]); } case MODE_LWMA : { if(ArrayResize(buf,total)<0) return(0); double sum=0.0,lsum=0.0; double price; int i,weight=0,pos=total-1; for(i=1;i<=period;i++,pos--) { price=array[pos]; sum+=price*i; lsum+=price; weight+=i; } pos++; i=pos+period; while(pos>=0) { buf[pos]=sum/weight; if(pos==0) break; pos--; i--; price=array[pos]; sum=sum-lsum+price*period; lsum-=array[i]; lsum+=price; } return(buf[shift+ma_shift]); } default: return(0); } return(0); } int IndicatorCountedMQL4(int prev_calculated) { if(prev_calculated>0) return(prev_calculated-1); if(prev_calculated==0) return(0); return(0); } double iRSIMQL4(string symbol, ENUM_TIMEFRAMES tf, int period, ENUM_APPLIED_PRICE price, int shift) { int handle=iRSI(symbol,tf,period,price); if(handle<0) { Print("The iRSI object is not created: Error",GetLastError()); return(-1); } else return(CopyBufferMQL4(handle,0,shift)); }
Hey everyone,
The QQE ADV is an awesome indicator to use when developing EA's. I have the mt5 version, but only the ex4 file, and with every update the indi won't work because it needs to be recompiled.
Anyways see attached for the mq4 file, I tried to convert but it won't work I just don't get the indicator to work! Not sure what to do with the iMAOnArray function being used
Any input would be greatly appreciated