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

[amibroker] problem with SetPositionSize and MM through CBT


  • Date: Mon, 22 Feb 2010 21:02:48 -0000
  • From: "tf28373" <tomfid@xxxxx>
  • Subject: [amibroker] problem with SetPositionSize and MM through CBT

PureBytes Links

Trading Reference Links



Hello everyone.

I am trying to apply following rule of estimating position size:
(f*q*E)/(m*ATR),
where f - fraction of current equity, q - currency pair quotation, E - current equity, m - multiplier of volatility measure (ATR).

Assuming that SetPositionSize(...,spsPercentOfEquity) would be adequate, I prepered following formula (here only parts):

//Backtest for AUDJPY//

a=45000/2.6729;//initial Equity = 16865,65 //

spread=0.025;

SetOption("InitialEquity",a);

SetOption("PriceBoundChecking",False);

SetOption("CommissionMode",2);

SetOption("CommissionAmount",0);

SetOption("AccountMargin",1);

/*RoundLotSize=0.01*/

TickSize=0.001;

PointValue=1;

//here comes trading rules...//

//among them there is a line with a following variable:

start[i]=BuyPrice[i];//start is a trade open price//

StaticVarSet("kurs_"+Name(),kurs);

//finally there is a MM part of the code:

f=Optimize("capital",1,0,100,0.25);

SetPositionSize((f*start)/(e*ATR(20)),2);

Unfortunately backtest results (positions' sizes) are weird. For example in last trade variables are as follows:

f=1, start=61.525, e=2.25 (for profitable system it should be much higher, however, such a value helps to show the embarassing differences) , ATR(20)=0,1255 and Equity(=Cash)=3493,15.

For such values position for the last transaction should be equal to 2741,08.  However, backtester set it to 7169,57.

I decided to use CBT to achieve some stability as far as Equity() is concerned. This is my code:

SetCustomBacktestProc("");

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

{

bo=GetBacktesterObject();

bo.PreProcess();

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

{

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

{

kurs2=StaticVarGet("kurs_"+sig.Symbol);

kurs3=kurs2[i];

 pozycja=(f/100*kurs3*bo.Equity)/(e*ATR(20));

sig.PosSize=pozycja;

}

bo.ProcessTradeSignals(i);

}

bo.PostProcess();

}

Again bad results...

What is especially confusing when bo.Equity is higher than initial equity (that is when system is profitable) everything is good. I really don't know where the problem is.

Do you have any ideas? Please help.

Tomasz



__._,_.___


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

__,_._,___