How to make backtest of my portfolio

I would like to know How Can I do a backtest of muy portfolio in Amibroker?
Is there any way to create a CSV file of muy portfolio Movements?


Thanks Tomasz , but I want to make a backtest of my account to get all the reports ect…

How can i get a csv file from my account with all the information about my movements?

Best Regards

I have found this way to backtest a csv file.

The problem is that I run the backtest selecting the new file create, where I have written the code. It start running the backtest through the 2.000 symnbols I haven in my database. In my file I have only three or four movements.

Can you help me?

@Josmidur dont you think that your statements are a bit vague ? Perhpas you could desribe in details what do you really want, post the code you want to run and then expect some response, instead of posting some random mumbo jumbo.

I attach my code :

file = "C:\\Archivos de Programa\\AmiBroker\\Formulas\\Custom\\20.- CARTERA\\Cartera-Acciones.csv"; // change this to real location of your data file
dt = DateTime();
// Initialize variables
Buy = Sell = possize = 0; 
fh = fopen( file, "r" );
if( fh )
     while( ! feof( fh ) )
         line = fgets( fh );
         // get the ticker symbol from the file
         sym = StrExtract( line, 3, ';' );
         // if ticker matches current symbol
         if ( Name() == sym )
             // extract data from line of text
             trade = StrExtract( line, 2, ';' );
             trade_datetime = StrToDateTime( StrExtract( line, 2, ';' ) );
             price = StrToNum( StrExtract( line, 5,  ';' ) );
             shares = StrToNum( StrExtract( line, 4,  ';' ) );
             if ( trade == "Buy" )
                 newbuy = dt == trade_datetime;
                 Buy = Buy OR newbuy; // combine previous buy signals with new
                 BuyPrice = IIf( newbuy, price, BuyPrice );
                 possize = IIf( newbuy, shares, possize );
             if ( trade == "Sell" )
                 newsell = dt == trade_datetime;
                 Sell = Sell OR newsell; // combine previous sell signals with new
                 SellPrice = IIf( newsell, price, SellPrice );
     fclose( fh );
     Error("ERROR: file can not be open" );
SetPositionSize( 10, spsShares ); ```

This is the format of the information of the file "Cartera-Acciones.csv" thant this code try to open. I go to Analysis Window , select the file I attach before and I run the backtest but nothing happen, there is no report, ect... I do not what happen . Can  you help me? 




this line

trade_datetime = StrToDateTime( StrExtract( line, 2, ';' ) );

is incorrect. Instead of just copy&pasting formula(s) from knowledge base article(s) rather take a look at the content of your data file and check where date is actually placed (column index).

Also check whether you are comparing intraday datetime array to datetime fo file.

Why don’t you simply use one of several debugging methods instead of guessing and not seeing issues without them? See How do I debug my formula Then you wouldn’t be left in the dark and would not need to ask simple things all the time you can easily find out yourself pretty quickly.

Thanks @fxshrat, but I have corrected the index in the line you mention, but it does not work. Can you help me?


  1. Get from the prices for Apple.
  2. Put into csv file the below two lines
  1. Execute Tomasz’s code from ( from KB ) - run Scan
  2. If the scan runs correctly ( you have the two lines visible ) then most likely you have not sufficient funds in the Backtester Settings.

@teyano I have done what you told me but It does not work. I have no idea…Can you help me?

Did you perform the scan ? Note stooq tickers are with the sufix ‘.us’ - add to the ticker or to the .csv file.

@teyano I send you my two files

I have taken into consideration that my database have the same ticker name than the tickers in the cdv file. But no results. Anyway what I try is to make a backtest of all my trades , contained in the csv file.

This is the link for downloading the files

Thanks to @fxshrat the problem is already solved.

My problem was

wrong selected symbol in analysis and missing historical data