Modify the Entry/Exit Price output and Datetime format in backtest report

Dear Amibroker Community,

I am currently having some issue with formating some output in the backtest report. In particular, here are some of the things I want to change:

  1. The Date column: I only want the enter and exit date without the time. In other word, I would like to get rid of the 00:00:00 behind the Month/Day/Year
  2. The Entry/Exit price: Some of the entry/exit price appear to have many decimal degits. How do I get rid of the extra digits and keep it nicely in 2 digit decimal place only?
    The reason I need the 2 digits format is for me to export it to csv automatically using batch function and then upload to my website.

I am supposed that I could add Custom metric, but I am just wondering if there might be any useful code I could put in my formular or any parameter/setting I could change anywhere?

Here is what I am seeing on my backtest output:

closing price

I'm not sure what code you're using to format the output of your backtest, but you can specify exact number of decimal digits with AddColumn(). For example, AddColumn( Close, "Close", 1.2 ); will format the close price to two decimal places.

Decimal place format is covered thoroughly in the first paragraph here:

As for the date/time formatting, I assume that you have already addressed system time settings as mentioned by Tomasz:

Assuming system formatting isn't the issue, I believe - based on the documentation - you should be able to get the date/time, and format it any way you would like for your needs using DateTimeToStr() and/or DateTimeFormat() - though you might have to use AddTextColumn() in your output.

Hopefully that helps some.

1 Like

Thank you very much @tallship
I looked into the links you share and many other solutions online.
Eventually, I found an alternative solution: get rid of the whole column with date/time all together and add another column with the right format.

Here is my solution:
Basically the process is to delete the default columns and add my custom columns.

SetOption( "NoDefaultColumns", True );
AddTextColumn( Name(), "Ticker", 1, colorDefault, colorDefault, 1 );

dt = DateTime();
dn = DateNum();

dates = DateTimeConvert( 2, dn, Null );
AddColumn( dates, "Date", formatDateTime );

Buy_dn = ValueWhen(Buy, dn);
Buy_date = DateTimeConvert(2,Buy_dn,Null);
AddColumn(Buy_date,"Buy date",formatdatetime);

This is the result:
nice columns

Hopefully is helpful to anyone out there :slight_smile:


This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.