I've read and re-read multiple posts regarding a similar problem with scale
outs on short positions(although most were for futures rather than equities).
I can get the scale out to work properly for the long positions, just not for
the shorts. I've tried to change the highsinceshort to a large number, doesn't
work. Tried to add a condition like Buy != 1, does not work. Still getting
trades where the trailing stop does not trigger on the shorts. Does anyone
have any ideas? Seems like this has been a problem for many people, but I
still haven't found a definitive answer as to why. I changed the buy/short
signals to a simple MA condition for this illustration.
Buy = c > MA(C,20);
Short = c < MA(C,20);
PriceAtBuy = 0;
PriceAtShort = 0;
HighSinceBuy = 0;
LowSinceShort = 0;
ExitBuy = 0;
ExitShort = 0;
FirstProfitTarget = Optimize("1st", 5, 1, 6, 1);
SecondProfitTarget = Optimize("2nd", 8, 7, 15, 1);
TrailingStop = Optimize("stop", 5, 5, 12, 1);
for(i=0; i<BarCount; i++)
{
//Long Trades
if(PriceAtBuy==0 AND Buy[i])
{
PriceAtBuy = BuyPrice[i];
}
//Short Trades
if(PriceAtShort==0 AND Short[i])
{
PriceAtShort = ShortPrice[i];
}
if(PriceAtBuy > 0)
{
HighSinceBuy = Max(High[i], HighSinceBuy);
//Check if 1st profit target is hit and Buy not = 1
if(ExitBuy == 0 AND H[i] >=
(1+FirstProfitTarget*.01)*PriceAtBuy)
{
//first profit target hit - scale out
ExitBuy = 1;
Buy[i] = sigScaleOut;
BuyPrice[i] = (1 + FirstProfitTarget * .01) *
PriceAtBuy;
}
//Check if second profit target is hit
if(ExitBuy == 1 AND High[i] >= (1+SecondProfitTarget*.01) *
PriceAtBuy)
{
//second profit target hit - exit
ExitBuy = 2;
SellPrice[i] = Max(Open[i], (1+SecondProfitTarget*.01)
* PriceAtBuy);
}
if(Low[i] <= (1-TrailingStop*.01) * HighSinceBuy)
{
//trailing stop hit - exit
ExitBuy = 3;
SellPrice[i] = Min(Open[i], (1 - TrailingStop*.01) *
HighSinceBuy);
}
if(ExitBuy >= 2)
{
Buy[i] = 0;
Sell[i] = ExitBuy + 1; //mark appropriate exit code
ExitBuy = 0;
PriceAtBuy = 0;
HighSinceBuy = 0;
}
}
if(PriceAtShort > 0)
{
LowSinceShort = 1000000;
LowSinceShort = Min(Low[i], LowSinceShort);
if(ExitShort == 0 AND L[i] <=
(1-FirstProfitTarget*.01)*PriceAtShort)
{
//first profit target hit - scale out
ExitShort = 1;
Short[i] = sigScaleOut;
ShortPrice[i] = (1-FirstProfitTarget*.01)*PriceAtShort;
}
if(ExitShort == 1 AND L[i] <=
(1-SecondProfitTarget*.01)*PriceAtShort)
{
ExitShort = 2;
CoverPrice[i] = Min(Open[i],
(1-SecondProfitTarget*.01)*PriceAtShort);
}
if(High[i] >= (1+TrailingStop*.01)*LowSinceShort)
{
ExitShort = 3;
CoverPrice[i] = Max(Open[i],
(1+TrailingStop*.01)*LowSinceShort);
}
if(ExitShort >= 2)
{
Short[i] = 0;
Cover[i] = ExitShort + 1;
ExitShort = 0;
PriceAtShort = 0;
LowSinceShort = 0;
}
}
}
SetPositionSize( 50, spsPercentOfEquity );
SetPositionSize(50, spsPercentOfPosition * (Buy == sigScaleOut OR Short ==
sigScaleOut));