Time: 2016-10-14 | Download file:T3MA_ribbon_filled_simple_&_mtf.mq4
//+------------------------------------------------------------------+ //| MA ribbon.mq4 | //| mladenfx@gmail.com | //| | //| original idea by Jose Silva | //+------------------------------------------------------------------+ #property copyright "mladen" #property link "mladenfx@gmail.com" #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 C'0,70,0' #property indicator_color2 C'70,0,0' #property indicator_color3 Red #property indicator_color4 Green #property indicator_width1 3 #property indicator_width2 3 #property indicator_width3 2 #property indicator_width4 2 // // // // // extern string TimeFrame = "Current time frame"; extern int T3Period1 = 13; extern double T3Hot1 = 0.7; extern int T3Price1 = PRICE_CLOSE; extern bool T3Original1 = true; extern int T3Period2 = 20; extern double T3Hot2 = 0.6; extern int T3Price2 = PRICE_CLOSE; extern bool T3Original2 = true; extern bool Interpolate = true; // // // // // double buffer1[]; double buffer2[]; double buffer3[]; double buffer4[]; double emas[][12]; double alpha1,alpha2; double c11,c12,c13,c14; double c21,c22,c23,c24; // // // // // string indicatorFileName; bool calculateValue; bool returnBars; int timeFrame; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int init() { SetIndexBuffer(0,buffer3); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexBuffer(1,buffer4); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexBuffer(2,buffer1); SetIndexBuffer(3,buffer2); // // // // // double a = T3Hot1; c11 = -a*a*a; c12 = 3*(a*a+a*a*a); c13 = -3*(2*a*a+a+a*a*a); c14 = 1+3*a+a*a*a+3*a*a; if (T3Original1) alpha1 = 2.0/(1.0 + T3Period1); else alpha1 = 2.0/(2.0 + (T3Period1-1.0)/2.0); // // // // // a = T3Hot2; c21 = -a*a*a; c22 = 3*(a*a+a*a*a); c23 = -3*(2*a*a+a+a*a*a); c24 = 1+3*a+a*a*a+3*a*a; if (T3Original2) alpha2 = 2.0/(1.0 + T3Period2); else alpha2 = 2.0/(2.0 + (T3Period2-1.0)/2.0); // // // // // indicatorFileName = WindowExpertName(); calculateValue = (TimeFrame=="calculateValue"); if (calculateValue) return(0); returnBars = (TimeFrame=="returnBars"); if (returnBars) return(0); timeFrame = stringToTimeFrame(TimeFrame); IndicatorShortName(timeFrameToString(timeFrame)+" T3 ribbon"); return(0); } int deinit() { return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int start() { int limit,i,counted_bars=IndicatorCounted(); if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit=MathMin(Bars-counted_bars,Bars-1); if (returnBars) { buffer3[0] = limit+1; return(0); } // // // // // if (calculateValue || timeFrame == Period()) { if (ArrayRange(emas,0) != Bars) ArrayResize(emas,Bars); for(i=limit; i>=0; i--) { buffer1[i] = iT3(iMA(NULL,0,1,0,MODE_SMMA,T3Price1,i),i,0,c11,c12,c13,c14,alpha1); buffer2[i] = iT3(iMA(NULL,0,1,0,MODE_SMMA,T3Price2,i),i,6,c21,c22,c23,c24,alpha2); buffer3[i] = buffer1[i]; buffer4[i] = buffer2[i]; } return(0); } // // // // // limit = MathMax(limit,MathMin(Bars,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period())); for (i=limit;i>=0;i--) { int y = iBarShift(NULL,timeFrame,Time[i]); buffer1[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",T3Period1,T3Hot1,T3Price1,T3Original1,T3Period2,T3Hot2,T3Price2,T3Original2,2,y); buffer2[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",T3Period1,T3Hot1,T3Price1,T3Original1,T3Period2,T3Hot2,T3Price2,T3Original2,3,y); buffer3[i] = buffer1[i]; buffer4[i] = buffer2[i]; // // // // // if (!Interpolate || y==iBarShift(NULL,timeFrame,Time[i-1])) continue; // // // // // datetime time = iTime(NULL,timeFrame,y); for(int n = 1; i+n < Bars && Time[i+n] >= time; n++) continue; for(int k = 1; k < n; k++) { buffer1[i+k] = buffer1[i] + (buffer1[i+n]-buffer1[i])*k/n; buffer2[i+k] = buffer2[i] + (buffer2[i+n]-buffer2[i])*k/n; buffer3[i+k] = buffer1[i+k]; buffer4[i+k] = buffer2[i+k]; } } // // // // // return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // double iT3(double price, int shift,int buffer, double c1, double c2, double c3, double c4,double alpha) { int i = Bars-shift-1; if (i < 1) { emas[i][0+buffer] = price; emas[i][1+buffer] = price; emas[i][2+buffer] = price; emas[i][3+buffer] = price; emas[i][4+buffer] = price; emas[i][5+buffer] = price; } else { emas[i][0+buffer] = emas[i-1][0+buffer]+alpha*(price -emas[i-1][0+buffer]); emas[i][1+buffer] = emas[i-1][1+buffer]+alpha*(emas[i][0+buffer]-emas[i-1][1+buffer]); emas[i][2+buffer] = emas[i-1][2+buffer]+alpha*(emas[i][1+buffer]-emas[i-1][2+buffer]); emas[i][3+buffer] = emas[i-1][3+buffer]+alpha*(emas[i][2+buffer]-emas[i-1][3+buffer]); emas[i][4+buffer] = emas[i-1][4+buffer]+alpha*(emas[i][3+buffer]-emas[i-1][4+buffer]); emas[i][5+buffer] = emas[i-1][5+buffer]+alpha*(emas[i][4+buffer]-emas[i-1][5+buffer]); } return(c1*emas[i][5+buffer] + c2*emas[i][4+buffer] + c3*emas[i][3+buffer] + c4*emas[i][2+buffer]); } //+------------------------------------------------------------------- //| //+------------------------------------------------------------------- // // // // // string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"}; int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200}; // // // // // int stringToTimeFrame(string tfs) { tfs = stringUpperCase(tfs); for (int i=ArraySize(iTfTable)-1; i>=0; i--) if (tfs==sTfTable[i] || tfs==""+iTfTable[i]) return(MathMax(iTfTable[i],Period())); return(Period()); } string timeFrameToString(int tf) { for (int i=ArraySize(iTfTable)-1; i>=0; i--) if (tf==iTfTable[i]) return(sTfTable[i]); return(""); } // // // // // string stringUpperCase(string str) { string s = str; for (int length=StringLen(str)-1; length>=0; length--) { int char1 = StringGetChar(s, length); if((char1 > 96 && char1 < 123) || (char1 > 223 && char1 < 256)) s = StringSetChar(s, length, char1 - 32); else if(char1 > -33 && char1 < 0) s = StringSetChar(s, length, char1 + 224); } return(s); }