I would have added a second breakeven the first 5 + 1 and the second
7 + 4 only when the market goes over +7 ticks in my favor and then
goes back to +6, the breakeven "dances" between +1 and + 4 This is the
code, am I probably missing something?
thank you very much
Massimiliano
protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade)
return;
// Resets the stop loss to the original value when all positions are closed
if (Position.MarketPosition == MarketPosition.Flat)
{
TriggerState = 0;
SetStopLoss(CalculationMode.Ticks, StopLossTicks);
}
// 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+3 ticks, set stop loss
to breakeven
if (Close[0] > Position.AveragePrice + 3 * TickSize)
{
TriggerState=1;
SetStopLoss(CalculationMode.Price, Position.AveragePrice +1*TickSize);
}
//
// Once the price is greater than entry price+3 ticks, set stop loss
to breakeven
if (Close[0] > Position.AveragePrice + 7 * TickSize)
{
TriggerState= 2;
SetStopLoss(CalculationMode.Price, Close[1] +4*TickSize);
}
Comment