//+------------------------------------------------------------------+ //| RSICurrencyStrength_v1.0 600+.mq4 | //| Copyright © 2018, TrendLaboratory | //| http://finance.groups.yahoo.com/group/TrendLaboratory | //| E-mail: igorad2003@yahoo.co.uk | //+------------------------------------------------------------------+ #property copyright "Copyright © 2018, TrendLaboratory" #property link "http://finance.groups.yahoo.com/group/TrendLaboratory" #property link "http://newdigital-world.com/forum.php" #property indicator_chart_window #property indicator_buffers 8 // #property indicator_width1 2 // #property indicator_width2 2 // #property indicator_width3 2 // #property indicator_width4 2 // #property indicator_width5 2 // #property indicator_width6 2 // #property indicator_width7 2 // #property indicator_width8 2 // #property indicator_maximum 100 // #property indicator_minimum 0 // #property indicator_level1 50 input ENUM_TIMEFRAMES timeFrame = 0; // Timeframe input string currencyArray = "USD;EUR;GBP;JPY;AUD;CAD;CHF;NZD"; // Array of Currencies input string symbolPrefix = ""; // Symbol Prefix input string symbolSuffix = ""; // Symbol Suffix input int rsiPeriod = 14; // Period of RSI input int overboughtLevel = 70; // Overbought Level input int oversoldLevel = 30; // Oversold Level input int countBars = 200; // Number of bars counted(0-all bars) input string uniqueName = "RSIStrength"; // ===================== input color currency1Color = clrTomato; // Currency #1 Color input color currency2Color = clrDodgerBlue; // Currency #2 Color input color currency3Color = clrWhiteSmoke; // Currency #3 Color input color currency4Color = clrPink; // Currency #4 Color input color currency5Color = clrYellowGreen; // Currency #5 Color input color currency6Color = clrFireBrick; // Currency #6 Color input color currency7Color = clrChocolate; // Currency #7 Color input color currency8Color = clrGray; // Currency #8 Color input color currency9Color = clrNONE; // Currency #9 Color input color currency10Color = clrNONE; // Currency #10 Color input int lineWidth = 1; // Line Width input bool showBoard = true; // Show Dashboard? input int BoardWindow = 0; // Dashboard Window input int fontSize = 13; // Button Size input int offset_X = 81; // Buttons X from Right input int offset_Y = 180; // Buttons Y from Top input ENUM_BORDER_TYPE borderType = 0; // Buttons Border Type input color borderColor = clrWhite; // Buttons Border Color input color textColor = clrBlack; // Buttons Text Color input string alerts = "=== Alerts & Emails ==="; // ===================== input bool alertOn = false; // Activate Alerts? input int alertShift = 1; // Alert Bar:0-current bar,1-previous bar input int soundsNumber = 5; // Number of sounds after Signal input int soundsPause = 5; // Pause in sec between sounds input string oversoldSound = "alert.wav"; // Oversold Alert Sound File input string overboughtSound = "alert2.wav"; // Overbought Alert Sound File input bool emailOn = false; // Send Email Alerts? input int emailsNumber = 1; // How many mails? input bool pushNotificationOn = false; // Send Push Notifications? double currency1[]; double currency2[]; double currency3[]; double currency4[]; double currency5[]; double currency6[]; double currency7[]; double currency8[]; double currency9[]; double currency10[]; int symbolsTotal, timeframe, cntbars, num, corner = 1; string ind_name, TF, IndicatorName, short_name, currencies[]; double periods[], scale; color boxColor[10]; //+------------------------------------------------------------------+ //| Indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { if(SymbolsTotal(true) < 5) { Alert("The minimum number of symbols must be 5 (five)."); return(INIT_PARAMETERS_INCORRECT); } timeframe = timeFrame; if(timeframe <= Period()) timeframe = Period(); TF = tf(timeframe); IndicatorDigits(2); string currArray = addSignRight(currencyArray,";"); stringToArray(currArray,currencies); num = ArraySize(currencies); scale = (double)fontSize/8.0; SetIndexBuffer(0, currency1); if(currency1Color != EMPTY_VALUE) SetIndexStyle(0,DRAW_LINE,EMPTY,lineWidth, currency1Color); else SetIndexStyle(0,DRAW_NONE); SetIndexBuffer(1, currency2); if(currency2Color != EMPTY_VALUE) SetIndexStyle(1,DRAW_LINE,EMPTY,lineWidth, currency2Color); else SetIndexStyle(1,DRAW_NONE); SetIndexBuffer(2, currency3); if(currency3Color != EMPTY_VALUE) SetIndexStyle(2,DRAW_LINE,EMPTY,lineWidth, currency3Color); else SetIndexStyle(2,DRAW_NONE); SetIndexBuffer(3, currency4); if(currency4Color != EMPTY_VALUE) SetIndexStyle(3,DRAW_LINE,EMPTY,lineWidth, currency4Color); else SetIndexStyle(3,DRAW_NONE); SetIndexBuffer(4, currency5); if(currency5Color != EMPTY_VALUE) SetIndexStyle(4,DRAW_LINE,EMPTY,lineWidth, currency5Color); else SetIndexStyle(4,DRAW_NONE); SetIndexBuffer(5, currency6); if(currency6Color != EMPTY_VALUE) SetIndexStyle(5,DRAW_LINE,EMPTY,lineWidth, currency6Color); else SetIndexStyle(5,DRAW_NONE); SetIndexBuffer(6, currency7); if(currency7Color != EMPTY_VALUE) SetIndexStyle(6,DRAW_LINE,EMPTY,lineWidth, currency7Color); else SetIndexStyle(6,DRAW_NONE); SetIndexBuffer(7, currency8); if(currency8Color != EMPTY_VALUE) SetIndexStyle(7,DRAW_LINE,EMPTY,lineWidth, currency8Color); else SetIndexStyle(7,DRAW_NONE); SetIndexBuffer(8, currency9); if(currency9Color != EMPTY_VALUE) SetIndexStyle(8,DRAW_LINE,EMPTY,lineWidth, currency9Color); else SetIndexStyle(8,DRAW_NONE); SetIndexBuffer(9,currency10); if(currency10Color != EMPTY_VALUE) SetIndexStyle(9,DRAW_LINE,EMPTY,lineWidth,currency10Color); else SetIndexStyle(9,DRAW_NONE); //--- IndicatorName = WindowExpertName(); short_name = IndicatorName+"["+TF+"]("+(string)rsiPeriod+","+(string)countBars+")"; IndicatorShortName(short_name); SetIndexLabel(0,currencies[0]); SetIndexLabel(1,currencies[1]); SetIndexLabel(2,currencies[2]); SetIndexLabel(3,currencies[3]); SetIndexLabel(4,currencies[4]); SetIndexLabel(5,currencies[5]); SetIndexLabel(6,currencies[6]); SetIndexLabel(7,currencies[7]); SetIndexLabel(8,currencies[8]); SetIndexLabel(9,currencies[9]); if(countBars == 0) cntbars = Bars - 1; else cntbars = timeframe/Period()*countBars; SetIndexDrawBegin(0,Bars - cntbars); SetIndexDrawBegin(1,Bars - cntbars); SetIndexDrawBegin(2,Bars - cntbars); SetIndexDrawBegin(3,Bars - cntbars); SetIndexDrawBegin(4,Bars - cntbars); SetIndexDrawBegin(5,Bars - cntbars); SetIndexDrawBegin(6,Bars - cntbars); SetIndexDrawBegin(7,Bars - cntbars); SetIndexDrawBegin(8,Bars - cntbars); SetIndexDrawBegin(9,Bars - cntbars); if(showBoard) { boxColor[0] = currency1Color; boxColor[1] = currency2Color; boxColor[2] = currency3Color; boxColor[3] = currency4Color; boxColor[4] = currency5Color; boxColor[5] = currency6Color; boxColor[6] = currency7Color; boxColor[7] = currency8Color; boxColor[8] = currency9Color; boxColor[9] = currency10Color; } return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { Comment(""); ObjectsDeleteAll(0,uniqueName); ChartRedraw(); } //+------------------------------------------------------------------+ //| Indicator iteration function | //+------------------------------------------------------------------+ int start() { calculateCurrencyStrength(); if(alertOn || emailOn || pushNotificationOn) { if(currencies[0] != "") levelAlert(0,currencies[0],currency1 ,overboughtLevel,oversoldLevel); if(currencies[1] != "") levelAlert(1,currencies[1],currency2 ,overboughtLevel,oversoldLevel); if(currencies[2] != "") levelAlert(2,currencies[2],currency3 ,overboughtLevel,oversoldLevel); if(currencies[3] != "") levelAlert(3,currencies[3],currency4 ,overboughtLevel,oversoldLevel); if(currencies[4] != "") levelAlert(4,currencies[4],currency5 ,overboughtLevel,oversoldLevel); if(currencies[5] != "") levelAlert(5,currencies[5],currency6 ,overboughtLevel,oversoldLevel); if(currencies[6] != "") levelAlert(6,currencies[6],currency7 ,overboughtLevel,oversoldLevel); if(currencies[7] != "") levelAlert(7,currencies[7],currency8 ,overboughtLevel,oversoldLevel); if(currencies[8] != "") levelAlert(8,currencies[8],currency9 ,overboughtLevel,oversoldLevel); if(currencies[9] != "") levelAlert(9,currencies[9],currency10,overboughtLevel,oversoldLevel); } return(0); } //+------------------------------------------------------------------+ //| Currency Strength Calculation function | //+------------------------------------------------------------------+ string watchList[], pairs[], calcSymbols[] = {"HKDUSD","INRUSD","JPYUSD","RUBUSD","TRYUSD","USDAUD","USDEUR","USDGBP","USDSAR","ZARUSD"}; double signs[], sortedPower[], cPower[]; void calculateCurrencyStrength() { int i, j, limit, shift, currentSymbolsTotal = SymbolsTotal(true), counted_bars = IndicatorCounted(); if(counted_bars < 0) return; if(counted_bars > 0) limit = Bars - counted_bars - 1; if(counted_bars < 1) { limit = cntbars; for(i=0;i 0) SetLevelValue(1,overboughtLevel); if(oversoldLevel > 0) SetLevelValue(2,oversoldLevel ); SetLevelStyle(2,1,clrSilver); } int window = BoardWindow; if(timeframe != Period()) { limit = MathMax(limit,timeframe/Period()); for(shift=0;shift=0;shift--) { currencyStrength(num,shift,cPower); currency1[shift] = cPower[0]; currency2[shift] = cPower[1]; currency3[shift] = cPower[2]; currency4[shift] = cPower[3]; currency5[shift] = cPower[4]; currency6[shift] = cPower[5]; currency7[shift] = cPower[6]; currency8[shift] = cPower[7]; if(shift == 0 && showBoard) { ArrayResize(sortedPower,num); ArrayCopy(sortedPower,cPower); ArraySort(sortedPower,WHOLE_ARRAY,0,MODE_DESCEND); for(i=0;i 0) pairChange[i*number+j] = value; else pairChange[i*number+j] = 100 - value; currencyPower[i] += pairChange[i*number+j]/(num-1); currencyPower[j] += (100 - pairChange[i*number+j])/(num-1); } else pairChange[i*number+j] = 0; } } } //+------------------------------------------------------------------+ //| Conversion String to Upper Case String | //+------------------------------------------------------------------+ string StringUpperCase(string str) { string s = str; for(int length=StringLen(str)-1;length>=0;length--) { int _char = StringGetChar(s,length); if((_char > 96 && _char < 123) || (_char > 223 && _char < 256)) s = StringSetChar(s, length,_char - 32); else if(_char > -33 && _char < 0) s = StringSetChar(s, length,_char + 224); } return(s); } //+------------------------------------------------------------------+ //| Add Sign to the Right | //+------------------------------------------------------------------+ string addSignRight(string text,string sign) { string result; text = StringTrimLeft(StringTrimRight(text)); if (StringSubstr(text,StringLen(text),1) != ";") result= StringConcatenate(text,";"); return(result); } void stringToArray(string text,string& array[]) { int s = 0; int i = StringFind(text,";",s); string current; while(i > 0) { current = StringSubstr(text,s,i-s); ArrayResize(array ,ArraySize(array)+1); array[ArraySize(array)-1] = current; s = i + 1; i = StringFind(text,";",s); } } //+------------------------------------------------------------------+ //| Conversion String to String Array | //+------------------------------------------------------------------+ void stringToStringArray(string text,string& array[]) { int s = 0; int i = StringFind(text,";",s); string current; while(i > 0) { current = StringSubstr(text,s,i-s); ArrayResize(array ,ArraySize(array)+1); array[ArraySize(array)-1] = current; s = i + 1; i = StringFind(text,";",s); } } //+------------------------------------------------------------------+ //| Find String In Array | //+------------------------------------------------------------------+ bool findStringInArray(string text,string& array[]) { for(int i=0;i= PERIOD_H1 ) result = "H" + (string)(itimeframe/PERIOD_H1); if(itimeframe >= PERIOD_D1 ) result = "D" + (string)(itimeframe/PERIOD_D1); if(itimeframe >= PERIOD_W1 ) result = "W" + (string)(itimeframe/PERIOD_W1); if(itimeframe >= PERIOD_MN1) result = "MN" + (string)(itimeframe/PERIOD_MN1); } return(result); } //+------------------------------------------------------------------+ //| Draw data about a symbol in a Box | //+------------------------------------------------------------------+ void SetText(string name,int win,string text,int x,int y,int anchor,color colour,int fontsize) { ObjectDelete(0,name); if(ObjectCreate(0,name,OBJ_LABEL,win,0,0)) { ObjectSetInteger(0,name,OBJPROP_XDISTANCE, x); ObjectSetInteger(0,name,OBJPROP_YDISTANCE, y); ObjectSetInteger(0,name,OBJPROP_COLOR , colour); ObjectSetInteger(0,name,OBJPROP_FONTSIZE ,fontsize); ObjectSetInteger(0,name,OBJPROP_CORNER , corner); ObjectSetInteger(0,name,OBJPROP_ANCHOR , anchor); ObjectSetString (0,name,OBJPROP_TEXT , text); } } //+------------------------------------------------------------------+ //| Draw a Box with given color for a symbol | //+------------------------------------------------------------------+ void SetBox(string name,int win,int x,int y,int width,int height,color bg_color,int border_type,color border_clr,int border_width) { ObjectDelete(0,name); if(ObjectCreate(0,name,OBJ_RECTANGLE_LABEL,win,0,0)) { ObjectSetInteger(0,name,OBJPROP_XDISTANCE , x); ObjectSetInteger(0,name,OBJPROP_YDISTANCE , y); ObjectSetInteger(0,name,OBJPROP_XSIZE , width); ObjectSetInteger(0,name,OBJPROP_YSIZE , height); ObjectSetInteger(0,name,OBJPROP_COLOR , border_clr); ObjectSetInteger(0,name,OBJPROP_BORDER_TYPE, border_type); ObjectSetInteger(0,name,OBJPROP_WIDTH ,border_width); ObjectSetInteger(0,name,OBJPROP_CORNER , corner); ObjectSetInteger(0,name,OBJPROP_STYLE , STYLE_SOLID); ObjectSetInteger(0,name,OBJPROP_BACK , false); ObjectSetInteger(0,name,OBJPROP_SELECTABLE , 0); ObjectSetInteger(0,name,OBJPROP_SELECTED , 0); ObjectSetInteger(0,name,OBJPROP_HIDDEN , true); ObjectSetInteger(0,name,OBJPROP_ZORDER , 0); ObjectSetInteger(0,name,OBJPROP_BGCOLOR , bg_color); } } datetime prevnbtime[10]; bool isNewBar(int index,int tf) { bool res = false; if(tf >= 0) { if(iTime(NULL,tf,0) != prevnbtime[index]) { res = true; prevnbtime[index] = iTime(NULL,tf,0); } } else res = true; return(res); } string prevmess[10]; bool BoxAlert(int index,bool cond,string text) { string mess = IndicatorName + "(" + TF + ")" + text; string close = DoubleToString(iClose(NULL,0,0),Digits); if(cond && mess + close != prevmess[index]) { Alert (mess); prevmess[index] = mess + " " + close; return(true); } return(false); } datetime pausetime; bool Pause(int sec) { if(TimeCurrent() >= pausetime + sec) {pausetime = TimeCurrent(); return(true);} return(false); } datetime warningtime; void WarningSound(bool cond,int inum,int sec,string sound,datetime curtime) { static int i; if(cond) { if(curtime != warningtime) i = 0; if(i < inum && Pause(sec)) {PlaySound(sound); warningtime = curtime; i++;} } } string prevemail[10]; bool EmailAlert(int index,bool cond,string text,int inum) { string subj = "New Signal from " + IndicatorName + "!!!"; string mess = IndicatorName + "(" + TF + ")" + text; string close = DoubleToString(iClose(NULL,0,0),Digits); if (cond && mess + close != prevemail[index]) { if(subj != "" && mess != "") for(int i=0;i ovb && strength[alertShift+1] <= ovb; bool crossBelow = strength[alertShift] < ovs && strength[alertShift+1] >= ovs; if(crossAbove || crossBelow) { if(isNewBar(index,Period())) { if(alertOn) { BoxAlert(index,crossAbove," : " + currency + " RSI Strength is above Overbought level " +DoubleToStr(ovb,2)); BoxAlert(index,crossBelow," : " + currency + " RSI Strength is below Oversold level " +DoubleToStr(ovs,2)); } if(emailOn) { EmailAlert(index,crossAbove," : " + currency + " RSI Strength is above Overbought level " +DoubleToStr(ovb,2),emailsNumber); EmailAlert(index,crossBelow," : " + currency + " RSI Strength is below Oversold level " +DoubleToStr(ovs,2),emailsNumber); } if(pushNotificationOn) { PushAlert(index,crossAbove," : " + currency + " RSI Strength is above Overbought level " +DoubleToStr(ovb,2)); PushAlert(index,crossBelow," : " + currency + " RSI Strength is below Oversold level " +DoubleToStr(ovs,2)); } } else { if(alertOn) { WarningSound(crossAbove,soundsNumber,soundsPause,overboughtSound,Time[alertShift]); WarningSound(crossBelow,soundsNumber,soundsPause,oversoldSound ,Time[alertShift]); } } } }