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

[amibroker] Define trade size



PureBytes Links

Trading Reference Links

I am trying to write a code extensively without using the built-in AB features such as trailing stops  and position sizes. So far I was able to put in the entries and exits but am having some trouble with the trade size which uses the current equity curve. This is the current code (ignore the strategy itself, as it is just random):

priceatbuy = 0;
for(i=0; i<20; i++)
{
    Buy[i] = 0;
    Sell[i] = 0;
}
for(i=20; i<BarCount; i++)
{
    if( priceatbuy == 0 & BuyPrice[i] > entryLevel[i] )   
    {
        Buy[i] = 1;
        BuyPrice[i] = Max(entryLevel[i], Low[i]);
        priceatbuy = BuyPrice[i];
    }
    else
        Buy[i] = 0;

    if( priceatbuy > 0 & SellPrice[i] < exitLevel[i] )
    {
        Sell[i] = 1;
        SellPrice[i] = Min(exitLevel[i], High[i]);
        priceatbuy = 0;
    }
    else
        Sell[i] = 0;
}


Now I want to buy shares equal to 50% of current equity (updated daily, not initial equity). I tried adding the following line into the FOR statement but that didn't work:
        SetPositionSize( equity()*0.5/priceatbuy, spsShares );

Any suggestions?  I know that
SetPositionSize(-50, spsPercentofEquity ) would do the job, but I would like to be able to tweak the number of shares manually. Thanks!


__._,_.___


**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/





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

__,_._,___