Help with basic pyramiding and trade delays.

Hi There,

I am trying to learn about pyramiding and I have been playing with help file code that increases/decreases positions as a percentage threshold is met. This works fine until I add some trade delays, at which point it will scale out all but a single share (according to the detail log.

How do I implement trade delays using pyramiding and correctly scale in/out? The sample code I am using is this:

// percent equity change threshold when pyramiding is performed 
PyramidThreshold = 5; 
SetTradeDelays(1,1,1,1);

// regular trading rules (no pyramiding) 
Buy = Cross( MACD(), Signal() ); 
Sell = Cross( Signal(), MACD() ); 

e = Equity(1); // generate equity without pyramiding effect 

PcntProfit = 100 * ( e - ValueWhen( Buy, e ) )/ValueWhen( Buy, e ); 

InTrade = Flip( Buy, Sell ); 

// ExRem is used here to ensure that scaling-in/out occurs 
// only once since trade entry 
DoScaleIn = ExRem( InTrade AND PcntProfit > PyramidThreshold, Sell ); 
DoScaleOut = ExRem( InTrade AND PcntProfit < -PyramidThreshold, Sell ); 

// modify rules to handle pyramiding 
Buy = Buy + sigScaleIn * DoScaleIn + sigScaleOut * DoScaleOut; 

PositionSize = IIf( DoScaleOut, 500, 1000 ); // enter and scale-in size $1000, scale-out size: $500