I have another issue with the strategy
When the strategy take a trade, these two messages show me at the same time. I dont understand why. This never happen in Backtesting, Trade Performance or even at Playback (thats wear)
I was thinking something like this in Long Trades
if (stopLoss < Close[0]) stopOrder = ExitLongStopMarket(0, true, entryOrder.Quantity, stopLoss, "StopLoss", "LongEntry"); if (takeProfit > Close[0]) takeOrder = ExitLongLimit(0, true, 1, takeProfit, "TakeProfit", "LongEntry");
Note: When I take the SAME trade at Playback, it takes how it suppose to be taking, but in "Real" I got thats errors
Thanks for your help
This is the code, I will show you the code in a simple way
Variables
private double stopLoss; private double entryPrice; private double takeProfitPrice; private Order stopOrder = null; private Order entryOrder = null; private Order takeOrder = null;
if (Position.MarketPosition == MarketPosition.Flat)
{
stopLoss = indicator.TriggerUp - (Value / tickValue) * TickSize;
}
if (Position.MarketPosition == MarketPosition.Flat && BullishTrigger)
{
entryOrder = EnterLong(Convert.ToInt32(1), "LongEntry");
}
if (Position.MarketPosition == MarketPosition.Long)
{
stopOrder = ExitLongStopMarket(0, true, entryOrder.Quantity, stopLoss, "StopLoss", "LongEntry");
takeOrder = ExitLongLimit(0, true, 1, takeProfitPrice, "TakeProfit", "LongEntry");
}
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
{
if (order.Name.Contains("Entry"))
{
entryOrder = order;
if (order.OrderState == OrderState.Cancelled)
{
entryOrder = null;
}
}
if (order.Name == "StopLoss")
{
stopOrder = order;
if (order.OrderState == OrderState.Cancelled)
{
stopOrder = null;
}
}
if (order.Name == "TakeProfit")
{
takeOrder = order;
if (order.OrderState == OrderState.Cancelled)
{
takeOrder = null;
}
if (order.OrderState == OrderState.Filled)
{
targetFilled = true;
}
}
}

Comment