I've been working with the sample price modification (break-even) strategy. I'm trying to add a second stop price mod step/stage as price advances, but if/when price regresses below the second step's price threshold, the stop, instead of staying at the second price, goes back to the original break even price. Can anyone show me how to add a second step to the sample price mod. strategy, where the strategy ignores the break-even statement after we've achieved the second stage? Am I making sense?
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Resets the stop loss to the original value when all positions are closed
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, 120);
}
// 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+50 ticks, set stop loss to breakeven
if (Close[0] > Position.AveragePrice + 120 * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AveragePrice);
}
//Here's the second stage I'm trying to add
//if (Close[0] > Position.AveragePrice + 240 * TickSize)
//{
// SetStopLoss(CalculationMode.Price, Position.AveragePrice + 120 * TickSize);
//}
}
// Set 1
if (
(Slope(SMA(21), 10, 0) > 0)
&& (Times[0][0].TimeOfDay > new TimeSpan(9, 30, 0))
&& (Times[0][0].TimeOfDay < new TimeSpan(12, 30, 0))
)
{
EnterLong(Convert.ToInt32(DefaultQuantity), "");
}
}
}
}
thanks,
David
Comment