Australian (ASX) Stock Market Forum

Amibroker: How to sort date columns in chronological order?

Joined
28 May 2020
Posts
127
Reactions
229
Hi,

I'm backtesting a system, here is a code excerpt:

// Set Column Sort Order
switch(Status("action")) {
case actionScan:
SetSortColumns(3, 2, 4);
break;
case actionExplore:
SetSortColumns(2, -3, -4, 7);
break;
case actionBacktest:
SetSortColumns(3, 2);
break;
}

In all cases, the first column in SetSortColumns is a Date column.

However, this sorts in character order, not chronological order.

See attached screenshot.

Thanks,
Linus
 

Attachments

  • 2020-07-20_08-50-45.png
    2020-07-20_08-50-45.png
    69.7 KB · Views: 12
I've got an answer to this issue after posting to the Amibroker forum.

The issue is due to my regional settings in Control Panel:

upload_2020-7-22_11-26-2.png

I have used this setting for years, and it is my preferred setting, since it is IMO the most unambiguous date format when working with overseas colleagues. There is no doubt as to the date, regardless of where you are in the world.

However, Amibroker does not handle this properly, and sorts the date column AFTER applying the regional setting to the underlying data. So, the dates sort in alphabetical rather than chronological order.

Amibroker is the first software package in years to not work with this regional setting:

  • Excel has no problem with dates. You create a date column, can apply any number of desired formats, and it always sorts in chronological order.
  • The "dir /o:d" and "dir /o:-d" sorts files in last modified chronological order, either ascending or descending respectively.
  • Just two examples...As I said, this is the first time in years that my desired regional setting caused a software issue.
I raised this with Amibroker, but they do not consider this a bug.

I tested all the other regional settings, both English (Australia) and English (US) format. The dd-mmm-yy (eg. 25-Dec-20) and its variants were the only ones that caused sorting issues.

I've changed my regional setting to the ISO 8601 format yyyy-mm-dd, which fixed the issue.

Hope this helps if someone runs into this (admittedly esoteric) problem in the future and finds this post.
 
Top