Could someone take a look at this pls?
I'm trying to code exiting once price is above buyprice by 3*ATR(20)
at the time of purchase. The basic code is based on the user guide
but I've gone wrong somewhere.
Thanks in advance.
BuyATR=ValueWhen(Buy,ATR(20)); // profit
ProfitTarget = 3*BuyATR;
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 ] >= ProfitTarget * priceatbuy)
{
// first profit target hit - scale-out
exit = 1;
Buy[ i ] = sigScaleOut;
}
}
}
SetPositionSize( 50, spsPercentOfPosition * ( Buy ==
sigScaleOut ) ); // scale out 50% of position