I'm trying to setup several targets for my strategy and I have some problems.... Stop loss and auto break even is working fine, but not the partial exits on different targets.
Can you help me to solve that please ?
Here's my code :
Variables :
// Default setting for StopLoss
private int stopL = 12;
// Default setting for Target 1
private int target1 = 10;
// Default setting for Target 2
private int target2 = 24;
// Default setting for position Size
private int nbcontracts = 2;
// Default setting for buffer entry
private int bufferentry = 2;
// Default setting for break even +1 level
private int breakeven = 6;
// Resets the stop loss to the original value when all positions are closed
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, stopL);
}
/////////// Break even part /////////
// If a long position is open, allow for stop loss modification to breakeven
else if (Position.MarketPosition == MarketPosition.Long)
{
// Once the price is greater than entry price +x ticks, set stop loss to breakeven +1
if (High[0] >= Position.AvgPrice + breakeven * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice +1 * TickSize);
}
}
// If a short position is open, allow for stop loss modification to breakeven
else if (Position.MarketPosition == MarketPosition.Short)
{
// Once the price is greater than entry price -x ticks, set stop loss to breakeven +1
if (Low[0] <= Position.AvgPrice - breakeven * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice -1 * TickSize);
}
}
/////////// End Break even part /////////
And then, entry condition and exits :
i
f ( My conditions here )
{
EnterShortStop(nbcontracts, Low[0] - bufferentry * TickSize, "WIISignalShort1");
ExitShortStop(1, target1, "Exit1WIISignalShort1", "WIISignalShort1");
ExitShortStop(1, target2, "Exit2WIISignalShort1", "WIISignalShort1");
}
I probably have a problem of syntax, but I cannot find it.... I'm stuck...
All the best !

Comment