//+------------------------------------------------------------------+ //| BSI.mq4 | //| Copyright 2015, fxborg. | //| http://blog.livedoor.jp/fxborg/ | //+------------------------------------------------------------------+ #property copyright "2015, fxborg" #property link "http://blog.livedoor.jp/fxborg/" #property description "Bounce Strength Indicator" #property strict //--- #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 Blue #property indicator_color2 Red #property indicator_color3 Black #property indicator_level1 10.0 #property indicator_level2 0.0 #property indicator_level3 -10.0 #property indicator_levelcolor clrSilver #property indicator_levelstyle STYLE_DOT //--- input parameters input int InpRangePeriod=20; // Range Period input int InpSlowing=3; // Slowing input int InpAvgPeriod=3; // Avg Period input bool InpUsingVolumeWeight=true; // Using TickVolume //--- buffers double ExtMainBuffer[]; double ExtPosBuffer[]; double ExtNegBuffer[]; //---- for calc double ExtHighesBuffer[]; double ExtLowesBuffer[]; double ExtVolBuffer[]; //--- int draw_begin1=0; int draw_begin2=0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit(void) { string short_name; //--- 2 additional buffers are used for counting. IndicatorBuffers(6); SetIndexBuffer(3,ExtHighesBuffer); SetIndexBuffer(4,ExtLowesBuffer); SetIndexBuffer(5,ExtVolBuffer); //--- indicator lines SetIndexLabel(0,"Floor Bounce Strength"); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexBuffer(0,ExtPosBuffer); SetIndexLabel(1,"Ceiling Bounce Strength"); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexBuffer(1,ExtNegBuffer); SetIndexLabel(2,"Bounce Strength Index"); SetIndexStyle(2,DRAW_LINE); SetIndexBuffer(2,ExtMainBuffer); //--- name for DataWindow and indicator subwindow label //--- draw_begin1=InpRangePeriod+InpSlowing; draw_begin2=draw_begin1+InpAvgPeriod; SetIndexDrawBegin(0,draw_begin1); SetIndexDrawBegin(1,draw_begin1); SetIndexDrawBegin(2,draw_begin2); short_name="Bane Strength Index("+IntegerToString(InpRangePeriod)+","+IntegerToString(InpSlowing)+","+IntegerToString(InpAvgPeriod)+")"; if(InpUsingVolumeWeight) short_name+=" using Volumes"; IndicatorShortName(short_name); //--- initialization done return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| BSI caluclate | //+------------------------------------------------------------------+ 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,k,pos; //--- check for bars count if(rates_total<=InpRangePeriod+InpAvgPeriod+InpSlowing) return(0); //--- counting from 0 to rates_total ArraySetAsSeries(ExtMainBuffer,false); ArraySetAsSeries(ExtPosBuffer,false); ArraySetAsSeries(ExtNegBuffer,false); ArraySetAsSeries(ExtHighesBuffer,false); ArraySetAsSeries(ExtLowesBuffer,false); ArraySetAsSeries(ExtVolBuffer,false); ArraySetAsSeries(low,false); ArraySetAsSeries(high,false); ArraySetAsSeries(close,false); ArraySetAsSeries(tick_volume,false); //--- pos=InpRangePeriod-1; //--- if(pos+1low[k]) dmin=low[k]; if(dmax0) { vol=tick_volume[k]/ExtVolBuffer[k]; } //--- Range position ratio double ratio=0; //--- Range spread double range=ExtHighesBuffer[k]-ExtLowesBuffer[k]; //--- Bar Spread double sp=(high[k]-low[k]); //--- Not DownBar if(!(close[k-1]-sp*0.2>close[k])) { //--- low equal range low if(low[k]==ExtLowesBuffer[k]) ratio=1; else // upper - low / range spread ratio=(ExtHighesBuffer[k]-low[k])/range; sumpos+=(close[k]-low[k])*ratio *vol; } //--- Not UpBar if(!(close[k-1]+sp*0.2