//+------------------------------------------------------------------+ //| iCybo_PairStrength.mq4 | //| Copyright 2012, Cybomate Automations | //| hijeenu@gmail.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2012, Cybomate Automations" #property link "hijeenu@gmail.com" #property indicator_chart_window //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Cybo_PairStrength.mq4 | //| Copyright 2012, Cybomate Automations | //| hijeenu@gmail.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2012, Cybomate Automations" #property link "hijeenu@gmail.com" string Currency1 ="EUR"; string Currency2 ="USD"; string Currency3 ="GBP"; string Currency4 ="CHF"; string Currency5 ="CAD"; string Currency6 ="AUD"; string Currency7 ="JPY"; string Currency8 ="NZD"; input int xAnchor = 700; input int yAnchor = 10; input int fontSize = 8; //input int TokyOpenOffset = -1; string masterPreamble = "iCybooDay_"; int panelheight =20; struct currency_ranking { int _index; string _name; double _value; }; currency_ranking currencyRanking[8]; string Currencies[] = {"EUR","USD","GBP","CHF","CAD","AUD","JPY","NZD"}; string Symbols[]; int SymbolCount = 0; int totalsym =0; int num=0; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- // delete objects string name; string s = masterPreamble; for (int i = ObjectsTotal() - 1; i >= 0; i--) { name = ObjectName(i); if (StringSubstr(name, 0, StringLen(s)) == s) { ObjectDelete(name); } } CreateSymbolList(); totalsym =ArraySize(Symbols); //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- string name; string s = masterPreamble; for (int i = ObjectsTotal() - 1; i >= 0; i--) { name = ObjectName(i); if (StringSubstr(name, 0, StringLen(s)) == s) { ObjectDelete(name); } } //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start(){ double currencyValues[8]; double c1 =calulate_strength(Currency1); double c2 =calulate_strength(Currency2); double c3 =calulate_strength(Currency3); double c4 =calulate_strength(Currency4); double c5 =calulate_strength(Currency5); double c6 =calulate_strength(Currency6); double c7 =calulate_strength(Currency7); double c8 =calulate_strength(Currency8); currencyValues[0] = c1; currencyValues[1] = c2; currencyValues[2] = c3; currencyValues[3] = c4; currencyValues[4] = c5; currencyValues[5] = c6; currencyValues[6] = c7; currencyValues[7] = c8; int currencyValuesIndex = 0; for (int u = 0; u < 7; u++) { double max = -5000.0; int tmpIndex = 0; for (int uu = 0; uu < 8; uu++) { if (currencyValues[uu] > max) { max = currencyValues[uu]; tmpIndex = uu; } } currencyRanking[currencyValuesIndex]._index = u+1; currencyRanking[currencyValuesIndex]._name = Currencies[tmpIndex]; currencyRanking[currencyValuesIndex]._value = max; currencyValues[tmpIndex] = -10000.0; currencyValuesIndex++; } // look for last // rank the values for (int z=0; z < 8; z++) { if (currencyValues[z] > -5000) { currencyRanking[currencyValuesIndex]._index = 8; currencyRanking[currencyValuesIndex]._name = Currencies[z]; currencyRanking[currencyValuesIndex]._value = currencyValues[z]; break; } } string _toDisplay, _toDisplay_2; int xOffset = 50; //display info for (int w = 0; w < 8; w++) { _toDisplay = IntegerToString(w+1) + ". " + currencyRanking[w]._name; _toDisplay_2 = DoubleToStr(currencyRanking[w]._value,1); if (w < 2) { SetText(masterPreamble + currencyRanking[w]._name + "index", _toDisplay, xAnchor, yAnchor + w * panelheight,clrLime,fontSize); SetText(masterPreamble + currencyRanking[w]._name + "value", _toDisplay_2, xAnchor + xOffset, yAnchor + w * panelheight,clrLime,fontSize); } else if (w < 6) { SetText(masterPreamble + currencyRanking[w]._name + "index", _toDisplay, xAnchor, yAnchor + w * panelheight,clrOrange,fontSize); SetText(masterPreamble + currencyRanking[w]._name + "value", _toDisplay_2, xAnchor + xOffset, yAnchor + w * panelheight,clrOrange,fontSize); } else { SetText(masterPreamble + currencyRanking[w]._name + "index", _toDisplay, xAnchor, yAnchor + w * panelheight,clrRed,fontSize); SetText(masterPreamble + currencyRanking[w]._name + "value", _toDisplay_2, xAnchor + xOffset, yAnchor + w * panelheight,clrRed,fontSize); } } return (0); } //---- double calulate_strength(string curstrngth ) { int count = ArraySize(Symbols); num =0; double sum=0; for (int ic=0; ic iOpen(sym,PERIOD_D1,22)) { pips= (MarketInfo(sym,MODE_BID)-iOpen(sym,PERIOD_D1,22))/(MarketInfo(sym,MODE_POINT)*pnt); sum =sum + pips; // Print(num +" ) currency "+ sym +" Pips "+ pips +" sum "+sum+" Current Bid "+MarketInfo(sym,MODE_BID)+" Hour Open "+iOpen(sym,PERIOD_H1,0)); num++; } else if (MarketInfo(sym,MODE_BID)< iOpen(sym,PERIOD_D1,22) ) { pips=(iOpen(sym,PERIOD_D1,22)- MarketInfo(sym,MODE_BID))/(MarketInfo(sym,MODE_POINT)*pnt); sum =sum - pips; // Print(num +" ) currency "+ sym +" Pips "+ (-pips) +" sum "+sum+" Current_Bid "+MarketInfo(sym,MODE_BID)+" Hour_Open "+iOpen(sym,PERIOD_H1,0)); num++; } } //quote else if(StringSubstr(sym ,3,6)==curstrngth) // if currencyStrength is base { if(MarketInfo(sym,MODE_BID)> iOpen(sym,PERIOD_D1,22)) { pips= (MarketInfo(sym,MODE_BID)-iOpen(sym,PERIOD_D1,22))/(MarketInfo(sym,MODE_POINT)*pnt); sum =sum -pips; // Print(num +" ) currency "+ sym +" Pips "+ (-pips) +" sum "+sum+" Current Bid "+MarketInfo(sym,MODE_BID)+" hour Open "+iOpen(sym,PERIOD_H1,0)); num++; } else if (MarketInfo(sym,MODE_BID)< iOpen(sym,PERIOD_D1,22) ) { pips=(iOpen(sym,PERIOD_D1,22)- MarketInfo(sym,MODE_BID))/(MarketInfo(sym,MODE_POINT)*pnt); sum =sum + pips; // Print(num +" ) currency "+ sym +" Pips "+ pips +" sum "+sum+" Current Bid "+MarketInfo(sym,MODE_BID)+" Hour Open "+iOpen(sym,PERIOD_H1,0)); num++; } } } return (sum/num); } int CreateSymbolList() { int CurrencyCount = ArrayRange(Currencies, 0); int Loop, SubLoop; string TempSymbol; for(Loop = 0; Loop < CurrencyCount; Loop++) for(SubLoop = 0; SubLoop < CurrencyCount; SubLoop++) { TempSymbol = Currencies[Loop] + Currencies[SubLoop]; if(MarketInfo(TempSymbol, MODE_BID) > 0) { ArrayResize(Symbols, SymbolCount + 1); Symbols[SymbolCount] = TempSymbol; SymbolCount++; } } //Alert(ArraySize(Symbols)); return(0); } //+------------------------------------------------------------------+ void SetText(string name,string text,int x,int y,color colour,int fontsize) { if (ObjectFind(0,name)<0) ObjectCreate(0,name,OBJ_LABEL,0,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_LEFT_UPPER); ObjectSetString(0,name,OBJPROP_FONT,"Arial"); ObjectSetString(0,name,OBJPROP_TEXT,text); }