printf (string format, ...)

Prints text and variables in a log file and the message window. This allows to display messages and record variables.

print (int to, string format, ...)

Prints text and variables to a target channel given by the to parameter, such as the log file, a .csv spreadsheet file, the HTML status page, or the performance report.

msg (string format, ...): int

Displays text and variables in a modal or nonmodal message box with [Yes] and [No] buttons, and waits for the user to click one of the buttons.

Returns

0 when [No] was clicked, 1 when [Yes] was clicked.

Parameters:

to

TO_WINDOW - print in [Test] and [Trade] mode to the message window and the log file (default for printf).
TO_LOG - print in [Test] mode only to the log file, in [Trade] and in STEPWISE mode also to the message window.
TO_FILE - print in all modes to the log file.
TO_ANY - print in all modes to the message window and log file.
TO_DIAG - print to the diag.txt file (see Verbose). Note that log files and diag.txt file are not yet open in the INITRUN.
TO_CSV - print into a file with the name of the script and extension ".csv", for exporting data.
TO_REPORT - print in the EXITRUN to the performance report, for displaying additional performance parameters.
TO_HTML - print in [Trade] or in STEPWISE mode to the HTML file that displays the live trading status. HMTL format codes can be included in the text.
TO_TITLE - print to the title bar.
TO_INFO - print to the info field. An empty format string - print(TO_INFO, ""); - displays the current account or simulation state in the info field.
TO_PANEL - print to the caption bar of a control panel.

format

C-style format string, containing the text to be displayed and optional placeholders for subsequent variables. The placeholders begin with a percent sign '%' and define the format of the displayed number in the following way:
"%[flags][width][.precision]f" for var or double variables with decimals. Example: "%+4.1f" prints a var with +/- sign, 4 digits, and one decimal. For printing float variables, use the %f placeholder and typecast them to (var).
"%[flags][width]d" for decimal int, long, short, char, or bool variables.
"%s" for strings.
[flags] = Optional one or more of the following characters:
   - = Left align the number within the given field width. Default: Right align.
   + = Prefix the number with a + or - sign. Default: Sign only for negative values.
   0 = Leading zeros are added until width is reached. Default: Blanks are added.
   blank (' ') = Prefix positive numbers with a single blank. Default: No single blank.
   # = Forces the number to contain a decimal point. Default: Decimal point only when the number is no integer.
[width] = Optional minimum number of characters displayed.
[.precision] = Optional maximum number of digits after the decimal point.

... Expressions or variables, one for each placeholder in the format text.

Remarks:

Examples:

// printf example
var vPrice = 123.456;
float fDiscount = 1.5;
int nNumber = 77;
...
printf("\nPrice %.3f for %d items, total %.3f, discount %.1f%%",
  vPrice, nNumber, nNumber*vPrice, (var)fDiscount);
// HTML status message example
if(ATR(30) < Threshold)
  print(TO_HTML,"<br>Low volatility - ATR30 = %.3f",ATR(30));
// nonmodal box example
function run()
{
  if(is(INITRUN))
    msg("#Nonmodal message box.\nClick [Ok] to exit script!");
  if(is(AFFIRMED))
    quit("Ok!");
  Sleep(10);
}

See also:

sound, string, keys, sprintf, strf, progress, watch

► latest version online