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

Re: [amibroker] setpositionsize as constant value rather than % of equity



PureBytes Links

Trading Reference Links

Yuki in the help for this there are options for defining the
positionsize. ee the list of AFL functions setpositionsize

spsValue (=1) - dollar value of size (as in previous versions)
spsPercentOfEquity (=2) - size expressed as percent of portfolio-level
equity (size must be from ..100 (for regular accounts) or .1000 for
margin accounts)
spsShares (=4) - size expressed in shares/contracts (size must be > 0 )
spsPercentOfPosition (=3) - size expressed as percent of currently
open position (for SCALING IN and SCALING OUT ONLY)
spsNoChange (=0) - don't change previously set size for given bar



On 10/29/05, Yuki Taga <yukitaga@xxxxxxxxxxxxx> wrote:
> The code below is verbatim from the User's Guide.  Unfortunately for
> me, it is not clear how I write the position size statements at the
> end, because I do not use percent of equity to determine
> positionsize. I use a fixed amount of money per position.
>
> Can someone help me with this?
>
> Yuki
>
> Buy = Cross( MA( C, 10 ), MA( C, 50 ) );
> Sell = 0;
>
> // the system will exit
> // 50% of position if FIRST PROFIT TARGET stop is hit
> // 50% of position is SECOND PROFIT TARGET stop is hit
> // 100% of position if TRAILING STOP is hit
>
> FirstProfitTarget = 10; // profit
> SecondProfitTarget = 20; // in percent
> TrailingStop = 10; // also in percent
>
> priceatbuy=0;
> highsincebuy = 0;
>
> exit = 0;
>
> 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 other support material please check also:
> http://www.amibroker.com/support.html
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>


--
Cheers
Graham
AB-Write >< Professional AFL Writing Service
Yes, I write AFL code to your requirements
http://e-wire.net.au/~eb_kavan/ab_write.htm


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Try Online Currency Trading with GFT. Free 50K Demo. Trade 
24 Hours. Commission-Free. 
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/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 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/

<*> 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/