Attachments forums

List of attachments posted on this forum.


All files on forums: 72766

Re: Trying to make an indicator MTF

mladen, Mon Feb 27, 2017 2:21 am

Xronos__ wrote:(I have no prior experience with mql so forgive me if this is funny for you)

Trying to make this ind mtf with no success

I have the suspicion that the error is at limit var and the way it is calculated ,
because the way it is currently coded is referring to the current timeframe and doesn't take into account the selected timeframe...

Code: Select all

 #property indicator_chart_window #property indicator_buffers 3 #property indicator_color1 Blue #property indicator_color2 Red #property indicator_color3 Red //---- input parameters extern int TYPE = 2, PERIOD = 16, FAST = 8, SLOW = 21; extern ENUM_TIMEFRAMES ATimeFrame = PERIOD_CURRENT; //---- indicator buffers double Buffer1[], Buffer2[], Buffer3[]; double slope[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { string name; switch(TYPE) { case 1: name =ATimeFrame+"1("+PERIOD+")"; break; case 2: name = ATimeFrame+"2("+PERIOD+","+FAST+"-"+SLOW+")"; break; case 3: name = ATimeFrame+"3("+PERIOD+","+FAST+"/"+SLOW+")"; break; default: name = ATimeFrame+"4("+PERIOD+")"; break; } IndicatorBuffers(4); IndicatorShortName(name); SetIndexBuffer(0,Buffer1); SetIndexLabel(0,name); SetIndexBuffer(1,Buffer2); SetIndexLabel(1,name); SetIndexBuffer(2,Buffer3); SetIndexLabel(2,name); SetIndexBuffer(3,slope); return(0); } //+------------------------------------------------------------------+ double FractalDimension(int i) { double N3 = (High[iHighest(NULL,ATimeFrame,MODE_HIGH,PERIOD,i)] -Low [iLowest (NULL,ATimeFrame,MODE_LOW,PERIOD,i)])/PERIOD, N1 = (High[iHighest(NULL,ATimeFrame,MODE_HIGH,PERIOD/2,i)] -Low [iLowest (NULL,ATimeFrame,MODE_LOW, PERIOD/2,i)]) / (PERIOD/2), N2 = (High[iHighest(NULL,ATimeFrame,MODE_HIGH,PERIOD/2,i+PERIOD/2)] -Low [iLowest (NULL,ATimeFrame,MODE_LOW, PERIOD/2,i+PERIOD/2)]) / (PERIOD/2); if(N1 > 0 && N2 > 0 && N3 > 0) return((MathLog(N1+N2) - MathLog(N3)) / MathLog(2.0)); return(0); } //+------------------------------------------------------------------+ double EfficencyRatio(int i = 0) { double noise = 0.0; double signal = MathAbs(iClose(Symbol(),ATimeFrame,iBarShift(Symbol(),ATimeFrame,Time[i])) - iClose(Symbol(),ATimeFrame,iBarShift(Symbol(),ATimeFrame,Time[i+PERIOD]))); for(int n = 0; n < PERIOD; n++) noise += MathAbs(iClose(Symbol(),ATimeFrame,iBarShift(Symbol(),ATimeFrame,Time[i+n])) - iClose(Symbol(),ATimeFrame,iBarShift(Symbol(),ATimeFrame,Time[i+n+1]))); if(noise>0.0) return(signal/noise); else return(EMPTY_VALUE); } //+------------------------------------------------------------------+ double StdDevRatio(int i = 0) { double shortStdDev = iStdDev(Symbol(),ATimeFrame,FAST,0,MODE_EMA,PRICE_CLOSE,iBarShift(Symbol(),ATimeFrame,Time[i])), longStdDev = iStdDev(Symbol(),ATimeFrame,SLOW, 0,MODE_EMA,PRICE_CLOSE,iBarShift(Symbol(),ATimeFrame,Time[i])); if (longStdDev!=0) return(shortStdDev/longStdDev); else return(1); } //+------------------------------------------------------------------+ int start() { double emaWeight = 2.0 / (PERIOD+1.0); int counted_bars=IndicatorCounted( ); if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; int limit = MathMin(Bars-counted_bars,Bars-1); if (slope[limit]==-1) CleanPoint(limit,Buffer2,Buffer3); for(int i=limit; i>=0; i--) { double adaptiveWeight; switch(TYPE) { case 1: { adaptiveWeight = MathExp(-4.6 * (FractalDimension(i)-1.0)); break; } case 2: { double slowestWeight = 2.0 / (SLOW+1.0), fastestWeight = 2.0 / (FAST+1.0); adaptiveWeight = EfficencyRatio(i)*fastestWeight + slowestWeight; adaptiveWeight *= adaptiveWeight; break; } case 3: { adaptiveWeight = StdDevRatio(i)*emaWeight; break; } default: adaptiveWeight = emaWeight; } Buffer1[i] = adaptiveWeight*iClose(Symbol(),ATimeFrame,iBarShift(Symbol(),ATimeFrame,Time[i])) + (1.0-adaptiveWeight)*Buffer1[i+1]; Buffer2[i] = EMPTY_VALUE; Buffer3[i] = EMPTY_VALUE; slope[i] = slope[i+1]; if (Buffer1[i] > Buffer1[i+1]) slope[i] = 1; if (Buffer1[i] < Buffer1[i+1]) slope[i] = -1; if (slope[i]==-1) PlotPoint(i,Buffer2,Buffer3,Buffer1); } return(0); } void CleanPoint(int i,double& first[],double& second[]) { if ((second[i] != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE)) second[i+1] = EMPTY_VALUE; else if ((first[i] != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE)) first[i+1] = EMPTY_VALUE; } void PlotPoint(int i,double& first[],double& second[],double& from[]) { if (first[i+1] == EMPTY_VALUE) { if (first[i+2] == EMPTY_VALUE) { first[i] = from[i]; first[i+1] = from[i+1]; second[i] = EMPTY_VALUE; } else { second[i] = from[i]; second[i+1] = from[i+1]; first[i] = EMPTY_VALUE; } } else { first[i] = from[i]; second[i] = EMPTY_VALUE; } }
I would appreciate any assistance on this or a fix, if possible, to study it... you could save me some time from searching on the net without knowing what to look for

Thanks in advance

Try the attached
_test.mq4
(13.7 KiB) Downloaded 308 times
All files in topic