//+------------------------------------------------------------------+ //| TrendPower.mq4 | //| Copyright © 2004, MetaQuotes Software Corp. | //| http://www.metaquotes.net/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2004, MetaQuotes Software Corp." #property link "http://www.metaquotes.net/" #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Red //---- input parameters extern int ADXPeriod = 14; extern int SMAfast = 5; extern int SMAslow = 14; extern int ma_method = MODE_EMA; int shift = 0, MAType = 1, cnt = 0, prevbars = 0,loopbegin = 0; double sum = 0, smconst = 0, prev = 0, weight = 0, linear = 0,IFish = 0,MAValue = 0; double signal = 0,noise = 0,efRatio = 0,i = 0, Fastest = 0.6667, Slowest = 0.0645; bool first = true; //---- buffers double TrendBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { IndicatorBuffers(1); SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,Red); SetIndexDrawBegin(0,ADXPeriod); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)); SetIndexBuffer(0,TrendBuffer); IndicatorShortName("TrendPower("+SMAfast+")"); return(0); } //+------------------------------------------------------------------+ //| Average Directional Movement Index | //+------------------------------------------------------------------+ int start() { // initial checkings // check for additional bars loading or total reloading if (Bars < prevbars) first = true; if (Bars-prevbars>1) first = true; prevbars = Bars; if (first) { // loopbegin prevent couning of counted bars exclude current loopbegin = Bars-SMAslow-1; if (loopbegin < 0) return(0); // not enough bars for counting first = False; } loopbegin++; // Comment( loopbegin); // current bar is to be recounted too for (shift = loopbegin; shift>= 0 ;shift--) { MAValue = 100 * (iMA(NULL,0,SMAfast,0,ma_method,PRICE_CLOSE,shift) - iMA(NULL,0,SMAslow,0,ma_method,PRICE_CLOSE,shift)) * iATR(NULL,0,SMAfast,shift) / iMA(NULL,0,SMAslow,0,ma_method,PRICE_CLOSE,shift) / iATR(NULL,0,SMAslow,shift); IFish = (MathExp(2*MAValue)-1)/(MathExp(2*MAValue)+1); TrendBuffer[shift] = IFish * 100; loopbegin = loopbegin-1; } }