I have a problem in my strategy live execution. It uses a simple EnterLong/Short order in OnBarUpdate and puts a stop loss and profit target in OnExecution when entry is executed.
When position is flat I reset the stop and target. After entry and stop/target of one or two traders, when a new entry is executed the stop and target are rejected with prices I have not set.
Please advise.
W.
Some code :
OnBarUpdate
if ( Position.MarketPosition == MarketPosition.Flat )
{
// reset stoploss and profittarget.
SetStopLoss(CalculationMode.Ticks, 2*BarsPeriod.Value + 2);
SetProfitTarget(CalculationMode.Ticks, 2*BarsPeriod.Value + 2);
if ( entry condition.... )
{
entryLongOrder = EnterLong(OrderQuantity, "LONG");
}
else if ( ... )
{
entryShortOrder = EnterShort(OrderQuantity, "SHORT");
}
}
if ( execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled ||
(execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0) )
{
double stopPrice = 0;
double targetPrice = 0;
if ( Position.MarketPosition == MarketPosition.Long )
{
targetPrice = execution.Order.AvgFillPrice + (2 * BarsPeriod.Value - 2) * TickSize;
stopPrice = execution.Order.AvgFillPrice - (2 * BarsPeriod.Value + 2) * TickSize;
SetStopLoss("LONG", CalculationMode.Price, stopPrice, false);
SetProfitTarget("LONG", CalculationMode.Price, targetPrice);
ECILogger("Stop at " + stopPrice + " and Target at " + targetPrice + " submitted");
}

Comment