I'm attempting to do an immediate stop and reverse on a system with code that sets the stop to breakeven. I copied the code from the SamplePriceModification.cs file on another help item and am using that. But what occurs now is that after a winning long trade I close the position, go short immediately and get immediately stopped out (instantly) on the backtesting of the strategy.
I saw the forum "Set stop to breakeven after profit" and your help but it doesnt work neither.
Can you help me please
This is the code.
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Resets the stop loss to the original value when all positions are closed
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, StopLoss);
}
// 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.AvgPrice + 50 * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice);
}
}
// Condition set 1
if (CrossAbove(WMA(CortaEntradaLargo), WMA(LargaEntradaLargo), 1))
{
EnterLong(DefaultQuantity, "Largo");
}
// Condition set 2
if (CrossBelow(WMA(CortaEntradaLargo), WMA(LargaEntradaLargo), 1)
&& ADX(14)[0] > ValorADX)
{
EnterShort(DefaultQuantity, "Corto");

Comment