//+------------------------------------------------------------------+ //| RSI SelfAdjustRSI v1.0[FX5](mtf).mq4 | //| FX5 | //| hazem@uk2.net | //+------------------------------------------------------------------+ //mod2007ForexTSD mtf mladen f-la ki //mod2008fxtsd #property copyright "FX5" #property link "hazem@uk2.net" //---- #property indicator_separate_window #property indicator_minimum 1 #property indicator_maximum 100 #property indicator_buffers 3 #property indicator_level1 20 #property indicator_level2 30 #property indicator_level3 50 #property indicator_level4 70 #property indicator_level5 80 #property indicator_levelcolor DarkSlateGray //---- input parameters extern int rsiPeriod = 14; extern double diviation = 2; extern bool MA_Method = true; extern color rsiColor = LimeGreen; extern color overBoughtColor = Blue; extern color overSoldColor = Red; extern string ____ = "_____"; extern int timeFrame = 0; extern string note_timeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-currenttf"; extern string note_MA_Method = "MA_Method/StandardDeviationMethod"; string IndicatorFileName; //---- buffers double rsi[]; double upperBorder[]; double lowerBorder[]; double absDiviation[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorBuffers(4); SetIndexStyle(0, DRAW_LINE, EMPTY, EMPTY, rsiColor); SetIndexStyle(1, DRAW_LINE, EMPTY, EMPTY, overBoughtColor); SetIndexStyle(2, DRAW_LINE, EMPTY, EMPTY, overSoldColor); //---- SetIndexBuffer(0, rsi); SetIndexBuffer(1, upperBorder); SetIndexBuffer(2, lowerBorder); SetIndexBuffer(3, absDiviation); //---- SetIndexDrawBegin(0, rsiPeriod); SetIndexDrawBegin(1, rsiPeriod * 2); SetIndexDrawBegin(2, rsiPeriod * 2); //---- SetIndexLabel(0, "RSI"); SetIndexLabel(1, "OverBought"); SetIndexLabel(2, "OverSold"); //---- switch(timeFrame) { case 1: string TimeFrameStr = "M1"; break; case 5 : TimeFrameStr = "M5"; break; case 15 : TimeFrameStr = "M15"; break; case 30 : TimeFrameStr = "M30"; break; case 60 : TimeFrameStr = "H1"; break; case 240 : TimeFrameStr = "H4"; break; case 1440 : TimeFrameStr = "D1"; break; case 10080 : TimeFrameStr = "W1"; break; case 43200 : TimeFrameStr = "MN1"; break; default : TimeFrameStr = "TF0"; } IndicatorShortName("SelfAdjustRSI (" + rsiPeriod + ") [" + TimeFrameStr + "]"); IndicatorFileName = WindowExpertName(); if (timeFrame < Period()) timeFrame = Period(); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { // int limit1,i1; int counted_bars1 = IndicatorCounted(); if(counted_bars1 < 0) return(-1); limit1 = Bars-counted_bars1; // // // MTF mode operating // // if (timeFrame != Period()) { limit1 = MathMax(limit1,timeFrame/Period()); datetime TimeArray[]; ArrayCopySeries(TimeArray ,MODE_TIME ,NULL,timeFrame); // // // // // for(i1=0,int y=0; i1<limit1; i1++) { if(Time[i1]<TimeArray[y]) y++; rsi[i1] = iCustom(NULL,timeFrame,IndicatorFileName,rsiPeriod,diviation,MA_Method,0,y); upperBorder[i1] = iCustom(NULL,timeFrame,IndicatorFileName,rsiPeriod,diviation,MA_Method,1,y); lowerBorder[i1] = iCustom(NULL,timeFrame,IndicatorFileName,rsiPeriod,diviation,MA_Method,2,y); } return(0); } // // // // // //---- int countedBars = IndicatorCounted(); if(MA_Method == true) MovingAverageMethod(countedBars); else StandardDeviationMethod(countedBars); //---- return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void MovingAverageMethod(int countedBars) { if(countedBars < 0) countedBars = 0; //---- for(int i = Bars - countedBars; i >= 0; i--) { rsi[i] = iRSI(NULL, 0, rsiPeriod, PRICE_CLOSE, i); double smoothedRSI = GetSmoothedRSI(i); absDiviation[i] = MathAbs(rsi[i] - smoothedRSI); double kDiviation = diviation * GetAbsDiviationAverage(i); upperBorder[i] = 50 + kDiviation; lowerBorder[i] = 50 - kDiviation; } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void StandardDeviationMethod(int countedBars) { if(countedBars < 0) countedBars = 0; //---- for(int i = Bars - countedBars; i >= 0; i--) { rsi[i] = iRSI(NULL, 0, rsiPeriod, PRICE_CLOSE, i); double rsiDiviation = iStdDevOnArray(rsi, 0, rsiPeriod, 0, MODE_SMA, i); double kDiviation = diviation * rsiDiviation; upperBorder[i] = 50 + kDiviation; lowerBorder[i] = 50 - kDiviation; } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double GetSmoothedRSI(int shift) { double sum = 0; for(int i = shift; i < shift + rsiPeriod; i++) { sum += rsi[i]; } return(sum / rsiPeriod); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double GetAbsDiviationAverage(int shift) { double sum = 0; for(int i = shift; i < shift + rsiPeriod; i++) { sum += absDiviation[i]; } return(sum / rsiPeriod); } //+------------------------------------------------------------------+
Sample
Analysis
Market Information Used:
Series array that contains open time of each bar
Indicator Curves created:
Implements a curve of type DRAW_LINE
Indicators Used:
Relative strength index
Standard Deviation indicator
Custom Indicators Used:
IndicatorFileName
Order Management characteristics:
Other Features: