PureBytes Links
Trading Reference Links
|
Hello,
It is very easy, just use pyramiding
http://www.amibroker.com/guide/h_pyramid.html
Buy = 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@xxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
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
>
>
>
>
>
------------------------ Yahoo! Groups Sponsor --------------------~-->
Yahoo! Groups gets a make over. See the new email design.
http://us.click.yahoo.com/hOt0.A/lOaOAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~->
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
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|