there is this code
// This is sample formula that allows
// to open multiple, separate positions on the same symbol
// without averaging effect (i.e. each position on the same
// symbol is completely independent).
//
// Sample code is provided for trading one symbol
// Enter symbol you want to trade below
Symbol = "MSFT";
Buy=Sell=Short=Cover=0; // real rules are defined inside custom backtest proc
SetCustomBacktestProc(""); // enable custom backtest
if( Status("action") == actionPortfolio )
{
// actual backtest routine
// (low-level)
bo = GetBacktesterObject();
SetForeign( Symbol );
// make sure to calculate actual buy and buyprice arrays for symbol we need
to backtest
Buy = 1; // For testing purposes just enter new position every bar
BuyPrice = Open;
RestorePriceArrays();
// actual backtest loop
bo.PreProcess();
for( i = 1; i < BarCount; i++ )
{
// first update backtest stats and handle stops
bo.UpdateStats( i, 0 );
bo.HandleStops( i );
bo.RawTextOutput("Bar " + i );
if( Buy[ i - 1 ] ) // if buy signal in previous bar
{
bo.EnterTrade( i, Symbol, True, BuyPrice[ i ], 500 /* $5000 into one
trade */);
}
for( OpenPos = bo.GetFirstOpenPos(); OpenPos; OpenPos =
bo.GetNextOpenPos() )
{
// exit positions if their age is > 5 bars and they are profitable
if( OpenPos.BarsInTrade > 5 AND OpenPos.GetProfit() > 0 )
{
// HERE IS A NEW PART !!!
// WE ARE PASSING HANDLE instead of ticker symbol
// THIS ENSURES PROPER OPERATION even if we have multiple positions
of the same
// stock
bo.ExitTrade( i, OpenPos.Handle, OpenPos.GetPrice( i, "O" ) );
}
}
bo.RawTextOutput("Number of open positions: " + bo.GetOpenPosQty() );
bo.UpdateStats( i, 2 );
}
bo.PostProcess();
}
see: http://www.amibroker.com/devlog/wp-content/uploads/2006/03/ReadMe4781.html
This is the area I hope Amibroker will improve. Although it is said lots is
possible in Amibroker and one can perform complex portfolio backtests it seems
to me it is impossible to find out what is exactly possible and what is not.
And if something is possible how to do it. The main reason I believe Amibroker
is not portfolio trading oriented is because Amibroker is built for speed and
is very usefull for single symbols systems. But complex portfolio systems is
where I feel the small trader can have an edge ...
rgds, Ed
----- Original Message -----
From: chwinc2000
To: [email protected]
Sent: Thursday, March 08, 2007 2:00 AM
Subject: [amibroker] Trading and managing multiple position
Hello,
Does anyone know how to enter and manage multiple positions on the
same symbol?
For example:
Buy when C>O
Sell 10 days longer.
Obviously I can have up to 9 Long positions at once. I would like each
trade to show up separately on the Backtest report so I can't use
Scale In/ Scale Out.
Does anyone know how to do this?
Thanks for the help.