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

Re: [amibroker] Erroneous Position Size and Entry Price



PureBytes Links

Trading Reference Links

Hello,

How I love newcomers who's first thing to do is to jump here and claim errors on AB side
and never on their own. 

======================================
Before claiming errors in AB debug your own code.
======================================

Unfortunatelly the formula you have sent is INCOMPLETE, therefore
it can not be run and tested and your coding error pointed out to you exactly.

One possible reason for double the size is that your buy rule
Buy = IIf(Buy, sigScaleIn, 0);  // allow pyramidding 

is actually PYRAMINDING (ADDING) to the trade.
So you enter once with  $10000 and then enter again $10000
hence the position size is DOUBLE (entered twice on the same symbol)

Your formula lacks the sell rule so it will accumulate more and more
until cash is out.

If you don't use sigScaleIn in your buy formula it won't double the size.

Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message ----- 
From: "Graham Johnson" <grahamj@xxxxxxxxxxxxxxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Wednesday, January 02, 2008 3:53 AM
Subject: [amibroker] Erroneous Position Size and Entry Price


> As part of the migration process from Wealth-Lab, I've been running 
> some parallel backtesting.
> 
> Symbol currently used is JBH(ASX) for period 01/07/2007 to 31/12/2007.
> 
> Both AB & WLD open long trades on 26/07/2007, 13/11/2007 & 
> 19/12/2007, and the exit dates match.
> 
> The 2nd & 3rd trades have matching Entry & Exit Prices and the 
> position sizes are within tolerance.
> 
> Trade for 26/07/2007 is the problem, the AB report shows entry price 
> $11.1357 and Position Size of $19988.60, whereas it should have been 
> $11.36 and $10000.00.
> 
> I've been using _TRACE to follow the calculations and the logic 
> appears to be correct so, ther must be something that I haven't got 
> quite right.  Any ideas, please?
> 
> The relevant code is
> //==================  Position Size  ==================
> vMaxPosn = 10000;
> vMaxRisk = 2000;
> vMaxTOPc = 3;
> vaPosnSize = vMaxRisk / Ref(vaIStopVal, -1) * Ref(vaLimitEntry, -1);
> vaPosnSize = Min(vaPosnSize, vMaxPosn);
> vaPosnSize = Min(vaPosnSize, Ref(vaAvgTO, -1) * vMaxTOPc / 100);
> SetPositionSize(vaPosnSize, spsValue);
> //_TRACE("Position Size: " + vaPosnSize);
> 
> //==================  Trade  ==================
> Buy = Ref(vaValidEntry,-1) AND Low <= Ref(vaLimitEntry, -1);
> Buy = IIf(Buy, sigScaleIn, 0);  // allow pyramidding, recorded as one 
> position
> BuyPrice = Min(Open, Ref(vaLimitEntry, -1));
> //_TRACE("Open: " + Open + " | Limit Entry: " + Ref(vaLimitEntry, -1) 
> + " | Buy Price: " + BuyPrice + " | T/O: " + Ref(vaAvgTO, -1) + " | 
> PosnSize: " + VaPosnSize);
> 
> 
> 
> 
> 
> 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
> 
> 
> 
> 
>


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/