//The Relative Brokers Vigor Index RBVI. Based on code RSI.mq4, Copyright © 2004, MetaQuotes Software Corp. http://www.metaquotes.net/ #property copyright "Copyright © 2004, MetaQuotes Software Corp., BECEMAL 2010" #property link "http://www.becemal.ru/" #property indicator_separate_window #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_level1 40 #property indicator_level2 60 #property indicator_buffers 3 #property indicator_color1 RoyalBlue extern int RBVIPeriod=10; double RBVIBuffer[]; double PosBuffer[]; double NegBuffer[]; bool init_flag=false; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool prepare_buffer() { if(init_flag) return(true); PosBuffer[0]=0; NegBuffer[0]=0; init_flag=true; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int init() { string short_name="RBVI("+RBVIPeriod+")"; SetIndexBuffer(1,PosBuffer); SetIndexBuffer(2,NegBuffer); SetIndexStyle(0,DRAW_LINE); SetIndexStyle(1,DRAW_NONE); SetIndexStyle(2,DRAW_NONE); SetIndexBuffer(0,RBVIBuffer); IndicatorShortName(short_name); SetIndexLabel(0,"RBVI"); SetIndexDrawBegin(0,RBVIPeriod); init_flag=false; return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { if (!init_flag) {prepare_buffer();} int i,counted_bars=IndicatorCounted(); double rel,negative,positive,sumn,sump; if(Bars<=RBVIPeriod) return(0); if(counted_bars<1) for(i=1;i<=RBVIPeriod;i++) RBVIBuffer[Bars-i]=50.0; i=Bars-RBVIPeriod-1; if(counted_bars>=RBVIPeriod) i=Bars-counted_bars-1; { } while(i>=0) { sumn=0.0; sump=0.0; rel=iATR(NULL,0,RBVIPeriod,i)*Volume[i]-iATR(NULL,0,RBVIPeriod,i+1)*Volume[i+1]; if(rel>0) sump= rel; else sumn=-rel; positive=(PosBuffer[i+1]*(RBVIPeriod-1)+sump)/RBVIPeriod; negative=(NegBuffer[i+1]*(RBVIPeriod-1)+sumn)/RBVIPeriod; PosBuffer[i]=positive; NegBuffer[i]=negative; if(negative==0.0) RBVIBuffer[i]=0.0; else RBVIBuffer[i]=100.0*(1.0-1.0/(1.0+positive/negative)); i--; } return(0); } //+------------------------------------------------------------------+