MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal

Automated Trading Language Documentation

Update to MetaTrader 4 build 735 and Test the VPS for Free


Initializes a string by specified symbols and provides the specified string size.

bool  StringInit(
   string&   string_var,       // string to initialize
   int       new_len=0,        // required string length after initialization
   ushort    character=0       // symbol, by which the string will be filled



[in][out]  String that should be initialized and deinitialized.


[in]  String length after initialization. If length=0, it deinitializes the string, i.e. the string buffer is cleared and the buffer address is zeroed.


[in]  Symbol to fill the string.

Return Value

In case of success returns true, otherwise - false. To get the error code call GetLastError().


If  character=0 and the length new_len>0, the buffer of the string of indicated length will be distributed and filled by zeroes. The string length will be equal to zero, because the whole buffer is filled out by string terminators.


void OnStart()
   string str;
   Print("str = ",str,": StringBufferLen(str) = ",
         StringBufferLen(str),"  StringLen(str) = ",StringLen(str));
/*  Result
str = : StringBufferLen(str) = 200   StringLen(str) = 0

See also

StringBufferLen, StringLen

Updated: 2014.10.21