//+------------------------------------------------------------------+ //| RSI.mq4 | //| Copyright © 2004, MetaQuotes Software Corp. | //| http://www.metaquotes.net/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2004, MetaQuotes Software Corp." #property link "http://www.metaquotes.net/" #property indicator_separate_window #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_buffers 1 #property indicator_color1 Blue //---- input parameters extern int RSIPeriod=21; extern int FastMA=23; extern int SlowMA=50; extern int Signal=5; extern int Type=1; //---- buffers double RSIBuffer[]; double PosBuffer[]; double NegBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { string short_name; //---- 2 additional buffers are used for counting. IndicatorBuffers(3); SetIndexBuffer(1,PosBuffer); SetIndexBuffer(2,NegBuffer); //---- indicator line SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,RSIBuffer); //---- name for DataWindow and indicator subwindow label switch (Type) { case 2: short_name="FATL-RSI(" + RSIPeriod + ")"; break; case 1: short_name="Shaff-RSI(" + RSIPeriod + "," + FastMA + "," + SlowMA + ")"; break; default: short_name="RSI(" + RSIPeriod + ")"; break; } IndicatorShortName(short_name); SetIndexLabel(0,short_name); //---- SetIndexDrawBegin(0,RSIPeriod); //---- return(0); } //+------------------------------------------------------------------+ //| Relative Strength Index | //+------------------------------------------------------------------+ int start() { int i,counted_bars=IndicatorCounted(); double rel,negative,positive; //---- if(Bars<=RSIPeriod) return(0); //---- initial zero if(counted_bars<1) for(i=1;i<=RSIPeriod;i++) RSIBuffer[Bars-i]=0.0; //---- i=Bars-RSIPeriod-1; if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1; while(i>=0) { double sumn=0.0,sump=0.0; if(i==Bars-RSIPeriod-1) { int k=Bars-2; //---- initial accumulation while(k>=i) { rel=GetValue(i); if(rel>0) sump+=rel; else sumn-=rel; k--; } positive=sump/RSIPeriod; negative=sumn/RSIPeriod; } else { //---- smoothed moving average rel=GetValue(i); if(rel>0) sump=rel; else sumn=-rel; positive=(PosBuffer[i+1]*(RSIPeriod-1)+sump)/RSIPeriod; negative=(NegBuffer[i+1]*(RSIPeriod-1)+sumn)/RSIPeriod; } PosBuffer[i]=positive; NegBuffer[i]=negative; if(negative==0.0) RSIBuffer[i]=0.0; else RSIBuffer[i]=100.0-100.0/(1+positive/negative); i--; } //---- return(0); } //+------------------------------------------------------------------+ double GetValue(int shift) { double Value = 0; if (Type == 2) Value = GetFATL(shift) - GetFATL(shift+1); else { if (Type == 1) Value = iMACD(NULL,0,FastMA,SlowMA,Signal,PRICE_CLOSE,MODE_MAIN,shift) - iMACD(NULL,0,FastMA,SlowMA,Signal,PRICE_CLOSE,MODE_MAIN,shift+1); else Value = Close[shift] - Close[shift + 1]; } return(Value); } //+------------------------------------------------------------------+ double GetFATL(int i) { double FATL; if (Bars < 40) return(0); FATL = 0.4360409450*Close[i+0] +0.3658689069*Close[i+1] +0.2460452079*Close[i+2] +0.1104506886*Close[i+3] -0.0054034585*Close[i+4] -0.0760367731*Close[i+5] -0.0933058722*Close[i+6] -0.0670110374*Close[i+7] -0.0190795053*Close[i+8] +0.0259609206*Close[i+9] +0.0502044896*Close[i+10] +0.0477818607*Close[i+11] +0.0249252327*Close[i+12] -0.0047706151*Close[i+13] -0.0272432537*Close[i+14] -0.0338917071*Close[i+15] -0.0244141482*Close[i+16] -0.0055774838*Close[i+17] +0.0128149838*Close[i+18] +0.0226522218*Close[i+19] +0.0208778257*Close[i+20] +0.0100299086*Close[i+21] -0.0036771622*Close[i+22] -0.0136744850*Close[i+23] -0.0160483392*Close[i+24] -0.0108597376*Close[i+25] -0.0016060704*Close[i+26] +0.0069480557*Close[i+27] +0.0110573605*Close[i+28] +0.0095711419*Close[i+29] +0.0040444064*Close[i+30] -0.0023824623*Close[i+31] -0.0067093714*Close[i+32] -0.0072003400*Close[i+33] -0.0047717710*Close[i+34] +0.0005541115*Close[i+35] +0.0007860160*Close[i+36] +0.0130129076*Close[i+37] +0.0040364019*Close[i+38]; return(FATL); }
Sample
Analysis
Market Information Used:
Series array that contains close prices for each bar
Indicator Curves created:
Implements a curve of type DRAW_LINE
Indicators Used:
MACD Histogram
Custom Indicators Used:
Order Management characteristics:
Other Features: