I need your help in solving my problem with order handling.
My scenario: If a "take profit" is reached, I want to open a new short position.
As simple as it sounds, but it always opens 2 shorts and I can't find a mistake. In the backtest everything works fine, so I guess it is the maybe the connection between IB and NT via the gateway?
In my picture there are one target, one close and one RON. Why is the "close" there, it should has been closed already?
Here is my code:
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 == "Profit target" && order.OrderState == OrderState.Filled && order.OrderAction == OrderAction.Sell ) {
enteredShort = true;
EnterShort(0, DefaultQuantity, "RON" );
SetStopLoss( "RON", CalculationMode.Percent, SL/100, false );
SetProfitTarget( "RON", CalculationMode.Percent, TP/100);
Print("Entered Short");
}
}
A penny for your thoughts!

Comment