The system starts with buying 1 contract and then keeps on adding one contract per x dollars of profit, while it squares off 1 contract per y dollars of loss..
Found this afl.But need help to modify according to my needs.
// percent equity change threshold when pyramiding is performed
PyramidThreshold = 5;
// 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
Source : http://www.amibroker.com/guide/h_pyramid.html
Found this afl.But need help to modify according to my needs.
// percent equity change threshold when pyramiding is performed
PyramidThreshold = 5;
// 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
Source : http://www.amibroker.com/guide/h_pyramid.html