//+------------------------------------------------------------------+ //| Velocity_v1.mq4 | //| Copyright © 2005, TrendLaboratory Ltd. | //| http://finance.groups.yahoo.com/group/TrendLaboratory | //| E-mail: igorad2004@list.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2005, TrendLaboratory Ltd." #property link "http://finance.groups.yahoo.com/group/TrendLaboratory" #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 LightBlue #property indicator_color2 Red //---- input parameters extern int VelocityPeriod=8; extern int Slow=5; //---- indicator buffers double FastBuffer[]; double SlowBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { string short_name; //---- indicator line SetIndexStyle(0,DRAW_LINE); SetIndexStyle(1,DRAW_LINE,STYLE_DOT); SetIndexBuffer(0,FastBuffer); SetIndexBuffer(1,SlowBuffer); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)); //---- name for DataWindow and indicator subwindow label short_name="Velocity("+VelocityPeriod+","+Slow+")"; IndicatorShortName(short_name); SetIndexLabel(0,"Fast"); SetIndexLabel(1,"Slow"); //---- SetIndexDrawBegin(0,VelocityPeriod); SetIndexDrawBegin(1,Slow); //---- return(0); } //+------------------------------------------------------------------+ //| Velocity_v1 | //+------------------------------------------------------------------+ int start() { int shift; double Vel,Vel1,Vel2,AvgVel,AvgVel1,AvgVel2,AvgVel21; for(shift=Bars-1-VelocityPeriod;shift>=0;shift--) { Vel1=Vel; AvgVel1=AvgVel; AvgVel21=AvgVel2; Vel=(Close[shift]-Close[shift+1])/Point; AvgVel=AvgVel1+2.0/(1.0+VelocityPeriod)*(Vel-AvgVel1); AvgVel2=AvgVel21+2.0/(1.0+VelocityPeriod)*(AvgVel-AvgVel21); FastBuffer[shift]=FastBuffer[shift+1]+2.0/(1.0+VelocityPeriod)*(AvgVel2-FastBuffer[shift+1]); SlowBuffer[shift]=SlowBuffer[shift+1]+2.0/(Slow+1.0)*(FastBuffer[shift]-SlowBuffer[shift+1]); } return(0); }