//+------------------------------------------------------------------+ //| BSI_Trend.mq4 | //| BSI_Trend Copyright 2015, fxborg | //| http://fxborg-labo.hateblo.jp/ | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, fxborg" #property link "http://fxborg-labo.hateblo.jp/" #property version "1.00" #property strict #property indicator_chart_window #property indicator_buffers 8 #property indicator_type1 DRAW_LINE #property indicator_type2 DRAW_LINE #property indicator_type3 DRAW_LINE #property indicator_type4 DRAW_LINE #property indicator_type5 DRAW_LINE #property indicator_type6 DRAW_ARROW #property indicator_type7 DRAW_ARROW #property indicator_type8 DRAW_LINE //--- #property indicator_color1 Orange #property indicator_color2 Gray #property indicator_color3 Aqua #property indicator_color4 DeepPink #property indicator_color5 DarkViolet #property indicator_color6 Red #property indicator_color7 Blue #property indicator_color8 Red #property indicator_label1 "Trend High" #property indicator_label2 "Trend Regr" #property indicator_label3 "Trend Low" #property indicator_label4 "Tango Line" #property indicator_label5 "Tango MA" #property indicator_label6 "Reversal Bar" #property indicator_label7 "Reversal Bar" #property indicator_label8 "BSI" //--- #property indicator_width1 1 #property indicator_width2 1 #property indicator_width3 1 #property indicator_width4 2 #property indicator_width5 2 #property indicator_width6 2 #property indicator_width7 2 #property indicator_width8 1 #property indicator_style1 STYLE_DASH #property indicator_style2 STYLE_DOT #property indicator_style3 STYLE_DASH #property indicator_style4 STYLE_SOLID #property indicator_style5 STYLE_SOLID #property indicator_style8 STYLE_DOT //--- input parameters input int InpChannelPeriod=30; // Channel Period input int InpTrendPeriod=30; // Trend Period input double InpReversalNoiseFilter=5; // NoiseFilter (Minimam Reversal Spread) input bool InpUsingVolumeWeight=true; // UseingVolumeWeight double RevNoiseFilter=InpReversalNoiseFilter*Point; //--- int min_rates_total; //--- indicator buffers double UpTrendBuffer[]; double LoTrendBuffer[]; double MdTrendBuffer[]; double TangoBuffer[]; double TangoMaBuffer[]; double TopBuffer[]; double BtmBuffer[]; //--- calc buffers double SlopeBuffer[]; double BSIBuffer[]; double HighesBuffer[]; double LowesBuffer[]; double VolBuffer[]; double UpRangeBuffer[]; double DnRangeBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //---- Initialization of variables of data calculation starting point min_rates_total=1+MathMax(InpTrendPeriod,InpChannelPeriod)+1; //--- indicator buffers mapping IndicatorBuffers(14); //--- indicator buffers SetIndexBuffer(0,UpTrendBuffer); SetIndexBuffer(1,MdTrendBuffer); SetIndexBuffer(2,LoTrendBuffer); SetIndexBuffer(3,TangoBuffer); SetIndexBuffer(4,TangoMaBuffer); SetIndexBuffer(5,TopBuffer); SetIndexBuffer(6,BtmBuffer); SetIndexBuffer(7,BSIBuffer); //--- calc buffers SetIndexBuffer(8,HighesBuffer); SetIndexBuffer(9,LowesBuffer); SetIndexBuffer(10,SlopeBuffer); SetIndexBuffer(11,UpRangeBuffer); SetIndexBuffer(12,DnRangeBuffer); SetIndexBuffer(13,VolBuffer); SetIndexArrow(5,159); SetIndexArrow(6,159); SetIndexShift(0,1); SetIndexShift(1,1); SetIndexShift(2,1); SetIndexShift(3,1); SetIndexShift(4,1); SetIndexShift(7,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,k,first; //--- check for bars count if(rates_total<=min_rates_total) return(0); //--- indicator buffers ArraySetAsSeries(UpTrendBuffer,false); ArraySetAsSeries(MdTrendBuffer,false); ArraySetAsSeries(LoTrendBuffer,false); ArraySetAsSeries(TangoBuffer,false); ArraySetAsSeries(TangoMaBuffer,false); ArraySetAsSeries(TopBuffer,false); ArraySetAsSeries(BtmBuffer,false); ArraySetAsSeries(BSIBuffer,false); //--- calc buffers ArraySetAsSeries(HighesBuffer,false); ArraySetAsSeries(LowesBuffer,false); ArraySetAsSeries(UpRangeBuffer,false); ArraySetAsSeries(DnRangeBuffer,false); ArraySetAsSeries(SlopeBuffer,false); ArraySetAsSeries(VolBuffer,false); //--- rate data ArraySetAsSeries(time,false); ArraySetAsSeries(high,false); ArraySetAsSeries(low,false); ArraySetAsSeries(close,false); ArraySetAsSeries(tick_volume,false); //+----------------------------------------------------+ //|Set High Low Buffeer | //+----------------------------------------------------+ first=InpChannelPeriod-1; if(first+1low[k]) dmin=low[k]; if(dmax1;j--) { if(LowesBuffer[j-2]-RevNoiseFilter*Point>LowesBuffer[j-1] && LowesBuffer[j-1]==LowesBuffer[j]) { //--- reversal of top btm_pos=j-1; BtmBuffer[btm_pos]=LowesBuffer[btm_pos]; break; } //--- reversal of bottom if(HighesBuffer[j-2]+RevNoiseFilter*Pointlow[j])range_lo=low[j]; } //--- set channel data double prev_high=MathMax(MathMax(MathMax(high[turn_pos-4], high[turn_pos-3]),high[turn_pos-2]),high[turn_pos-1]); double prev_low=MathMin(MathMin(MathMin(low[turn_pos-4], low[turn_pos-3]),low[turn_pos-2]),low[turn_pos-1]); UpRangeBuffer[i]=MathMax(range_hi,prev_high); TangoBuffer[i]=(range_hi+range_lo)/2; DnRangeBuffer[i]=MathMin(range_lo,prev_low); //--- } } //+----------------------------------------------------+ //| Set Tango MA Buffeer & BSI Buffer | //+----------------------------------------------------+ int MaPeriod=(int)MathRound(InpChannelPeriod/2); first=InpChannelPeriod-1+MaPeriod-1; if(first+1bsi2 && bsi1>bsi2)) { //+----------------------------------------------------+ //| Trend Line | //+----------------------------------------------------+ double a,b; double price[],upper[],lower[]; ArraySetAsSeries(price,true); ArraySetAsSeries(upper,true); ArraySetAsSeries(lower,true); //--- Get Rate info int chk_h = CopyHigh(Symbol(),PERIOD_CURRENT,time[i],InpTrendPeriod,upper); int chk_l = CopyLow(Symbol(),PERIOD_CURRENT,time[i],InpTrendPeriod,lower); int chk_c = CopyClose(Symbol(),PERIOD_CURRENT,time[i],InpTrendPeriod,price); if(chk_cLowesBuffer[i]) { //--- UpTrendBuffer[i] = a+(h1+h2)/2; LoTrendBuffer[i] = a-(l1+l2)/2; MdTrendBuffer[i]=a; SlopeBuffer[i]=b; //--- for(j=1;j0) { double vol_fact=MathSqrt(VolBuffer[k]); v=MathSqrt(vol[k])/vol_fact; } //--- Range position ratio double ratio=0; //--- Bar Spread double sp=(hi[k]-lo[k]); //--- Not DownBar if(!(cl[k-1]-sp*0.2>cl[k])) { ratio=-1*(lo[k]/TangoMaBuffer[k])+2; sumpos+=(cl[k]-lo[k])*ratio*v; } //--- Not UpBar if(!(cl[k-1]+sp*0.2