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

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



PureBytes Links

Trading Reference Links

Hello Graham,

thanks a lot !
My headache is over now. :-)
Seems that i have tried it to complicated.

Kind regards
Thomas


--- In amibroker@xxxxxxxxxxxxxxx, Graham <kavemanperth@xxx> wrote:
>
> 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@xxx> 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.PosSizeand 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
 
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/