In the stoploss area of my strategy i have used a SetStopLoss template example with allow modification to breakeven. Plus i have made some of my own adjustments to suit.
I.e. Once the price is greater than +30 ticks, set stop loss to breakeven + 5 ticks. This is fine, it works OK.
HOWEVER,,, i would like some advice on the code logic needed to do a second modification on the stoploss.
I.e. Once the price is greater than +60ticks, set stop loss to breakeven + 20 ticks.
Here is my code, displaying, If going long:
// Resets the stop loss to the original value when all positions are closed
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss("", CalculationMode.Percent, 0.002, false);
}
// If a long position is open, allow for stop loss modification to breakeven
elseif (Position.MarketPosition == MarketPosition.Long)
{
// Once the price is greater than entry price+30 ticks, set stop loss to breakeven + 5 ticks
if (Close[0] > Position.AvgPrice + 30 * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice + 5 * TickSize);
}
}
(this section below does not work in addition with the above stoploss statemets....?)
// If a long position is open, allow for stop loss modification to breakeven
elseif (Position.MarketPosition == MarketPosition.Long)
{
// Once the price is greater than entry price+60 ticks, set stop loss to breakeven + 20 ticks
if (Close[0] > Position.AvgPrice + 60 * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice + 20 * TickSize);
}
}
FYI. i am feeling my way through this code language for the first time ever this week, so please excuse if i dont use correct code terminology!
Steven
Comment