//+------------------------------------------------------------------+ //| Copyright 2012, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2012, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" #property indicator_separate_window #property indicator_buffers 6 #property indicator_plots 2 //--- plot up #property indicator_label1 "up" #property indicator_type1 DRAW_HISTOGRAM #property indicator_color1 clrGreen #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot dn #property indicator_label2 "dn" #property indicator_type2 DRAW_HISTOGRAM #property indicator_color2 clrRed #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot mov //--- input parameters input int dif=1; //--- indicator buffers double up[]; double dn[]; double mov[]; double trend[]; double wave[]; double vol[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,up,INDICATOR_DATA); SetIndexBuffer(1,dn,INDICATOR_DATA); SetIndexBuffer(2,mov,INDICATOR_CALCULATIONS); SetIndexBuffer(3,trend,INDICATOR_CALCULATIONS); SetIndexBuffer(4,wave,INDICATOR_CALCULATIONS); SetIndexBuffer(5,vol,INDICATOR_CALCULATIONS); ArraySetAsSeries(mov, true); ArraySetAsSeries(trend, true); ArraySetAsSeries(wave, true); ArraySetAsSeries(vol, true); ArraySetAsSeries(up, true); ArraySetAsSeries(dn, true); //--- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { /* First time prev_calculated = 0 or Bars or Bars - 1 */ //--- int limit, i; //--- if(prev_calculated<0) return(-1); //---- if(prev_calculated>0) limit=rates_total - prev_calculated; else limit=rates_total - 1; /* First time limit = rates_total -1 after limit = 1 or 2 */ mov[limit]=0; trend[limit]=0; wave[limit]=0; vol[limit]=0; up[limit]=0; dn[limit]=0; ArraySetAsSeries(close, true); for(i=limit-1; i>=0; i--) { if (close[i]-close[i+1]>0) mov[i]=1; if (close[i]-close[i+1]==0) mov[i]=0; if (close[i]-close[i+1]<0) mov[i]=-1; if ((mov[i]!=0) && (mov[i]!=mov[i+1])) {trend[i]=mov[i];} else {trend[i]=trend[i+1];} if ((trend[i]!=wave[i+1]) && (MathAbs(close[i]-close[i+1])*10000>=dif)) {wave[i]=trend[i];} else {wave[i]=wave[i+1];} if (wave[i]==wave[i+1]) {vol[i]=vol[i+1]+volume[i];} else {vol[i]=volume[i];} if (wave[i]==1) {up[i]=vol[i]; dn[i]=0;} if (wave[i]==-1) {dn[i]=vol[i]; up[i]=0;} } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+