Could someone please explain the proper format of using sigscaleout? There are several examples of sigscalein in the manual and other places, but I'm simply trying to do a 50% scale out and my detailed trade log shows selling 100% of the position on the first trigger. When I change the code to do sigscalein it works perfectly. Please help! Just a simple example of showing selling 50% on the first trigger and 50% on the next would be perfect. Please explain as if you would to a 5 year old that eats crayons. Thanks!
Kindest Regards,
tony
SetTradeDelays(0,0,0,0);
BuyPrice = C;
SellPrice = C;
// Each Buy is allocated 25% of available equity.
//PositionSize = -25;
BUYSIGNAL=c>Ref(HHV(c,20),-1);
Buy = buysignal;//IIf(BUYSIGNAL,sigScaleIn,0);
SELLSIGNAL = c<Ref(LLV(c,20),-1);
SetPositionSize( 50, spsPercentOfPosition *( Buy == sigScaleOut ));
Sell = IIf(SELLSIGNAL,SigScaleOut,0);
// Remove the extra Sell signals,
// but NOT the extra Buy signals.
//Sell = ExRem(Sell,Buy);
//Figure 7.7 Scale In
Plot(Ref(HHV(c,20),-1),"HHV20",colorGreen,styleLine);
Plot(Ref(LLV(c,20),-1),"LLV20",colorDarkRed,styleLine);
Plot(C,"Close",colorDefault,styleline);
Here it sold the whole position rather than scale out.
When i copy the code of that example, it does not scaleout 50%.
The buy/sell/scaleout signals are correct, it is only the 50% scaleout that is the issue.
Basically it sells almost full position at scaleout...?
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;
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