//+------------------------------------------------------------------+ //| Anchored momentum.mq4 | //| mladen | //| | //| developed by Rudy Stefenel | //| Technical analysis of Stoctks and Commodities (TASC) | //| february 1998 - article : "Anchored momentum" | //+------------------------------------------------------------------+ #property copyright "mladen" #property link "mladenfx@gmail.com" #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Green #property indicator_color2 DimGray #property indicator_width1 2 #property indicator_width2 2 // // // // // #define typeGeneral 0 #define typeMost 1 #define typeGeneralEma 2 #define typeMostEma 3 // // // // // extern int MomPeriod = 10; extern int EmaPeriod = 7; extern int SmaPeriod = 7; extern int MomentumType = typeGeneral; extern int AppliedPrice = PRICE_CLOSE; // // // // // double Momentum[]; double Momentul[]; double Buffers[]; double Buffere[]; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int init() { IndicatorBuffers(4); SetIndexBuffer(0,Momentum); SetIndexLabel(1,"Momentum"); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexBuffer(1,Momentul); SetIndexLabel(1,NULL); SetIndexBuffer(2,Buffers); SetIndexBuffer(3,Buffere); // // // // // MomPeriod = MathMax(SmaPeriod,MomPeriod); MomPeriod = MathMax(EmaPeriod,MomPeriod); MomentumType = MathMax(MathMin(MomentumType,3),0); string type; switch (MomentumType) { case typeGeneral : type = "General"; break; case typeGeneralEma : type = "General with EMA"; break; case typeMost : type = "Most"; break; case typeMostEma : type = "Most with EMA"; } IndicatorShortName(type+" ("+SmaPeriod+","+EmaPeriod+","+MomPeriod+")"); return(0); } int deinit() { return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int start() { int counted_bars = IndicatorCounted(); int i,limit; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; // // // // // for(i = limit; i >= 0; i--) { double price = iMA(NULL,0,1,0,MODE_SMA,AppliedPrice,i); int index; // // // // // switch (MomentumType) { case typeGeneral : index = i+(MomPeriod-((SmaPeriod-1)/2.00)); Buffers[i] = iMA(NULL,0,SmaPeriod,0,MODE_SMA,AppliedPrice,i); Momentum[i] = EMPTY_VALUE; if (Buffers[index] != 0) Momentum[i] = 100.00 * (price / Buffers[index] - 1.00); break; // // // // // case typeMost : Buffers[i] = iMA(NULL,0,2.00*MomPeriod+1,0,MODE_SMA,AppliedPrice,i); Momentum[i] = EMPTY_VALUE; if (Buffers[i] != 0) Momentum[i] = 100.00 * (price / Buffers[i] - 1.00); break; // // // // // case typeGeneralEma : index = i+(MomPeriod-((SmaPeriod-1)/2.00)); Buffers[i] = iMA(NULL,0,SmaPeriod,0,MODE_SMA,AppliedPrice,i); Buffere[i] = iMA(NULL,0,EmaPeriod,0,MODE_EMA,AppliedPrice,i); Momentum[i] = EMPTY_VALUE; if (Buffers[index] != 0) Momentum[i] = 100.00 * (Buffere[i] / Buffers[index] - 1.00); break; // // // // // case typeMostEma : Buffers[i] = iMA(NULL,0,2.00*MomPeriod+1,0,MODE_SMA,AppliedPrice,i); Buffere[i] = iMA(NULL,0,EmaPeriod,0,MODE_EMA,AppliedPrice,i); Momentum[i] = EMPTY_VALUE; if (Buffers[i] != 0) Momentum[i] = 100.00 * (Buffere[i] / Buffers[i] - 1.00); } Momentul[i] = Momentum[i]; } return(0); }