//+------------------------------------------------------------------+ //| TriangularMA centered.mq4 | //| mladen | //+------------------------------------------------------------------+ #property copyright "mladen" #property link "mladenfx@gmail.com" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 LimeGreen // // // // // extern int HalfLength = 12; extern int Price = PRICE_CLOSE; // // // // // double buffer1[]; double weights[]; double sumWeights=0; int fullLength; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // int init() { HalfLength=MathMax(HalfLength,1); fullLength = HalfLength*2+1; ArrayResize(weights,fullLength); // // // // // sumWeights = HalfLength+1; weights[HalfLength] = HalfLength+1; for (int i=0; i<HalfLength; i++) { weights[i] = i+1; weights[fullLength-i-1] = i+1; sumWeights += i+i+2; } SetIndexBuffer(0,buffer1); SetIndexDrawBegin(0,HalfLength); return(0); } int deinit() { return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int start() { double sum,sumw; int counted_bars=IndicatorCounted(); int i,j,k,limit; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; // // // // // for (i=limit;i>=0;i--) { for(sum=0.0, j=0; j<fullLength; j++) sum += iMA(NULL,0,1,0,MODE_SMA,Price,i+j)*weights[j]; buffer1[i+HalfLength] = sum/sumWeights; } for (i=HalfLength-1;i>=0;i--) { sum = (HalfLength+1)*iMA(NULL,0,1,0,MODE_SMA,Price,i); sumw = (HalfLength+1); // // // // // for(j=1,k=HalfLength; j<HalfLength; j++,k--) { sum += iMA(NULL,0,1,0,MODE_SMA,Price,i+j)*k; sumw += k; if (j<=i) { sum += iMA(NULL,0,1,0,MODE_SMA,Price,i-j)*k; sumw += k; } } buffer1[i] = sum/sumw; } // // // // // return(0); }
Sample
Analysis
Market Information Used:
Indicator Curves created:
Indicators Used:
Moving average indicator
Custom Indicators Used:
Order Management characteristics:
Other Features: