//+------------------------------------------------------------------+ //| Disparity Index.mq4 | //| Linuxser | //| contact me in Forex TSD | //+------------------------------------------------------------------+ #property copyright "www.forex-station.com" #property link "www.forex-station.com" #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 clrDodgerBlue #property indicator_color2 clrRed #property indicator_color3 clrRed #property indicator_width1 3 #property indicator_width2 3 #property indicator_width3 3 #property indicator_levelcolor clrDarkSlateGray #property indicator_level1 0 #property strict input int DispPeriod = 13; // Disparity period input ENUM_MA_METHOD MaMethod = MODE_EMA; // Disparity ma method input ENUM_APPLIED_PRICE Price = PRICE_CLOSE; // Disparity price //---- buffers double val[],valDa[],valDb[],valc[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { IndicatorBuffers(4); SetIndexBuffer(0,val, INDICATOR_DATA); SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(1,valDa,INDICATOR_DATA); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(2,valDb,INDICATOR_DATA); SetIndexStyle(2,DRAW_LINE); SetIndexBuffer(3,valc, INDICATOR_CALCULATIONS); IndicatorShortName("Disparity Index(" + (string)DispPeriod + ")"); //---- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 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[]) { int i,counted_bars=prev_calculated; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; int limit = fmin(rates_total-counted_bars,rates_total-1); // // // // // if (valc[limit]==-1) CleanPoint(limit,valDa,valDb); for(i=limit; i>=0; i--) { double ma = iMA(NULL,0,DispPeriod,0,MaMethod,Price,i); val[i] = (ma>0.0) ? 100*(close[i]-ma)/ma : 0; valDa[i] = EMPTY_VALUE; valDb[i] = EMPTY_VALUE; valc[i] = (ival[i+1]) ? 1 : (val[i]=Bars-3) return; if ((second[i] != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE)) second[i+1] = EMPTY_VALUE; else if ((first[i] != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE)) first[i+1] = EMPTY_VALUE; } void PlotPoint(int i,double& first[],double& second[],double& from[]) { if (i>=Bars-2) return; if (first[i+1] == EMPTY_VALUE) if (first[i+2] == EMPTY_VALUE) { first[i] = from[i]; first[i+1] = from[i+1]; second[i] = EMPTY_VALUE; } else { second[i] = from[i]; second[i+1] = from[i+1]; first[i] = EMPTY_VALUE; } else { first[i] = from[i]; second[i] = EMPTY_VALUE; } }