Absolute Strength Indicator For MT5
Table Of Contents:
- Absolute Strength Indicator For MT5
- Installing the Absolute Strength Indicator For MT5
- Parameters of the Absolute Strength Indicator For MT5
- Buffers of the Absolute Strength Indicator For MT5
- Main Parts Of The Code
The Absolute Strength Indicator For MT5 defines the strength of a trend with absolute levels instead of dynamic levels. The indicators RSI, DMI and Stochastic are using dynamic levels. This indicator uses fixed levels to define the strength of the bulls in comparison to the strength of the bears. The strength of the bulls is drawn with blue color. The strength of the bears is drawn with orange color. The distance between the orange and the blue line in the histogram defines the strength of the trend. If the orange line is above the blue line then a downward trend is detected. Otherwise an upward trend is signaled.
Installing the Absolute Strength Indicator For MT5
After you downloaded the indicator via the form above you need to unzip the zip-file. Then you need to copy the file absolutestrength_v2.mq5 into the folder MQL5\Indicators of your MT5 installation. After that please restart MT5 and then you will be able to see the indicator in the list of indicators.
Parameters of the Absolute Strength Indicator For MT5
The Absolute Strength Indicator For MT5 has 14 parameters to configure.
input ENUM_TIMEFRAMES TimeFrame = 0; input ENUM_MATH_MODE MathMode = 0; // Math method input ENUM_APPLIED_PRICE Price = PRICE_CLOSE; //Apply to input int Length = 10; // Period of Evaluation input int PreSmooth = 1; // Period of PreSmoothing input int Smooth = 1; // Period of Smoothing input int Signal = 1; // Period of Signal Line input ENUM_SMOOTH_MODE MA_Mode = 1; // Moving Average Mode input ENUM_LEVELS_MODE LevelsMode = 0; input double StrengthLevel = 70; // Strength Level (ex.70) input double WeaknessLevel = 30; // Weakness Level (ex.30) input int LookBackPeriod = 30; // LookBack Period for LevelsMode=2,3 input double UpperMultiplier = 1; // Upper Band Multiplier for LevelsMode=2 input double LowerMultiplier = 1; // Lower Band Multiplier for LevelsMode=2
Buffers of the Absolute Strength Indicator For MT5
The Absolute Strength Indicator For MT5 provides 12 buffers.
SetIndexBuffer(0, Bulls,INDICATOR_DATA); SetIndexBuffer(1, Bears,INDICATOR_DATA); SetIndexBuffer(2,signalBulls,INDICATOR_DATA); SetIndexBuffer(3,signalBears,INDICATOR_DATA); SetIndexBuffer(4, strength,INDICATOR_DATA); SetIndexBuffer(5, weakness,INDICATOR_DATA); SetIndexBuffer(6, price,INDICATOR_CALCULATIONS); SetIndexBuffer(7, loprice,INDICATOR_CALCULATIONS); SetIndexBuffer(8, bulls,INDICATOR_CALCULATIONS); SetIndexBuffer(9, bears,INDICATOR_CALCULATIONS); SetIndexBuffer(10, lbulls,INDICATOR_CALCULATIONS); SetIndexBuffer(11, lbears,INDICATOR_CALCULATIONS);
Main Parts Of The Code
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 &TickVolume[], const long &Volume[], const int &Spread[]) { int i, x, y, shift, limit, mtflimit, len, copied; double up, lo, upPivot, dnPivot; datetime mtf_time; //--- preliminary calculations if(prev_calculated == 0) { limit = 0; mtflimit = rates_total - 1; ArrayInitialize(Bulls,EMPTY_VALUE); ArrayInitialize(Bears,EMPTY_VALUE); ArrayInitialize(signalBulls,EMPTY_VALUE); ArrayInitialize(signalBears,EMPTY_VALUE); ArrayInitialize(strength,0); ArrayInitialize(weakness,0); } else { limit = prev_calculated-1; mtflimit = PeriodSeconds(tf)/PeriodSeconds(Period()); } copied = CopyBuffer(Price_handle,0,0,rates_total - 1,price); if(copied lt 0) { Print("not all prices copied. Will try on next tick Error =",GetLastError(),", copied =",copied); return(0); } if(MathMode == 2) { copied = CopyBuffer(Lo_handle,0,0,rates_total - 1,loprice); if(copied lt 0) { Print("not all prices copied. Will try on next tick Error =",GetLastError(),", copied =",copied); return(0); } } //--- the main loop of calculations if(tf gt Period()) { ArraySetAsSeries(Time,true); for(shift=0,y=0;shift lt mtflimit;shift++) { if(Time[shift] lt iTime(NULL,TimeFrame,y)) y++; mtf_time = iTime(NULL,TimeFrame,y); x = rates_total - shift - 1; copied = CopyBuffer(mtf_handle,0,mtf_time,mtf_time,mtf_bulls); if(copied lt = 0) return(0); copied = CopyBuffer(mtf_handle,1,mtf_time,mtf_time,mtf_bears); if(copied lt = 0) return(0); Bulls[x] = mtf_bulls[0]; Bears[x] = mtf_bears[0]; if(Signal gt 1) { copied = CopyBuffer(mtf_handle,2,mtf_time,mtf_time,mtf_sigbulls); if(copied lt = 0) return(0); copied = CopyBuffer(mtf_handle,3,mtf_time,mtf_time,mtf_sigbears); if(copied lt = 0) return(0); signalBulls[x] = mtf_sigbulls[0]; signalBears[x] = mtf_sigbears[0]; } copied = CopyBuffer(mtf_handle,4,mtf_time,mtf_time,mtf_strength); if(copied lt = 0) return(0); copied = CopyBuffer(mtf_handle,5,mtf_time,mtf_time,mtf_weakness); if(copied lt = 0) return(0); strength[x] = mtf_strength[0]; weakness[x] = mtf_weakness[0]; } } else for(shift=limit;shift lt rates_total;shift++) { if(shift gt Length) { switch(MathMode) { case 0: bulls[shift] = 0.5*(MathAbs(price[shift] - price[shift-1]) + (price[shift] - price[shift-1]))/_point; bears[shift] = 0.5*(MathAbs(price[shift] - price[shift-1]) - (price[shift] - price[shift-1]))/_point; break; case 1: up = 0; lo = 10000000000; for(i=0;i lt Length;i++) { up = MathMax(up,High[shift-i]); lo = MathMin(lo,Low [shift-i]); } bulls[shift] = (price[shift] - lo)/_point; bears[shift] = (up - price[shift])/_point; break; case 2: bulls[shift] = MathMax(0,0.5*(MathAbs(price[shift] - price[shift-1]) + (price[shift] - price[shift-1])))/_point; bears[shift] = MathMax(0,0.5*(MathAbs(loprice[shift-1] - loprice[shift]) + (loprice[shift-1] - loprice[shift])))/_point; if (bulls[shift] gt bears[shift]) bears[shift] = 0; else if (bulls[shift] lt bears[shift]) bulls[shift] = 0; else if (bulls[shift] == bears[shift]) {bulls[shift] = 0; bears[shift] = 0;} break; } if(MathMode == 1) len = 1; else len = Length; if(shift lt len) continue; lbulls[shift] = mAverage(0,MA_Mode,bulls,len,Time[shift],shift); lbears[shift] = mAverage(1,MA_Mode,bears,len,Time[shift],shift); if(shift lt len + Smooth) continue; Bulls[shift] = mAverage(2,MA_Mode,lbulls,Smooth,Time[shift],shift); Bears[shift] = mAverage(3,MA_Mode,lbears,Smooth,Time[shift],shift); if(shift lt len + Smooth + Signal) continue; if(Signal gt 1) { signalBulls[shift] = mAverage(4,MA_Mode,Bulls,Signal,Time[shift],shift); signalBears[shift] = mAverage(5,MA_Mode,Bears,Signal,Time[shift],shift); } if(LevelsMode == 0) { if(StrengthLevel gt 0) strength[shift] = StrengthLevel/100*(Bulls[shift] + Bears[shift]); if(WeaknessLevel gt 0) weakness[shift] = WeaknessLevel/100*(Bulls[shift] + Bears[shift]); } else if(LevelsMode == 1 && shift gt len + Smooth + LookBackPeriod) { for(int j = 0; j lt LookBackPeriod; j++) { HiArray[j] = MathMax(Bulls[shift-j],Bears[shift-j]); LoArray[j] = MathMin(Bulls[shift-j],Bears[shift-j]); } if(UpperMultiplier gt 0) strength[shift] = SMA(HiArray,LookBackPeriod,LookBackPeriod-1) + UpperMultiplier*stdDev(HiArray,LookBackPeriod); if(LowerMultiplier gt 0) weakness[shift] = SMA(LoArray,LookBackPeriod,LookBackPeriod-1) - LowerMultiplier*stdDev(LoArray,LookBackPeriod); } else if(LevelsMode == 2 && shift gt len + Smooth + LookBackPeriod) { for(int j = 0; j lt LookBackPeriod; j++) { HiArray[j] = MathMax(Bulls[shift-j],Bears[shift-j]); LoArray[j] = MathMin(Bulls[shift-j],Bears[shift-j]); } upPivot = getPivots(0,HiArray,LookBackPeriod); dnPivot = getPivots(1,LoArray,LookBackPeriod); strength[shift] = upPivot - (upPivot - dnPivot)*(1 - StrengthLevel/100); weakness[shift] = dnPivot + (upPivot - dnPivot)*WeaknessLevel/100; } } } //--- done return(rates_total); } //+------------------------------------------------------------------+ double mAverage(int index,int mode,double& array[],int length,datetime time,int bar) { double ma = 0; switch(mode) { case 1: ma = EMA (index,array[bar],length ,time,bar); break; case 2: ma = EMA (index,array[bar],2*length-1,time,bar); break; case 3: ma = LWMA(array,length,bar); break; case 0: ma = SMA (array,length,bar); break; } return(ma); } // SMA - Simple Moving Average double SMA(double& array[],int length,int bar) { int i; double sum = 0; for(i = 0;i lt length;i++) sum += array[bar-i]; return(sum/length); } // EMA - Exponential Moving Average double EMA(int index,double _price,int length,datetime time,int bar) { if(ptime[index] lt time) {ema[index][1] = ema[index][0]; ptime[index] = time;} if(ftime[index]) {ema[index][0] = _price; ftime[index] = false;} else ema[index][0] = ema[index][1] + 2.0/(1+length)*(_price - ema[index][1]); return(ema[index][0]); } // LWMA - Linear Weighted Moving Average double LWMA(double& array[],int length,int bar) { double lwma, sum = 0, weight = 0; for(int i = 0;i lt length;i++) { weight+= (length - i); sum += array[bar-i]*(length - i); } if(weight gt 0) lwma = sum/weight; else lwma = 0; return(lwma); } // stdDev - Standard Deviation double stdDev(double& array[],int length) { int i; double avg = 0; for (i=0;i lt length;i++) avg += array[i]/length; double sum = 0; for (i=0;i lt length;i++) sum += MathPow(array[i] - avg,2); return(MathSqrt(sum/length)); } double getPivots(int type,double& array[],int len) { int i; double max = 0, min = 100000000; for(i=0;i lt len;i++) { if(type == 0 && array[i] gt max && array[i] lt 1000000) max = array[i]; if(type == 1 && array[i] lt min ) min = array[i]; } if(type == 0) return(max); if(type == 1) return(min); return(0); } string priceToString(ENUM_APPLIED_PRICE app_price) { switch(app_price) { case PRICE_CLOSE : return("Close"); case PRICE_HIGH : return("High"); case PRICE_LOW : return("Low"); case PRICE_MEDIAN : return("Median"); case PRICE_OPEN : return("Open"); case PRICE_TYPICAL : return("Typical"); case PRICE_WEIGHTED: return("Weighted"); default : return(""); } } datetime iTime(string symbol,ENUM_TIMEFRAMES TF,int index) { if(index lt 0) return(-1); static datetime timearray[]; if(CopyTime(symbol,TF,index,1,timearray) gt 0) return(timearray[0]); else return(-1); }