[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Trading and managing multiple position



PureBytes Links

Trading Reference Links

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.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@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
Investment management software Investment property software Investment software
Investment tracking software Return on investment software

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___