//============================================================================= // Conversions.mqh // Copyright © 2008, Derk Wehler // DerkWehler@gmail.com // //============================================================================= #define OP_BOTH -1 #define ALL_OPEN -1 #define ALL_PENDING -1 #define ALL_PENDING_BUYS -2 #define ALL_PENDING_SELLS -3 string C_AUD = "Aussie"; string C_CAD = "Canadian"; string C_CHF = "Swiss Frank"; string C_EUR = "Euro"; string C_GBP = "Pound"; //Great British string C_JPY = "Yen"; //Japanese string C_NZD = "New Zeeland"; string C_USD = "Dollar"; //U.S. int TimeFrameConst2Val(int TF_In_Minutes) { switch(TF_In_Minutes) { case PERIOD_M1: return(1); // M1 case PERIOD_M5: return(2); // M5 case PERIOD_M15: return(3); // M15 case PERIOD_M30: return(4); // M30 case PERIOD_H1: return(5); // H1 case PERIOD_H4: return(6); // H4 case PERIOD_D1: return(7); // D1 case PERIOD_W1: return(8); // W1 case PERIOD_MN1: return(9); // MN } } string TimeFrameVal2String(int TF_val) { switch(TF_val) { case 1: return("M1"); case 2: return("M5"); case 3: return("M15"); case 4: return("M30"); case 5: return("H1"); case 6: return("H4"); case 7: return("D1"); case 8: return("W1"); case 9: return("MN"); } } int SymbolConst2Val(string symbol) { // Handle problem of trailing chars on mini accounts. string mySymbol = StringSubstr(symbol,0,6); if (mySymbol == "AUDCAD") return(1); if (mySymbol == "AUDJPY") return(2); if (mySymbol == "AUDNZD") return(3); if (mySymbol == "AUDUSD") return(4); if (mySymbol == "CADJPY") return(5); if (mySymbol == "CHFJPY") return(6); if (mySymbol == "EURAUD") return(7); if (mySymbol == "EURCAD") return(8); if (mySymbol == "EURCHF") return(9); if (mySymbol == "EURGBP") return(10); if (mySymbol == "EURJPY") return(11); if (mySymbol == "EURUSD") return(12); if (mySymbol == "GBPCHF") return(13); if (mySymbol == "GBPJPY") return(14); if (mySymbol == "GBPUSD") return(15); if (mySymbol == "NZDJPY") return(16); if (mySymbol == "NZDUSD") return(17); if (mySymbol == "USDCAD") return(18); if (mySymbol == "USDCHF") return(19); if (mySymbol == "USDJPY") return(20); return(21); } string OrderType2String(int type) { if (type == OP_BUY) return("BUY"); if (type == OP_SELL) return("SELL"); if (type == OP_BUYSTOP) return("BUY STOP"); if (type == OP_SELLSTOP) return("SELL STOP"); if (type == OP_BUYLIMIT) return("BUY LIMIT"); if (type == OP_SELLLIMIT) return("SELL LIMIT"); if (type == ALL_PENDING_BUYS) return("ALL PENDING BUYS"); if (type == ALL_PENDING_SELLS) return("ALL PENDING SELLS"); if (type == ALL_PENDING) return("ALL OPEN OR ALL PENDING"); return("NONE"); } int OrderString2Num(string type) { if (type == "BUY" || type == "buy" || type == "Buy") return(OP_BUY); else if (type == "SELL" || type == "sell" || type == "Sell") return(OP_SELL); else if (type == "BUYSTOP" || type == "buystop" || type == "BuyStop") return(OP_BUYSTOP); else if (type == "SELLSTOP" || type == "sellstop" || type == "SellStop" || type == "SELL STOP" || type == "sell stop" || type == "Sell Stop") return(OP_SELLSTOP); else if (type == "BUYLIMIT" || type == "buylimit" || type == "BuyLimit" || type == "BUY LIMIT" || type == "buy limit" || type == "Buy Limit") return(OP_BUYLIMIT); else if (type == "SELLLIMIT" || type == "selllimit" || type == "SellLimit" || type == "SELL LIMIT" || type == "sell limit" || type == "Sell Limit") return(OP_SELLLIMIT); } string Bool2Text(bool value) { return(GetBoolText(value)); } string GetBoolText(bool value) { if (value == true) return("True"); return("False"); } int GetHigherTF(int TF_In_Minutes) { if (TF_In_Minutes == 0) TF_In_Minutes = Period(); switch(TF_In_Minutes) { case PERIOD_M1: return(PERIOD_M5); case PERIOD_M5: return(PERIOD_M15); case PERIOD_M15: return(PERIOD_M30); case PERIOD_M30: return(PERIOD_H1); case PERIOD_H1: return(PERIOD_H4); case PERIOD_H4: return(PERIOD_D1); case PERIOD_D1: return(PERIOD_W1); case PERIOD_W1: return(PERIOD_MN1); case PERIOD_MN1: return(PERIOD_MN1); default: Alert(" Conversions.mqh, GetHigherTF(): invalid value"); return(-1); } } int GetLowerTF(int TF_In_Minutes) { if (TF_In_Minutes == 0) TF_In_Minutes = Period(); switch(TF_In_Minutes) { case PERIOD_M1: return(PERIOD_M1); case PERIOD_M5: return(PERIOD_M1); case PERIOD_M15: return(PERIOD_M5); case PERIOD_M30: return(PERIOD_M15); case PERIOD_H1: return(PERIOD_M30); case PERIOD_H4: return(PERIOD_H1); case PERIOD_D1: return(PERIOD_H4); case PERIOD_W1: return(PERIOD_D1); case PERIOD_MN1: return(PERIOD_W1); default: Alert(" Conversions.mqh, GetLowerTF(): invalid value"); return(-1); } } string Symbol2LongName(string symb="") { if (symb == "") symb = Symbol(); if (symb == "AUDCAD") return(C_AUD + ", " + C_CAD); if (symb == "AUDJPY") return(C_AUD + ", " + C_JPY); if (symb == "AUDNZD") return(C_AUD + ", " + C_NZD); if (symb == "AUDUSD") return(C_AUD + ", " + C_USD); if (symb == "CADJPY") return(C_CAD + ", " + C_JPY); if (symb == "CHFJPY") return(C_CHF + ", " + C_JPY); if (symb == "EURAUD") return(C_EUR + ", " + C_AUD); if (symb == "EURCAD") return(C_EUR + ", " + C_CAD); if (symb == "EURCHF") return(C_EUR + ", " + C_CHF); if (symb == "EURGBP") return(C_EUR + ", " + C_GBP); if (symb == "EURJPY") return(C_EUR + ", " + C_JPY); if (symb == "EURUSD") return(C_EUR + ", " + C_USD); if (symb == "GBPCHF") return(C_GBP + ", " + C_CHF); if (symb == "GBPJPY") return(C_GBP + ", " + C_JPY); if (symb == "GBPUSD") return(C_GBP + ", " + C_USD); if (symb == "NZDJPY") return(C_NZD + ", " + C_JPY); if (symb == "NZDUSD") return(C_NZD + ", " + C_USD); if (symb == "USDCAD") return(C_USD + ", " + C_CAD); if (symb == "USDCHF") return(C_USD + ", " + C_CHF); if (symb == "USDJPY") return(C_USD + ", " + C_JPY); } string TimeFrame2LongName(int TF_In_Minutes) { switch(TF_In_Minutes) { case PERIOD_M1: return("One Minute"); case PERIOD_M5: return("Five Minute"); case PERIOD_M15: return("Fifteen Minute"); case PERIOD_M30: return("Thirty Minute"); case PERIOD_H1: return("Hourly"); case PERIOD_H4: return("Four Hour"); case PERIOD_D1: return("Daily"); case PERIOD_W1: return("Weekly"); case PERIOD_MN1: return("Monthly"); } }