PureBytes Links
Trading Reference Links
|
It might be in the way your code is for the scale-outs. I did a test
myself and it sold 50% of the current holding at each scale out. I
also tried with 25% SetPositionSize( 25, spsPercentOfPosition * ( Buy
== sigScaleOut ) ); and it sold 25% of the curent holding at each
scaleout signal
I just used the example code and changed the Sell to a buy=scaleout to
test how it worked
/*
Example 4: partial exit (scaling out) on profit target stops
Example of code that exits 50% on first profit target, 50% on next
profit target and everything at trailing stop:
*/
Buy = Cross( MA( C, 10 ), MA( C, 50 ) );
Sell = 0;
// the system will exit
// 50% of position if FIRST PROFIT TARGET stop is hit
// 50% of position is SECOND PROFIT TARGET stop is hit
// 100% of position if TRAILING STOP is hit
FirstProfitTarget = 10; // profit
SecondProfitTarget = 20; // in percent
TrailingStop = 10; // also in percent
priceatbuy=0;
highsincebuy = 0;
exit = 0;
for( i = 0; i < BarCount; i++ )
{
if( priceatbuy == 0 AND Buy[ i ] )
{
priceatbuy = BuyPrice[ i ];
}
if( priceatbuy > 0 )
{
highsincebuy = Max( High[ i ], highsincebuy );
if( exit == 0 AND
High[ i ] >= ( 1 + FirstProfitTarget * 0.01 ) * priceatbuy )
{
// first profit target hit - scale-out
exit = 1;
Buy[ i ] = sigScaleOut;
}
if( exit == 1 AND
High[ i ] >= ( 1 + SecondProfitTarget * 0.01 ) * priceatbuy )
{
// second profit target hit - exit
exit = 2;
SellPrice[ i ] = Max( Open[ i ], ( 1 + SecondProfitTarget *
0.01 ) * priceatbuy );
}
if( Low[ i ] <= ( 1 - TrailingStop * 0.01 ) * highsincebuy )
{
// trailing stop hit - exit
exit = 3;
SellPrice[ i ] = Min( Open[ i ], ( 1 - TrailingStop * 0.01 )
* highsincebuy );
}
if( exit >= 2 )
{
// Buy[ i ] = 0;
Buy[ i ] = sigScaleOut;
// Sell[ i ] = exit + 1; // mark appropriate exit code
exit = 0;
priceatbuy = 0; // reset price
highsincebuy = 0;
}
}
}
SetPositionSize( 50, spsPercentOfEquity );
SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) );
// scale out 50% of position
--
Cheers
Graham
AB-Write >< Professional AFL Writing Service
Yes, I write AFL code to your requirements
http://e-wire.net.au/~eb_kavan/ab_write.htm
On 12/19/05, dweilmuenster95125 <dweilmuenster95125@xxxxxxxxx> wrote:
> My Backtest is Long Only, based on Weekly Charts.
>
> The only two statements in my AFL code regarding Position Size are:
>
> SetPositionSize (100/3,spsPercentOfEquity);
> SetPositionSize(50, IIf( Buy == sigScaleOut, spsPercentOfPosition,
> spsNoChange ) );
>
> Execution of the scaling out gives unpredictable results. An example
> below shows that the first scaleout was OK (110 out of 220 open
> shares of IBM scaled out on 11/5/2004). However, the next scale out
> on 11/12/2004 (the next weekly bar) scales out 210 shares, when
> there are only 110 shares in the position, leaving the account short
> by 100 shares.
>
> Any thoughts as to what may be going wrong?
>
> I have lots of other examples where the scale out size is not 50% of
> the current position. Am happy to share more of the code, but
> thought this might be enough to generate some ideas.
>
>
> Thanks,
> David
> ------------------------------------------------
>
>
>
>
>
> Date Information
> …
> 8/20/2004
> Entry signals(score):
> Exit signals:
> 0 Open Positions: , Equity: 57406.1, Cash: 57406.1
> 8/27/2004
> Entry signals(score):IBM=Buy(14.4218),
> Exit signals:
> Enter Long, IBM, Price: 85.23, Shares: 220, Commission: 2.2,
> Rank: 14.4218, Equity 57401.7, Margin Loan: 0, Fx rate: 1
> 1 Open Positions: , IBM (+220), Equity: 57359.8, Cash: 38675.2
> 9/3/2004
> Entry signals(score):
> Exit signals:
> 1 Open Positions: , IBM (+220), Equity: 57260.8, Cash: 38697.2
> …
> 10/29/2004
> Entry signals(score):
> Exit signals:
> 1 Open Positions: , IBM (+220), Equity: 58615.8, Cash: 38873
> 11/5/2004
> Entry signals(score):
> Exit signals:IBM=Scale-Out,
> Scale-Out Long IBM, Price 89.33, Shares 110, Fx Rate 1, Total
> Shares Hold 110, Exited 110, Avg. Price Entry 85.23, Exit 89.33, Avg
> Fx. Rate Entry 1, Exit 1
> 1 Open Positions: , IBM (+110), Equity: 58985.6, Cash: 48725.9
> 11/12/2004
> Entry signals(score):
> Exit signals:IBM=Scale-Out,
> Scale-Out Long IBM, Price 92.5, Shares 210, Fx Rate 1, Total
> Shares Hold -100, Exited 320, Avg. Price Entry 85.23, Exit 91.4103,
> Avg Fx. Rate Entry 1, Exit 1
> 1 Open Positions: , IBM (-100), Equity: 58656.4, Cash: 68187.4
> …
>
>
>
>
>
>
>
>
> 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 other support material please check also:
> http://www.amibroker.com/support.html
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
------------------------ Yahoo! Groups Sponsor --------------------~-->
Try Online Currency Trading with GFT. Free 50K Demo. Trade
24 Hours. Commission-Free.
http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/GHeqlB/TM
--------------------------------------------------------------------~->
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 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/
<*> 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/
|