Thank you all for your help.EMP,i copied your code and ran it as i still am getting very odd # of shares on the initial scale out,and its certainly not a consistent ratio.I will read what i can,but this is puzzling..
__._,_.___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
| Investment management software | Real estate investment software | Investment property software |
| Software support | Real estate investment analysis software | Investment software |
YAHOO! GROUPS LINKS
- Visit your group "amibroker" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
|
hi,
i tested your code on HANS. I added some code to
display what is going on. I always like to visualize the system and this is easy
to do with Amibroker.
What you see in the image I added is that the
initial Buy signal is already in July. In november it scales out followed by a
sell signal. If I run the backtest I find that scaling out sells half of the
initial amount.
Between the initial buy and the scale out there are
multiple buy signals. However these are ignored by the backtester since the
initial position is eneterd in July. So maybe your problem has something to do
with the range you use in your backtest. Try to backtest all
quotations.
Buy = Cross(C,
MA( C,21) );
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 = 20; // profit SecondProfitTarget =30; // in percent TrailingStop = 50; // 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; Sell[ i ] = exit + 1; // mark appropriate exit code exit = 0; priceatbuy = 0; // reset price highsincebuy = 0; } } } SetPositionSize( 10, spsPercentOfEquity ); SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) ); // scale out 50% of position SetBarsRequired(10000,10000); SetChartOptions(0, chartShowDates); Plot(C,"",colorWhite,64); PlotShapes(IIf(Buy == 1,shapeUpArrow,0),colorWhite, layer = 0, yposition = BuyPrice, offset = 0 ); PlotShapes(IIf(Buy == sigScaleOut,shapeDownTriangle,0),colorAqua, layer = 0, yposition = BuyPrice, offset = 0 ); PlotShapes(IIf(Sell,shapeDownArrow,0),colorYellow, layer = 0, yposition = SellPrice, offset = 0 ); //PlotShapes(IIf(Short,shapeHollowDownArrow,0),colorLightBlue, layer = 0, yposition = ShortPrice, offset = 0 );
|
