How to get latest quotes from watchlist into a single CSV file

Hi Guys,

Many here will be familiar with exporting data into csv files using code like this:

fh = fopen( "DataFor"+Name()+".csv", "w" );
if( fh )
{
  fputs("Symbol,Date,Time,Open,High,Low,Close,OpenInt,Volume\\n", fh );

  dn = DateNum();
  tn = TimeNum();
 
  for( i = 0; i < BarCount; i++ )
  {
   Line = Name() +
   StrFormat(",%06.0f,%06.0f,%g,%g,%g,%g,%g,%g\\n",
   dn[ i ] % 1000000,
   tn[ i ],
   Open[ i ],
   High[ i ],
   Low[ i ],
   Close[ i ],
   OpenInt[ i ],
   Volume[ i ] );
  
   fputs( Line, fh );
  }
 
  fclose( fh );
}

Buy=Sell=0; // for scan
Filter = Status("lastbarinrange");
AddTextColumn("Export done", "Status");

code copied from amibroker.com

I'm looking to export the latest closing price for all the symbols in my selected watchlist into a single file...

Any help would be much appreciated!

Cheers

Everything is already covered in existing documentation:
http://www.amibroker.com/kb/2006/03/04/how-to-export-quotations-from-amibroker-to-csv-file/

It does not require any coding, just run exploration and then File->Export menu

Every output that you see in Analysis window can be exported to single CSV file by merely using File->Export menu as documented in the manual:
http://www.amibroker.com/guide/h_newanalysis.html

Quote:

Exporting and importing result list

To export data to CSV file or HTML file use File -> Export HTML/CSV menu (from the main window). To import previously exported HTML file use File->Import HTML... as shown in the picture below. Note that these menu items appear only if you have New Analysis window active.
image

Also use search before creating new thread. Export is already covered in 130 existing threads on this forum: https://forum.amibroker.com/search?q=export

1 Like

Hi Tomaz,

Again thankyou for your response, I am aware of this thread and quite familiar with the process of exporting from the analysis window.

Whilst my request may seem like reinventing the wheel, I am hoping to move this from a manual exercise to something that happens when I explore or scan my afl-file which also contains my trading system.

The idea being that when I explore my code for Buy and Sell signals it automatically exports the latest quotes from all symbols into a csv file within the Amibroker main directory, called let’s say (“systemX - latestQuotes”).

A separate spreadsheet which I use to monitor my live trades can then use the data retrieval feature in excel to update all prices of positions I currently hold.

It would simply make monitoring my trading system a little quicker and easier.

..........

Is it possible to run a FOR loop over the selected watchlist and select each symbol individually using SetForeign to extract the latest quote.

..........

If this makes no sense I’ll just go back to exporting the quotes manually ... at the end of the day it only takes a few more minutes to use Filter and export them....

Kinds Regards, Matthew Wills

If you want to automate export then simply use batch processor of AmiBroker. It has file export option.

So save your exploration as analysis project. File extension of analysis projects is "APX". Before saving analysis to apx file set "Filter" (to include your watchlist) and analysis "Range" there.

309

Then create batch process in batch window and save to batch file (extension "ABB").
Then open AB task scheduler and set your schedule.

639

Or instead of using task scheduler simply open your batch file manually from File - Open (if you don't need scheduled runs). Then click "Run" in batch window. The batch process loads your project, runs your exploration and exports result list to file.

5 Likes

Yes batch seems to be the best solution for what you are after.

Alternatively you could write your exploration using original code and append mode, but keep keep in mind to turn on sharing flag because without that you would got problems in multithreading. Exact example is included in the Knowledge Base: http://www.amibroker.com/kb/2016/01/27/how-to-write-to-single-shared-file-in-multi-threaded-scenario/

2 Likes

Thankyou all!

I'll go with the batch option and let you know how it goes

Many thanks again
Matt

hayy you are awesome .. can you please tell me how to run the batch in every 10 seconds,??

hi TOMASZ .. can you please tell me how to run the batch in every 10 seconds . please ??