Hello,
No, in the example I gave you they will exit after 10 days
since initial entry.
You could do separate exits using pyramiding code
but you would need to write a loop
and track which entry matches which exit and set sizes
accordingly.
For this particular application, I think that custom
backtester is better suited and leads to simpler and
shorter code and actual code would look as
follows:
Sell=Short=Cover=0; // real
rules are defined inside custom backtest proc
Buy = IIf( Close >
Open,
sigScaleIn, 0 );
// entry rule
SetCustomBacktestProc(""); //
enable custom backtest
if( Status("action") == actionPortfolio )
{ // actual backtest routine
//
(low-level)
bo = GetBacktesterObject();
// actual backtest loop
bo.PreProcess();
for( i = 0; i
< BarCount; i++ ) {
// first
update backtest stats and handle stops bo.UpdateStats( i,
0 );
bo.HandleStops( i );
_TRACE("Bar
" + i );
for( sig
= bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i) )
{
if( sig.IsEntry()
OR
sig.IsScale() ) {
_TRACE("ENTER " + sig.Symbol );
bo.EnterTrade(
i, sig.Symbol, True, sig.Price, 5000 /* $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 >= 10 ) {
// EXIT WHEN POSITION IS 10 bars old
_TRACE("EXIT " + OpenPos.Symbol );
bo.ExitTrade( i, OpenPos.Handle, OpenPos.GetPrice( i, "O" ) );
}
}
bo.UpdateStats( i, 2 ); }
bo.PostProcess();
}
_TRACEs lines are just for extra debuggin info. You may remove
them to get more speed.
Best regards, Tomasz Janeczko amibroker.com
----- Original Message -----
Sent: Thursday, March 08, 2007 9:31
PM
Subject: Re: [amibroker] Trading and
managing multiple position
Hello Tomasz,
If I used the ScaleIn/ScaleOut. Will each entry have the same exit
condition?
For example:
Entry if Close > Open
Exit 10 days later
Will each entry exit 10days later or will they all the position be closed
on first exit?
If I enter a different positionsize for each entry, will it automatically
determine entry quanity and only sell correct entry quantity?
Thanks for the help.
Tomasz Janeczko
<groups@xxxxxxxxxxxxx> wrote:
Hello, It is very easy, just use pyramiding http://www.amibroker.com/guide/h_pyramid.htmlBuy
= IIF( C > O, sigScaleIn, 0 ); Sell = 0; ApplyStop( stopTypeNBar,
stopModeBars, 10 ); There is simply NO reason to treat this
"separately" because on your brokerage account you will have them all
listed as one position. But if you are determined to have them
separate the sample code how to do that is included in the User's Guide
as well as in the Release Notes document CBT: Trade object has now
"Handle" property that can be passed to ExitTrade and ScaleTrade methods
instead of symbol to allow control over exiting/scaling multiple
positions of the same symbol CHANGES FOR VERSION 4.76.0 (as compared
to 4.75.2) CBT: Trade object has now "Handle" property that can be passed
to ExitTrade and ScaleTrade methods instead of symbol to allow control
over exiting/scaling multiple positions of the same symbol // 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();
Best regards, Tomasz
Janeczko amibroker.com ----- Original Message ----- From:
"chwinc2000" <chwinc2000@xxxxxxcom> To:
<amibroker@xxxxxxxxxps.com> Sent:
Thursday, March 08, 2007 1:59 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. > > > > > Please note that this group is
for discussion between users only. > > To get support from
AmiBroker please send an e-mail directly to > SUPPORT {at}
amibroker.com > > For NEW RELEASE ANNOUNCEMENTS and other news
always check DEVLOG: > http://www.amibroker.com/devlog/ > >
For other support material please check also: > http://www.amibroker.com/support.html > >
Yahoo! Groups Links > > > > >
Food
fight? Enjoy some healthy debate in the Yahoo!
Answers Food & Drink Q&A.
__._,_.___
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
SPONSORED LINKS
__,_._,___
|