Print out content of a matrix, array or object

Hello,

is it possible to print out the content of a matrix, array or any object at once.
This would be helpful during development if AFL code,
For instance I want to know all values of the trade object at the customer backtest. At the momentI am using _TRACE-statemens for each attribute of the object "trade":

	for (trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade()) {
		_TRACEF("EntryDateTime %s", DateTimeToStr(trade.EntryDateTime));
		_TRACEF("EntryPrice %g", trade.EntryPrice);
		_TRACEF("ExitDateTime  %s", DateTimeToStr(trade.ExitDateTime));
		_TRACEF("ExitPrice  %g", trade.ExitPrice);
		_TRACEF("BarsInTrade  %g", trade.BarsInTrade);
		_TRACEF("Symbol  %s", trade.Symbol);
		_TRACEF("Shares  %g", trade.Shares);
		_TRACEF("GetMFE  %g", trade.GetMFE);
		_TRACEF("GetMAE  %g", trade.GetMAE);

So. a call of _TRACE("trade", trade) would be nice:

	for (trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade()) {
		_TRACE("trade " + trade);

In the programming language Java the method Object::toString can be used to format the object content to a human readable string.

Matrices have MxToString: http://www.amibroker.com/guide/afl/mxtostring.html
Arrays and numbers are auto-converted to string when appended to string via type coercion, so you just type:

"Price is " + Close;

Objects don't have such functionality because it would have undesirable side effects (difficulty to find errors when somebody used "+" on object). But adding .toString() method to objects is good idea.

4 Likes