amibroker

HomeKnowledge Base

How does the intraday-to-daily compression work?

When you are using intraday database daily candles are usually constructed by time-compression of intraday (for example 1-minute data). AmiBroker offers lots of flexibility when it comes to defining intraday-to-daily time compression.
(more…)

How to create copy of portfolio equity?

As you know Portfolio backtester creates special ticker “~~~EQUITY” which holds portfolio-level equity of the system under test. Some may find it useful to save this equity into another symbol after backtest for future analysis and/or comparison. Good news is that it is possible to do that automatically using custom backtester procedure and AddToComposite function. The formula below shows how.
(more…)

Getting X, Y co-ordinates of Study()

The following code sample shows how to get date/time (X co-ordinate) and value (Y co-ordinate) of starting and ending point of manually drawn study.
(more…)

Re-balancing open positions

Here is an example that shows how to code rotational trading system with rebalancing. The system buys and shorts top 20 securities according to absolute value of positionscore (user definable – in this example we used 20 day rate-of-change) – each at 5% of equity then each day it rebalances existing positions to 5% if only the difference between current position value and “ideal” value is greater than 0.5% and bigger than one share.

Note that this code sample uses Custom Backtester interface that is documented here.

EnableRotationalTrading(); 

EachPosPercent 5

PositionScore ROCC20 ); 

PositionSize = -EachPosPercent

SetOption("WorstRankHeld"40 );
SetOption("MaxOpenPositions"20 ); 

SetOption("UseCustomBacktestProc"True ); 

if( 
Status("action") == actionPortfolio )
{
  
bo GetBacktesterObject();

  
bo.PreProcess(); // Initialize backtester

  
for(bar=0bar BarCountbar++)
  {
   
bo.ProcessTradeSignalsbar );
  
   
CurEquity bo.Equity;
  
   for( 
pos bo.GetFirstOpenPos(); pospos bo.GetNextOpenPos() )
   {
    
posval pos.GetPositionValue();
   
    
diff posval 0.01 EachPosPercent CurEquity;
    
price pos.GetPricebar"C" );
   
    
// rebalance only if difference between desired and
    // current position value is greater than 0.5% of equity
    // and greater than price of single share
    
if( diff != AND
        
absdiff ) > 0.005 CurEquity AND
        
absdiff ) > price )
    {
     
bo.ScaleTradebarpos.Symboldiff 0priceabsdiff ) );
    }
   }
  }
  
bo.PostProcess(); // Finalize backtester

Preventing exit during first N bars

Here is sample technique that allows to prevent exiting position during first N bars since entry. The implementation uses loops that checks for signals in Buy array and if it finds one it starts counting bars in trade. During first N bars all sell signals are then removed (set to zero) only once counter reaches user-defined limit sell signals are accepted.
(more…)

How to export quotations from AmiBroker to CSV file ?

The easiest way to export quotes to CSV file is to use the below formula from Automatic Analysis window:
(Analysis -> Automatic Analysis)
(more…)

How to use your LiveCharts account with AmiQuote ?

UPDATE April 2, 2008: We received the following information from eSignal:
” It wasn’t our intention to have this product be made compatible with 3rd party software[…] The new version of LiveCharts uses a different method of exporting data and it will no longer work with AmiQuote starting the week of April 14th, 2008.”

This effectivelly means that the instructions below will become obsolete April 14th, 2008.

You can use your Livecharts ($9.95/month) subscription to feed AmiQuote with real time data from Lycos. However, there is one extra step involved in order to make it work.
(more…)

How to change the title line in my custom indicator ?

To have custom title in the indicator window, you can define Title variable within the indicator’s code, e.g:
(more…)