StringFormat

この関数は、取得されたパラメータをフォーマットして文字列として返します。

string  StringFormat(
  string  format,    // フォーマット記述した文字列
  ...    ...        // パラメータ
  );

パラメータ

フォーマットでありません。

[in]  フォーマット方法を含む文字列。フォーマットの規則は PrintFormat 関数の場合と同じです。

...

[in]  コンマで区切られたパラメータ

戻り値

文字列

例:

void OnStart()
{
//-- 文字列変数
  string output_string;
  string temp_string;
  string format_string;
//--- ヘッダを準備
  temp_string=StringFormat("Contract specification for %s:\n",_Symbol);
  StringAdd(output_string,temp_string);
//--- int 値の出力
  int digits=(int)SymbolInfoInteger(_Symbol,SYMBOL_DIGITS);
  temp_string=StringFormat("   SYMBOL_DIGITS = %d (number of digits after the decimal point)\n",
                          digits);
  StringAdd(output_string,temp_string);
//--- double 値の出力(小数点以下の桁数は変動)
  double point_value=SymbolInfoDouble(_Symbol,SYMBOL_POINT);
  format_string=StringFormat("   SYMBOL_POINT = %%.%df (point value)\n",
                            digits);
  temp_string=StringFormat(format_string,point_value);
  StringAdd(output_string,temp_string);
//--- int value output
  int spread=(int)SymbolInfoInteger(_Symbol,SYMBOL_SPREAD);
  temp_string=StringFormat("   SYMBOL_SPREAD = %d (current spread in points)\n",
                          spread);
  StringAdd(output_string,temp_string);
//--- int 値の出力
  int min_stop=(int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
  temp_string=StringFormat("   SYMBOL_TRADE_STOPS_LEVEL = %d (minimal indention in points for Stop orders)\n",
                          min_stop);
  StringAdd(output_string,temp_string);
//--- double (分数部なし)
  double contract_size=SymbolInfoDouble(_Symbol,SYMBOL_TRADE_CONTRACT_SIZE);
  temp_string=StringFormat("   SYMBOL_TRADE_CONTRACT_SIZE = %.f (contract size)\n",
                          contract_size);
  StringAdd(output_string,temp_string);
//--- デフォルト精度での double 値の出力
  double tick_size=SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);
  temp_string=StringFormat("   SYMBOL_TRADE_TICK_SIZE = %f (minimal price change)\n",
                          tick_size);
  StringAdd(output_string,temp_string);
//--- スワップ計算モードの決定
  int swap_mode=(int)SymbolInfoInteger(_Symbol,SYMBOL_SWAP_MODE);
  string str_swap_mode;
  switch(swap_mode)
    {
    case SYMBOL_SWAP_MODE_DISABLED: str_swap_mode="SYMBOL_SWAP_MODE_DISABLED (no swaps)"; break;
    case SYMBOL_SWAP_MODE_POINTS: str_swap_mode="SYMBOL_SWAP_MODE_POINTS (in points)"; break;
    case SYMBOL_SWAP_MODE_CURRENCY_SYMBOL: str_swap_mode="SYMBOL_SWAP_MODE_CURRENCY_SYMBOL (in money, in base currency of the symbol)"; break;
    case SYMBOL_SWAP_MODE_CURRENCY_MARGIN: str_swap_mode="SYMBOL_SWAP_MODE_CURRENCY_MARGIN (in money, in margin currency of the symbol)"; break;
    case SYMBOL_SWAP_MODE_CURRENCY_DEPOSIT: str_swap_mode="SYMBOL_SWAP_MODE_CURRENCY_DEPOSIT (in money, in client deposit currency)"; break;
    case SYMBOL_SWAP_MODE_INTEREST_CURRENT: str_swap_mode="SYMBOL_SWAP_MODE_INTEREST_CURRENT (as the specified annual interest from the instrument price at calculation of swap)"; break;
    case SYMBOL_SWAP_MODE_INTEREST_OPEN: str_swap_mode="SYMBOL_SWAP_MODE_INTEREST_OPEN (as the specified annual interest from the position open price)"; break;
    case SYMBOL_SWAP_MODE_REOPEN_CURRENT: str_swap_mode="SYMBOL_SWAP_MODE_REOPEN_CURRENT (by reopening positions by the close price +/- specified number of points)"; break;
    case SYMBOL_SWAP_MODE_REOPEN_BID: str_swap_mode="SYMBOL_SWAP_MODE_REOPEN_BID (by reopening positions by the current Bid price +/- specified number of points)"; break;
    }
//--- 文字列値の出力
  temp_string=StringFormat("   SYMBOL_SWAP_MODE = %s\n",
                          str_swap_mode);
  StringAdd(output_string,temp_string);
//--- デフォルト精度でのdouble 値の出力
  double swap_long=SymbolInfoDouble(_Symbol,SYMBOL_SWAP_LONG);
  temp_string=StringFormat("   SYMBOL_SWAP_LONG = %f (long swap value)\n",
                          swap_long);
  StringAdd(output_string,temp_string);
//--- デフォルト精度でのdouble 値の出力
  double swap_short=SymbolInfoDouble(_Symbol,SYMBOL_SWAP_SHORT);
  temp_string=StringFormat("   SYMBOL_SWAP_SHORT = %f (short swap value)\n",
                          swap_short);
  StringAdd(output_string,temp_string);
//--- 取引モードの決定
  int trade_mode=(int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_MODE);
  string str_trade_mode;
  switch(trade_mode)
    {
    case SYMBOL_TRADE_MODE_DISABLED: str_trade_mode="SYMBOL_TRADE_MODE_DISABLED (trade is disabled for the symbol)"; break;
    case SYMBOL_TRADE_MODE_LONGONLY: str_trade_mode="SYMBOL_TRADE_MODE_LONGONLY (only long positions are allowed)"; break;
    case SYMBOL_TRADE_MODE_SHORTONLY: str_trade_mode="SYMBOL_TRADE_MODE_SHORTONLY (only short positions are allowed)"; break;
    case SYMBOL_TRADE_MODE_CLOSEONLY: str_trade_mode="SYMBOL_TRADE_MODE_CLOSEONLY (only position close operations are allowed)"; break;
    case SYMBOL_TRADE_MODE_FULL: str_trade_mode="SYMBOL_TRADE_MODE_FULL (no trade restrictions)"; break;
    }
//--- 文字列値の出力
  temp_string=StringFormat("   SYMBOL_TRADE_MODE = %s\n",
                          str_trade_mode);
  StringAdd(output_string,temp_string);
//--- コンパクトな形式での double 値の出力
  double volume_min=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
  temp_string=StringFormat("   SYMBOL_VOLUME_MIN = %g (minimal volume for a deal)\n",volume_min);
  StringAdd(output_string,temp_string);
//--- コンパクトな形式での double 値の出力
  double volume_step=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
  temp_string=StringFormat("   SYMBOL_VOLUME_STEP = %g (minimal volume change step)\n",volume_step);
  StringAdd(output_string,temp_string);
//--- コンパクトな形式での double 値の出力
  double volume_max=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX);
  temp_string=StringFormat("   SYMBOL_VOLUME_MAX = %g (maximal volume for a deal)\n",volume_max);
  StringAdd(output_string,temp_string);
//--- 契約金計算モードの決定
  int calc_mode=(int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_CALC_MODE);
  string str_calc_mode;
  switch(calc_mode)
    {
    case SYMBOL_CALC_MODE_FOREX:str_calc_mode="SYMBOL_CALC_MODE_FOREX (Forex)";break;
    case SYMBOL_CALC_MODE_FUTURES:str_calc_mode="SYMBOL_CALC_MODE_FUTURES (futures)";break;
    case SYMBOL_CALC_MODE_CFD:str_calc_mode="SYMBOL_CALC_MODE_CFD (CFD)";break;
    case SYMBOL_CALC_MODE_CFDINDEX:str_calc_mode="SYMBOL_CALC_MODE_CFDINDEX (CFD for indices)";break;
    case SYMBOL_CALC_MODE_CFDLEVERAGE:str_calc_mode="SYMBOL_CALC_MODE_CFDLEVERAGE (CFD at leverage trading)";break;
    case SYMBOL_CALC_MODE_EXCH_STOCKS:str_calc_mode="SYMBOL_CALC_MODE_EXCH_STOCKS (trading securities on a stock exchange)";break;
    case SYMBOL_CALC_MODE_EXCH_FUTURES:str_calc_mode="SYMBOL_CALC_MODE_EXCH_FUTURES (trading futures contracts on a stock exchange)";break;
    case SYMBOL_CALC_MODE_EXCH_FUTURES_FORTS:str_calc_mode="SYMBOL_CALC_MODE_EXCH_FUTURES_FORTS (trading futures contracts on FORTS)";break;
    }
//--- 文字列値の出力
  temp_string=StringFormat("   SYMBOL_TRADE_CALC_MODE = %s\n",
                          str_calc_mode);
  StringAdd(output_string,temp_string);
//--- 小数点以下の桁数が 2 桁の double 値の出力
  double margin_initial=SymbolInfoDouble(_Symbol,SYMBOL_MARGIN_INITIAL);
  temp_string=StringFormat("   SYMBOL_MARGIN_INITIAL = %.2f (initial margin)\n",
                          margin_initial);
  StringAdd(output_string,temp_string);
//--- 小数点以下の桁数が 2 桁の double 値の出力
  double margin_maintenance=SymbolInfoDouble(_Symbol,SYMBOL_MARGIN_MAINTENANCE);
  temp_string=StringFormat("   SYMBOL_MARGIN_MAINTENANCE = %.2f (maintenance margin)\n",
                          margin_maintenance);
  StringAdd(output_string,temp_string);
//--- int 値の出力
  int freeze_level=(int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_FREEZE_LEVEL);
  temp_string=StringFormat("   SYMBOL_TRADE_FREEZE_LEVEL = %d (order freeze level in points)",
                          freeze_level);
  StringAdd(output_string,temp_string);
  Print(output_string);
  Comment(output_string);
/* execution result
  Contract specification for EURUSD:
    SYMBOL_DIGITS = 5 (number of digits after the decimal point)
    SYMBOL_POINT = 0.00001 (point value)
    SYMBOL_SPREAD = 10 (current spread in points)
    SYMBOL_TRADE_STOPS_LEVEL = 18 (minimal indention in points for Stop orders)
    SYMBOL_TRADE_CONTRACT_SIZE = 100000 (contract size)
    SYMBOL_TRADE_TICK_SIZE = 0.000010 (minimal price change)
    SYMBOL_SWAP_MODE = SYMBOL_SWAP_MODE_POINTS (in points)
    SYMBOL_SWAP_LONG = -0.700000 (buy order swap value)
    SYMBOL_SWAP_SHORT = -1.000000 (sell order swap value)
    SYMBOL_TRADE_MODE = SYMBOL_TRADE_MODE_FULL (no trade restrictions)
    SYMBOL_VOLUME_MIN = 0.01 (minimal volume for a deal)
    SYMBOL_VOLUME_STEP = 0.01 (minimal volume change step)
    SYMBOL_VOLUME_MAX = 500 (maximal volume for a deal)
    SYMBOL_TRADE_CALC_MODE = SYMBOL_CALC_MODE_FOREX (Forex)
    SYMBOL_MARGIN_INITIAL = 0.00 (initial margin)
    SYMBOL_MARGIN_MAINTENANCE = 0.00 (maintenance margin)
    SYMBOL_TRADE_FREEZE_LEVEL = 0 (order freeze level in points)
*/
}

参照

PrintFormatDoubleToStringColorToStringTimeToString