//+------------------------------------------------------------------+ //| UpDnVol.mq5 | //| Copyright 2015, fxborg | //| http://blog.livedoor.jp/fxborg/ | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, fxborg" #property link "http://blog.livedoor.jp/fxborg/" #property version "1.00" #property indicator_separate_window #property indicator_buffers 5 #property indicator_plots 2 #property indicator_type1 DRAW_HISTOGRAM #property indicator_type2 DRAW_HISTOGRAM #property indicator_color1 DodgerBlue #property indicator_color2 Red int CalcBars=10; #define DIR_UP 1.0 #define DIR_DOWN 2.0 #define DIR_NONE 0.0 #property indicator_width1 4 #property indicator_width2 4 #property indicator_width3 2 double VolUpBuffer[]; double VolDnBuffer[]; double VolColBuffer[]; double TrBuffer[]; double DirBuffer[]; double TimeBuffer[]; //---- declaration of global variables int min_rates_total; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //---- Initialization of variables of data calculation starting point min_rates_total=CalcBars+2; //--- indicator buffers mapping SetIndexBuffer(0,VolUpBuffer,INDICATOR_DATA); SetIndexBuffer(1,VolDnBuffer,INDICATOR_DATA); SetIndexBuffer(2,DirBuffer,INDICATOR_COLOR_INDEX); SetIndexBuffer(3,TimeBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(4,TrBuffer,INDICATOR_CALCULATIONS); //--- set drawing line empty value PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0); PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0); PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,0); PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,0); PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); //--- 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,j,first; //--- check for bars count if(rates_total<=min_rates_total) return(0); //--- first=2; if(first+10) first=prev_calculated-2; else { for(i=0; i(high[i]-low[i])) { DirBuffer[i]=DirBuffer[i-1]; return; } if(atr*1.2dn1+dn0) { if(DirBuffer[i-1]==DIR_UP && up1>dn1 && up0up1 && dn0