Need some help with some MT5 code

 

I'm trying to get an alert to include the time frame the alert has gone of in. I get an error saying the number to string conversion and the actual alert says BuyNZDUSD16392 (the numbers are the conversion but how do I get it to say H8 or H12 D1)

I tried PERIOD_CURRENT this did not work 


alert issue

 
giogee:

I'm trying to get an alert to include the time frame the alert has gone of in. I get an error saying the number to string conversion and the actual alert says BuyNZDUSD16392 (the numbers are the conversion but how do I get it to say H8 or H12 D1)

I tried PERIOD_CURRENT this did not work 

Use EnumToString();

txt = "Buy" + _Symbol + EnumToString(_Period);
 

It worked


Thank you so much @Lakshan Perera

 
Always write self-documenting code
string as_string(ENUM_APPLIED_PRICE price, int len=0){
   string price_XXX = EnumToString(price);                     // PRICE_XXX
   return StringSubstr(price_XXX, 6, len);                     // XXX
}
string   as_string(ENUM_TIMEFRAMES period){
   if(period == PERIOD_CURRENT)  period   = (ENUM_TIMEFRAMES) _Period;
   string   period_xxx  = EnumToString(period);                // PERIOD_XXX
   return StringSubstr(period_xxx, 7);                         // XXX
}
string   as_string(ENUM_MA_METHOD p, int len=0){
   string mode_XXX = EnumToString(p);                          // MODE_XXX
   return StringSubstr(mode_XXX, 5, len);                      // XXX
}
string   lots_as_string( double lots){ return DoubleToString(lots, gDigitsLots);  }
string   price_as_string(double price){return DoubleToString(price, _Digits);     }
string   pips_as_string( double pips, string plusSign="+"){
   return to_signed_fixed(pips, gDigitsPip, plusSign);                         }
string   to_signed_fixed(double value, int nDecimals, string plusSign="+"){
   if(value < 0.) plusSign = "";
   return plusSign + DoubleToString(value, nDecimals);
}
<Edited by moderator: mql4 code on a mql5 topic> No it's not, it's generic.
 
whroeder1:
Always write self-documenting code
Please pay attention to what you post. Your code doesn't compile as mql5.
 
Alain Verleyen: Please pay attention to what you post. Your code doesn't compile as mql5.

Neither did the previous post.

EnumToString(_Period);
 
whroeder1:

Neither did the previous post.

What do you mean?
 
whroeder1:

Neither did the previous post.

You are arguing for nothing. The previous post is fine with mql5.
 

Really? EnumToString(anInt) compiles? I don't think so.

It was you that started the argument "Please pay attention to what you post. Your code doesn't compile as mql5." My post was about self-documenting code. You brought up a nit.

 
whroeder1:

Really? EnumToString(anInt) compiles? I don't think so.

It was you that started the argument "Please pay attention to what you post. Your code doesn't compile as mql5." My post was about self-documenting code. You brought up a nit.

You should try it (EnumToString(_Period)) first and then you should apologize to Alain and Lakshan. As I know you, you can't admit that you are wrong.

BTW your code seems to be self-documenting for you but that is absolutely subjective. If I (and I believe lots of other people too) read your code it seems to me very bad legible. Let everyone do it in his own way.

 

As before it has worked @Lakshan Perera 

some 1 has recommended i use this. I'm not a coder I paid for the code to be written then when i asked for the message to be edited the coder wanted more money so i thought i would ask.

how would i use the code below. I just want to see which works better  

IntegerToString(Period()) IntegerToString(Symbol())

Reason: