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

Re: [amibroker] Position sizing based on current equity possible ???



PureBytes Links

Trading Reference Links

I thought you could just so it as this in the main afl code

RiskPerContract = 2*ATR(50) x PointValue x TickSize;  ( eg 2*ATR(50) x 100000 x 0.0001 )

PositionSize = -0.75 x MarginDeposit / RiskPerContract;


--
Cheers
Graham
AB-Write >< Professional AFL Writing Service
Yes, I write AFL code to your requirements
http://www.aflwriting.com


On 24/04/07, Thomas <tzg@xxxxxxxxxxxxxxxxxxx> wrote:

Hello,

 

I am trying to write a system that risks always 0.75% of CURRENT EQUITY per trade and uses ATR stops, which means that I need the custom backtester to access actual equity. The problem is that I can't access the ATR value in the signal object, where I could define the position size.

 

Here is the description that shows how it should work when it is finished:

 

1.)     RiskPerContract = 2*ATR(50) x PointValue x (1/TickSize);

2.)     Contracts = (CurrentEquity x 0.75%) / RiskPerContract;

3.)     PositionSize = Contracts x MarginDeposit;

 

I have already tried a lot and can't find any solution. Please help if possible. See my code below. For simplicity i have just tried to access the ATR value. It seems that AmiBroker simply ignores the value of sig.PosSize and instead uses full equity for the trade.

Thanks in advance !

 

Kind regards,

Thomas

 

SetCustomBacktestProc("" );

 

if( Status ("action") == actionPortfolio )

{

   bo = GetBacktesterObject ();

   bo.PreProcess();

  

   for( bar = 0; bar < BarCount; bar++)

   {

       CurrentPortfolioEquity = bo.Equity;

 

       for( sig = bo.GetFirstSignal(bar); sig; sig = bo.GetNextSignal(bar))

       {

       sym = sig.Symbol;

       SetForeign(sym);

       MyATR = Ref (2* ATR(50),- 1);

       RestorePriceArrays ();

 

       if( CurrentPortfolioEquity > 0 ) sig.PosSize = MyATR[bar];

       else sig.PosSize = 0;

       }

       bo.ProcessTradeSignals(bar);

   }

   bo.PostProcess();

}

/***********************************************************************/

// sample rules:

Buy = Cross ( CCI(), 100 );

Sell = Cross ( 100, CCI () );

Short = Cross ( -100, CCI () );

Cover = Cross ( CCI(), -100 );

/***********************************************************************/

SetOption("InitialEquity" ,100000);

SetOption("FuturesMode" ,True);

PointValue = PointValue * ( 1/TickSize);

RoundLotSize = 1 ;

MarginDeposit = 1000 ;

/***********************************************************************/

_SECTION_BEGIN("Price" );

SetChartOptions(0 ,chartShowArrows|chartShowDates);

_N(Title = StrFormat ("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}" , O, H, L, C, SelectedValue ( ROC( C, 1 ) ) ));

Plot( C, "Close" , ParamColor( "Color", colorBlack ), styleNoTitle | ParamStyle ("Style") | GetPriceStyle () );

_SECTION_END();

/***********************************************************************/




__._,_.___

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

__,_._,___