//+------------------------------------------------------------------+ //| CurrencyStrengthBoard_v1.8ea 600+.mq4 | //| Copyright © 2016, TrendLaboratory | //| http://finance.groups.yahoo.com/group/TrendLaboratory | //| E-mail: igorad2003@yahoo.co.uk | //+------------------------------------------------------------------+ #property copyright "Copyright © 2016, TrendLaboratory" #property link "http://finance.groups.yahoo.com/group/TrendLaboratory" #property link "http://newdigital-world.com/forum.php" #property strict #property indicator_chart_window //--- #property indicator_plots 0 enum ENUM_ALERTS { off = 0, //Alerts Off all = 1, //Alerts on all levels extreme = 2, //Extreme strong level very = 3, //Very strong level strong = 4, //Strong level }; //--- INPUTS input ENUM_TIMEFRAMES timeFrame = PERIOD_D1; input string currencyArray = "USD;EUR;GBP;JPY;AUD;CAD;CHF;NZD"; input string symbolPrefix = ""; input string symbolSuffix = ""; input string outputForSymbol = "EURUSD"; input bool compactModeOn = true; input bool showInPips = true; input int refreshTime = 1; // Refresh Time in sec input int offset_X = 200; input int offset_Y = 250; input color strongColor = clrBlue; input color weakColor = clrRed; input color neutralColor = clrWhite; input color borderColor = clrWhite; input int fontSize = 8; input ENUM_ALERTS levelsAlertMode = 0; //Levels alert mode input double extremeStrongLevel = 90; //Extreme strong level(0-Off) input double veryStrongLevel = 70; //Very strong level(0-Off) input double strongLevel = 50; //Strong level(0-Off) input bool currencyAlertOn = false; //Currency strength alert On/Off input bool pushNotificationOn = false; //Push Notification On/Off double outchange[]; double outratio[]; double maxchange[]; double maxchangesym[]; string watchList[], currencies[], pairs[], IndicatorName, TF, outsymbol; int symbolsTotal, num, timeframe, corner = 0, offset_x, offset_y; int strongR, strongG, strongB; int weakR, weakG, weakB; int neutralR,neutralG,neutralB; double scale, pairPoint[], dRatios[]={1,10,1,10,1,10,100}; bool firstTime = true, once = true; datetime prevtime; MqlRates mtfBar[]; //+------------------------------------------------------------------+ //| Indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { if(outputForSymbol == "") outsymbol = Symbol(); else outsymbol = symbolPrefix+outputForSymbol+symbolSuffix; IndicatorBuffers(4); SetIndexBuffer(0, outchange); SetIndexBuffer(1, outratio); SetIndexBuffer(2, maxchange); SetIndexBuffer(3,maxchangesym); //--- if(SymbolsTotal(true) < 5) { Alert("The minimum number of symbols must be 5 (five)."); return(INIT_PARAMETERS_INCORRECT); } //--- ArraySetAsSeries(mtfBar,true); //--- timeframe = timeFrame; if(timeframe <= 0) timeframe = Period(); TF = tf(timeframe); IndicatorName = WindowExpertName(); string currArray = addSignRight(currencyArray,";"); num = stringToArray(currArray,currencies); if(showInPips) ArrayResize(pairPoint,num*num); colorToRGB(strongColor , strongR, strongG, strongB); colorToRGB(weakColor , weakR, weakG, weakB); colorToRGB(neutralColor,neutralR,neutralG,neutralB); scale = (double)fontSize/8.0; offset_x = offset_X; offset_y = offset_Y; prevtime = TimeLocal(); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { Comment(""); ObjectsDeleteAll(0,"Box " +TF); ObjectsDeleteAll(0,"Pair " +TF); ObjectsDeleteAll(0,"Value " +TF); ObjectsDeleteAll(0,"Majors " +TF); ObjectsDeleteAll(0,"Currency " +TF); ObjectsDeleteAll(0,"TimeFrame "+TF); ObjectsDeleteAll(0,"Period " +TF); ChartRedraw(); } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ int start() { int i, currentSymbolsTotal = SymbolsTotal(true); if(TimeLocal() < prevtime + refreshTime) return(0); else prevtime = TimeLocal(); //--- if(symbolsTotal != currentSymbolsTotal) { ArrayResize(watchList,currentSymbolsTotal); for(i=0;i 0 || currencyAlertOn || pushNotificationOn) { if(firstTime) { if(levelsAlertMode > 0 || pushNotificationOn) { ArrayResize(prevmess,symbolsTotal); for(i=0;i 0) outchange[0] = pairChange[i*num+k]; sumChange += pairChange[i*num+k]; if(MathAbs(pairChange[i*num+k]) > maxChange) {maxChange = MathAbs(pairChange[i*num+k]); maxChgPair = pairs[i*num+k];} if(MathAbs(pairChange[i*num+k]) < minChange) {minChange = MathAbs(pairChange[i*num+k]); minChgPair = pairs[i*num+k];} } } else { //Print("ERROR! Symbol "+pair+" is absent in the Watch List!"); SymbolSelect(symbol,true); continue; } } kk[i] = k + 1; currencyPower[i] = sumChange;///(k + 1); sortedPower[i] = currencyPower[i]; } maxchange[0] = maxChange; maxchangesym[0] = symbolToNumber(maxChgPair); ArraySort(sortedPower); double maxPower = sortedPower[num-1]; double minPower = sortedPower[0]; for(int i=0;i 0 && ratio[k] > 0) outratio[0] = ratio[k]; if(outchange[0] <= 0 && ratio[k] <= 0) outratio[0] = ratio[k]; } break; } } } int pos = 0, neg = 0, sdig = 2; bool extremeStrong = false; bool veryStrong = false; bool strong = false; string pct = "%"; if(showInPips) {pct = ""; sdig = 1;} for(int k=0;k= 0) { if(!compactModeOn) { pos++; color1 = (int)(strongR + (1 - ratio[k])*(neutralR - strongR)); color2 = (int)(strongG + (1 - ratio[k])*(neutralG - strongG)); color3 = (int)(strongB + (1 - ratio[k])*(neutralB - strongB)); if(ratio[k] > 0.5) textcolor = clrWhite; else textcolor = clrBlack; if(ratio[k] > 0) plus = "+"; else plus = ""; SetBox ("Box " +TF+" "+currencies[i]+IntegerToString(k),0,(int)(offset_x+(i+1)*52*scale),(int)(offset_y+pos*32*scale),(int)(50*scale),(int)(30*scale),rgbToColor(color1,color2,color3),0,borderColor,1); SetText("Pair " +TF+" "+currencies[i]+IntegerToString(k),sortedPair[k],(int)(offset_x+25*scale+(i+1)*52*scale),(int)(offset_y+2*scale+pos*32*scale),ANCHOR_UPPER,textcolor,fontSize); SetText("Value "+TF+" "+currencies[i]+IntegerToString(k),plus+DoubleToString(sortedChange[k],sdig)+pct,(int)(offset_x+25*scale+(i+1)*52*scale),(int)(offset_y+14*scale+pos*32*scale),ANCHOR_UPPER,textcolor,fontSize); } if(levelsAlertMode > 0 || pushNotificationOn) { bool popup = levelsAlertMode > 0; if((levelsAlertMode == 1 || levelsAlertMode == 2) && extremeStrongLevel > 0) extremeStrong = ratio[k] > extremeStrongLevel/100; else extremeStrong = false; if((levelsAlertMode == 1 || levelsAlertMode == 3) && veryStrongLevel > 0) veryStrong = ratio[k] > veryStrongLevel/100; else veryStrong = false; if((levelsAlertMode == 1 || levelsAlertMode == 4) && strongLevel > 0) strong = ratio[k] > strongLevel/100; else strong = false; if(currencies[i] == StringSubstr(sortedPair[k],0,3)) { if(extremeStrong && ((levelsAlertMode == 1 || levelsAlertMode == 2) || pushNotificationOn)) pairBoxAlert(extremeStrong,sortedPair[k]," is extreme bullish!",popup,pushNotificationOn); else if(veryStrong && ((levelsAlertMode == 1 || levelsAlertMode == 3) || pushNotificationOn)) pairBoxAlert(veryStrong ,sortedPair[k]," is very bullish!",popup,pushNotificationOn); else if(strong && ((levelsAlertMode == 1 || levelsAlertMode == 4) || pushNotificationOn)) pairBoxAlert(strong ,sortedPair[k]," is bullish!",popup,pushNotificationOn); } else if(currencies[i] == StringSubstr(sortedPair[k],3,3)) { if(extremeStrong && ((levelsAlertMode == 1 || levelsAlertMode == 2) || pushNotificationOn)) pairBoxAlert(extremeStrong,sortedPair[k]," is extreme bearish!",popup,pushNotificationOn); else if(veryStrong && ((levelsAlertMode == 1 || levelsAlertMode == 3) || pushNotificationOn)) pairBoxAlert(veryStrong ,sortedPair[k]," is very bearish!",popup,pushNotificationOn); else if(strong && ((levelsAlertMode == 1 || levelsAlertMode == 4) || pushNotificationOn)) pairBoxAlert(strong ,sortedPair[k]," is bearish!",popup,pushNotificationOn); } } } } for(int k=sortedsize-1;k>=0;k--) { if(ratio[k] < 0) { if(!compactModeOn) { neg++; color1 = (int)(neutralR + ratio[k]*(neutralR - weakR)); color2 = (int)(neutralG + ratio[k]*(neutralG - weakG)); color3 = (int)(neutralB + ratio[k]*(neutralB - weakB)); if(MathAbs(ratio[k]) > 0.5) textcolor = clrWhite; else textcolor = clrBlack; SetBox ("Box " +TF+" "+currencies[i]+IntegerToString(k),0,(int)(offset_x+(i+1)*52*scale),(int)(offset_y-neg*32*scale),(int)(50*scale),(int)(30*scale),rgbToColor(color1,color2,color3),0,borderColor,1); SetText("Pair " +TF+" "+currencies[i]+IntegerToString(k),sortedPair[k],(int)(offset_x+25*scale+(i+1)*52*scale),(int)(offset_y+2*scale-neg*32*scale),ANCHOR_UPPER,textcolor,fontSize); SetText("Value "+TF+" "+currencies[i]+IntegerToString(k),DoubleToString(sortedChange[k],sdig)+pct,(int)(offset_x+25*scale+(i+1)*52*scale),(int)(offset_y+14*scale-neg*32*scale),ANCHOR_UPPER,textcolor,fontSize); } } } bordercolor = borderColor; strongest = currencyPower[i] == maxPower; weakest = currencyPower[i] == minPower; if(!compactModeOn) { bwidth = 1; if(strongest) {bordercolor = strongColor; bwidth = (int)(2*fontSize/8.0);} if(weakest ) {bordercolor = weakColor; bwidth = (int)(2*fontSize/8.0);} boxColor = clrGray; textcolor = clrWhite; } else { if(MathMax(MathAbs(maxPower),MathAbs(minPower)) != 0) compactRatio = currencyPower[i]/MathMax(MathAbs(maxPower),MathAbs(minPower)); if(compactRatio >= 0) { color1 = (int)(strongR + (1 - compactRatio)*(neutralR - strongR)); color2 = (int)(strongG + (1 - compactRatio)*(neutralG - strongG)); color3 = (int)(strongB + (1 - compactRatio)*(neutralB - strongB)); } else { color1 = (int)(neutralR + compactRatio*(neutralR - weakR)); color2 = (int)(neutralG + compactRatio*(neutralG - weakG)); color3 = (int)(neutralB + compactRatio*(neutralB - weakB)); } boxColor = (color)rgbToColor(color1,color2,color3); if(MathAbs(compactRatio) > 0.5) textcolor = clrWhite; else textcolor = clrBlack; bwidth = 1; } SetBox ("Majors " +TF+" "+currencies[i],0,(int)(offset_x+(i+1)*52*scale),(int)(offset_y),(int)(50*scale),(int)(30*scale),boxColor,0,bordercolor,bwidth); SetText("Currency "+TF+" "+currencies[i],currencies[i],(int)(offset_x+25*scale+(i+1)*52*scale),(int)(offset_y+2*scale),ANCHOR_UPPER,textcolor,fontSize); if(currencyPower[i] > 0) SetText("Value " +TF+" "+currencies[i],"+"+DoubleToString(currencyPower[i],sdig)+pct,(int)(offset_x+25*scale+(i+1)*52*scale),(int)(offset_y+14*scale),ANCHOR_UPPER,textcolor,fontSize); else SetText("Value " +TF+" "+currencies[i],DoubleToString(currencyPower[i],sdig)+pct,(int)(offset_x+25*scale+(i+1)*52*scale),(int)(offset_y+14*scale),ANCHOR_UPPER,textcolor,fontSize); if(currencyAlertOn) { currencyBoxAlert(strongest,currencies[i]," is strongest currency!",currencyAlertOn,pushNotificationOn); currencyBoxAlert(weakest ,currencies[i]," is weakest currency!" ,currencyAlertOn,pushNotificationOn); } } } bool findStringInArray(string text,string& array[]) { for(int i=0;i 0) { current = StringSubstr(text,s,i-s); size = ArraySize(array) + 1; ArrayResize(array,size); array[size-1] = current; s = i + 1; i = StringFind(text,";",s); } return(size); } void colorToRGB(color clr,int& R, int& G, int& B) { R = clr&0x000000FF; G = (clr>>8)&0x000000FF; B = (clr>>16)&0x000000FF; } int rgbToColor(int R, int G, int B) { return (256*(256*B + G) + R); } string tf(int itimeframe) { string result = ""; switch(itimeframe) { case PERIOD_M1: result = "M1" ; case PERIOD_M5: result = "M5" ; case PERIOD_M15: result = "M15"; case PERIOD_M30: result = "M30"; case PERIOD_H1: result = "H1" ; case PERIOD_H4: result = "H4" ; case PERIOD_D1: result = "D1" ; case PERIOD_W1: result = "W1" ; case PERIOD_MN1: result = "MN1"; default: result = "N/A"; } if(result == "N/A") { if(itimeframe < PERIOD_H1 ) result = "M" + (string)itimeframe; if(itimeframe >= 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); } string prevmess[]; bool pairBoxAlert(bool cond,string pair,string text,bool popup,bool push) { int pos = StringLen(IndicatorName + "(" + TF + ")" + " : "); int len = StringLen(pair); string mess = IndicatorName + "(" + TF + ")" + " : " + pair + text; if(cond) { for(int i=0;i