Symbol description in backtester report do not left justify/crash Amibroker

I have a very simple question regarding showing a stock description in the backtest report; however, there is something very serious here as well, because it can crash the system, not crash, but Amibroker just completely exit out of Windows without giving an error message.

The variable StockID was defined earlier as: StockID = trade.symbol();

Now when I use the line: bo.AddCustomMetric( "Stock Description :", StrFormat(StockID)); to display the stock description, this failed to left justify. I wish I can make it left justify, but can live with the way it is. (see diagram).

Here is a very interesting line that will crash Amibroker without an error message: adding +10 after strlen(StockID)

bo.AddCustomMetric( "Stock ID :", StrFormat("%-" + strlen(StockID) + 10 + "s", StockID));	 

The line above will crash Amibroker every time I run the code. Now if I don't add the 10 and just do this:

bo.AddCustomMetric( "Stock ID :", StrFormat("%-" + strlen(StockID) + "s", StockID));

This won't crash Amibroker but it won't left justified. I can add 1, or 2 ... up to 9, still won't left justified properly, but when I add +10, it crash the system.

Please help.

stock description

You are using the type formatters incorrectly.

%- is incorrect use
see here https://www.amibroker.com/guide/afl/strformat.html

Each extra parameter should match with its correct type like %s %f %g that is a placeholder in the first string parameter.

I am not aware of built-in function as i'm relatively new user but you can write your own function to pad desired number of spaces on the right of each string and get a workaround for left align justified strings.

There is nothing interesting. You are abusing the system by incorrectly using StrFormat. And adding spaces is an absurd attempt to do justification of text. That is NOT how it is done. Spaces DO NOT provide justification/alignment. The field type decides about alignment. And is it NOT you who decides. AmiBroker decides. Numeric fields are right-aligned, text fields are left-aligned.

2 Likes