//+------------------------------------------------------------------+ //| A coding error.mq4 | //| mladen | //+------------------------------------------------------------------+ #property copyright "mladen" #property link "mladenfx@gmail.com" #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 DarkOrange #property indicator_levelcolor DimGray // // // // // extern int Length = 35; extern int Price = PRICE_CLOSE; extern double LevelHigh = 80; extern double LevelLow = 20; extern int T3Period = 5; extern double T3Hot = 0.7; extern bool T3Original = false; // // // // // double Trend[]; double values[][7]; double alpha; double c1; double c2; double c3; double c4; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int init() { SetIndexBuffer(0,Trend); SetIndexLabel(0,"Trend"); // // // // // LevelHigh = MathMin(MathMax(LevelHigh,0),100); LevelLow = MathMin(MathMax(LevelLow,0) ,100); if (LevelHigh<LevelLow) { double temp = LevelHigh; LevelHigh = LevelLow; LevelLow = temp; } // // // // // double a = T3Hot; c1 = -a*a*a; c2 = 3*(a*a+a*a*a); c3 = -3*(2*a*a+a+a*a*a); c4 = 1+3*a+a*a*a+3*a*a; T3Period = MathMax(1,T3Period); if (T3Original) alpha = 2.0/(1.0 + T3Period); else alpha = 2.0/(2.0 + (T3Period-1.0)/2.0); // // // // // SetLevelValue(0,LevelHigh); SetLevelValue(1,LevelLow); SetLevelValue(2,100); SetLevelValue(3,0); return(0); } int deinit() { return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // #define prices 0 #define T3_start 1 // // // // // int start() { int counted_bars=IndicatorCounted(); int i,r,limit; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit = MathMin(Bars-counted_bars,Bars-Length); if (ArrayRange(values,0) != Bars) ArrayResize(values,Bars); // // // // // for(i=limit, r=Bars-limit-1; i>=0; i--,r++) { values[r][prices] = iMA(NULL,0,1,0,MODE_SMA,Price,i); // // // // // double momentum = values[r][prices]-values[r-Length][prices]; double sumUpDi = 0; double sumDnDi = 0; for(int j=1; j<Length; j++) { double gradient = values[r][prices]+momentum*j/(Length); double deviation = gradient-values[r-j][prices]; if (deviation > 0) sumUpDi += deviation; else sumDnDi -= deviation; } // // // // // if ((sumUpDi+sumDnDi)!=0) double tTrend = 100.0*sumUpDi/(sumUpDi+sumDnDi); else tTrend = 0; if (T3Period>1) Trend[i] = iT3(tTrend,r,T3_start); else Trend[i] = tTrend; } return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // double iT3(double price,int i,int s) { if (i < 1) { values[i][s+0] = price; values[i][s+1] = price; values[i][s+2] = price; values[i][s+3] = price; values[i][s+4] = price; values[i][s+5] = price; } else { values[i][s+0] = values[i-1][s+0]+alpha*(price -values[i-1][s+0]); values[i][s+1] = values[i-1][s+1]+alpha*(values[i][s+0]-values[i-1][s+1]); values[i][s+2] = values[i-1][s+2]+alpha*(values[i][s+1]-values[i-1][s+2]); values[i][s+3] = values[i-1][s+3]+alpha*(values[i][s+2]-values[i-1][s+3]); values[i][s+4] = values[i-1][s+4]+alpha*(values[i][s+3]-values[i-1][s+4]); values[i][s+5] = values[i-1][s+5]+alpha*(values[i][s+4]-values[i-1][s+5]); } return(c1*values[i][s+5] + c2*values[i][s+4] + c3*values[i][s+3] + c4*values[i][s+2]); }
Sample
Analysis
Market Information Used:
Indicator Curves created:
Indicators Used:
Moving average indicator
Custom Indicators Used:
Order Management characteristics:
Other Features: