Hello,
Thank you very much for your e-mail.
I would recommend adding few AddColumn statements and use Exploration
to see what is happening in your code to gain better understanding and be able to fix
See:
http://www.amibroker.com/kb/2014/09/29/debugging-techniques-part-1-exploration/
Best regards,
Tomasz Janeczko
amibroker.com
//POSITION Sizing
// 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 = 50; // profit in percent
SecondProfitTarget = 120; // profit in percent
TrailingStop = 15; // also in percent
priceatbuy=0;
highsincebuy = 0;
exit = 0;
for( i = 0; i < BarCount; i++ ) // check every bar for scale out
{
if( priceatbuy == 0 AND Buy[ i ] ) //check if there is a trade.
{
priceatbuy = BuyPrice[ i ]; // assign buy price to price at buy
}
if( priceatbuy > 0 ) // if there is trade opened already.
{
highsincebuy = Max( High[ i ], highsincebuy );
if( exit == 0 AND
High[ i ] >= ( 1 + FirstProfitTarget * 0.01 ) * priceatbuy )
{
// first profit target hit - scale-out
exit = 1; // assign exit to 1 once hit the 1st target.
Buy[ i ] = sigScaleOut; // assign 1st scale out signal to Buy array.
}
if( exit == 1 AND
High[ i ] >= ( 1 + SecondProfitTarget * 0.01 ) * priceatbuy )
{
// second profit target hit - exit
exit = 2; // assign exit to 2 once hit the 2nd target
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 ) // if exit all the position and do sth below( reset every thing wait for new signal)
{
Buy[ i ] = 0;
Sell[ i ] = exit + 1; // mark appropriate exit code
exit = 0;
priceatbuy = 0; // reset price
highsincebuy = 0;
}
}
}
SetPositionSize( 8, spsPercentOfEquity ); // allocation of each position.
SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) ); // scale out 50% of position
}
I USE ABOVE CODE
but I have 2 problem
1. sometimes profit target will not hit ,but there is a scaleout signal ( too early to scaleout)
2. the number of shares that scale out is not 50% as it should be, but as high as 70%-80%
please help me find out the reason why please
Best Regards,
Peter
Posted by: Tomasz Janeczko <groups@amibroker.com>
| Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (2) |
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/
EmoticonEmoticon