//+------------------------------------------------------------------+ //| TrendArea | //| mladen | //+------------------------------------------------------------------+ #property copyright "copyleft mladen" #property link "mladenfx@gmail.com" #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 Green #property indicator_color2 Red #property indicator_color3 DimGray #property indicator_width1 2 #property indicator_width2 2 #property indicator_style3 STYLE_DOT // // // // // extern int FastPeriod = 4; extern int SlowPeriod = 15; extern int MaMethod = MODE_SMMA; // // // // // double gBuffer[]; double rBuffer[]; double zBuffer[]; double tBuffer[]; double aBuffer[]; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int init() { IndicatorBuffers(5); SetIndexBuffer(0,gBuffer); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexBuffer(1,rBuffer); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexBuffer(2,zBuffer); SetIndexBuffer(3,tBuffer); SetIndexEmptyValue(3,0); SetIndexBuffer(4,aBuffer); SetIndexEmptyValue(4,0); // // // // // string ShortName; switch(MaMethod) { case 0 : ShortName="TrendArea sma ("; break; case 1 : ShortName="TrendArea ema ("; break; case 2 : ShortName="TrendArea smma ("; break; case 3 : ShortName="TrendArea lwma ("; } IndicatorShortName(ShortName+FastPeriod+","+SlowPeriod+")"); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int start() { int countedBars = IndicatorCounted(); int i,limit; if (countedBars<0) return(-1); if (countedBars>0) countedBars--; limit = MathMin(Bars-countedBars,Bars-1); // // // // // for(i = limit; i >=0; i--) { double fastMa = iMA(NULL,0,FastPeriod,0,MaMethod,PRICE_CLOSE,i); double slowMa = iMA(NULL,0,SlowPeriod,0,MaMethod,PRICE_CLOSE,i); double fastMp = iMA(NULL,0,FastPeriod,0,MaMethod,PRICE_CLOSE,i+1); double slowMp = iMA(NULL,0,SlowPeriod,0,MaMethod,PRICE_CLOSE,i+1); // // // // // bool cross = ((fastMa>slowMa && fastMp<slowMp) || (fastMa<slowMa && fastMp>slowMp)); if (cross) { tBuffer[i] = 1; aBuffer[i] = 0; } else { tBuffer[i] = tBuffer[i+1]; if (fastMa > slowMa) tBuffer[i] = tBuffer[i+1]+1; if (fastMa < slowMa) tBuffer[i] = tBuffer[i+1]-1; aBuffer[i] = aBuffer[i+1] + MathAbs(tBuffer[i])*MathAbs(fastMa-slowMa); } // // // // // zBuffer[i] = 0; gBuffer[i] = EMPTY_VALUE; rBuffer[i] = EMPTY_VALUE; if (tBuffer[i]>0) gBuffer[i] = aBuffer[i]; else rBuffer[i] = -aBuffer[i]; } // // // // // return(0); }
Sample
Analysis
Market Information Used:
Indicator Curves created:
Implements a curve of type DRAW_HISTOGRAM
Indicators Used:
Moving average indicator
Custom Indicators Used:
Order Management characteristics:
Other Features: