Skip to content

Instantly share code, notes, and snippets.

@currencysecrets
Created August 9, 2013 12:51
Show Gist options
  • Save currencysecrets/6193393 to your computer and use it in GitHub Desktop.
Save currencysecrets/6193393 to your computer and use it in GitHub Desktop.
Simple MQL4 Utility Functions. Converting datetime to string. Converting double to a specific number of decimal places. Converting price to string.
/**
* @double price to convert to string
* @int number of decimal places to show (default = Digits of active currency)
*/
string D( double price, int num = -1 ) {
if ( num == -1 ) { num = Digits; }
return( DoubleToStr( price, num ) );
}
/**
* @double price to clip
* @int number of decimal places to show (default = Digits of active currency)
*/
double N( double price, int num = -1 ) {
if ( num == -1 ) { num = Digits; }
return( NormalizeDouble( price, num ) );
}
/**
* @datetime datetime to convert to string
* @int format of datetime (default = TIME_DATE|TIME_MINUTES|TIME_SECONDS; 0 = TIME_DATE; else = TIME_DATE|TIME_MINUTES)
*/
string T( datetime d, int type = 1 ) {
if ( type == 1 ) {
return( TimeToStr( d, TIME_DATE|TIME_MINUTES|TIME_SECONDS ) );
} else if ( type == 0 ) {
return( TimeToStr( d, TIME_DATE ) );
} else {
return( TimeToStr( d, TIME_DATE|TIME_MINUTES ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment