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

[amibroker] Re: Mony managmenet question



PureBytes Links

Trading Reference Links

Use bo.ScaleTrade. Take a look at TJ's example:

http://www.amibroker.com/kb/2006/03/06/re-balancing-open-positions/

PS

--- In amibroker@xxxxxxxxxxxxxxx, "rashidfarah_98" 
<rashidfarah_98@xxx> wrote:
>
> Does any one know how to exit from a position partially
> after it rises a certain % in relation to the
> available portfolio equity?
> 
> 
> For example, if I initially start with $50,000,then
> open 10 positions each holding $10,000. That is 20% of
> the total equity for each position.
> Now, I would have a trailing stop to exit say 7%. But
> also I would not allow a position to comprise more
> than 30% of the total portfolio equity. Once the
> position reaches 30% of folio I sell 10% and keep the
> value that is equivalent to the original 20%.
> 
> So the question is how do I exit partially. It seems
> this has to be done within portfolio backtester.
> 
> I know the following:
> 1- total equity:
> 	CurrentPortfolioEquity = bo.Equity;
> 2- The value of each open position
> 	nInvestedValue = 0;
> 	for(openpos = bo.GetFirstOpenPos(); openpos; openpos = 
> bo.GetNextOpenPos()) { 
> 		nInvestedValue = nInvestedValue + 
> openpos.GetPositionValue();
> 		nOpenPositions++;
> 	}
> 
> Now you there is something similar as shown in the code
> bellow. But, this is at the system level and generic
> for all positions.
> I am not sure we can link this with "bo.Equity".
> 
> Can anyone help by pointing me the way.
> 
> Thanks,
> Rashid
>  
> ==================
> for( i = 0; i < BarCount; i++ ) 
> { 
>    if( priceatbuy == 0 AND Buy[ i ] ) 
>     { 
>        priceatbuy = BuyPrice[ i ]; 
>     } 
> 
>    if( priceatbuy > 0 ) 
>     { 
>        highsincebuy = Max( High[ i ], highsincebuy ); 
> 
>       if( exit == 0 AND 
>           High[ i ] >= ( 1 + FirstProfitTarget * 0.01
> ) * priceatbuy ) 
>        { 
>          // first profit target hit - scale-out 
>          exit = 1; 
>          Buy[ i ] = sigScaleOut; 
>        } 
> 
>       if( exit == 1 AND 
>           High[ i ] >= ( 1 + SecondProfitTarget * 0.01
> ) * priceatbuy ) 
>        { 
>          // second profit target hit - exit 
>          exit = 2; 
>          SellPrice[ i ] = Max( Open[ i ], ( 1 +
> SecondProfitTarget * 0.01 ) * priceatbuy ); 
>        } 
> 
>       if( Low[ i ] <= ( 1 - TrailingStop * 0.01 ) *
> highsincebuy ) 
>        { 
>          // trailing stop hit - exit 
>          exit = 3;    
>          SellPrice[ i ] = Min( Open[ i ], ( 1 -
> TrailingStop * 0.01 ) * highsincebuy ); 
>        } 
> 
>       if( exit >= 2 ) 
>        { 
>          Buy[ i ] = 0; 
>          Sell[ i ] = exit + 1; // mark appropriate
> exit code 
>          exit = 0; 
>          priceatbuy = 0; // reset price 
>          highsincebuy = 0; 
>        } 
>     } 
> } 
> 
> SetPositionSize( 50, spsPercentOfEquity ); 
> SetPositionSize( 50, spsPercentOfPosition * ( Buy ==
> sigScaleOut ) ); // scale out 50% of position
>




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/