I need a solution able to handle both Rejection caused by a "managed approach" code or/and an ATM operation controlled by a strategy.
Should the OnOrderUpdate handle both managed approach or Atm operation behavior?
As start this is the basic code I have.
The first questions are:
(After commenting out the Test_Line which cannot be always effective)
why OnOrderUpdate doesn't report the rejection?
The code below is essentially a simple breakeven testing for stop below the close by some margin and the OnOrderUpdate code from https://ninjatrader.com/es/support/h...orhandling.htm
The core code I am using is:
protected override void OnStateChange()
{
if (State == State.SetDefaults) RealtimeErrorHandling = RealtimeErrorHandling.IgnoreAllErrors;
}
#region BreakEven for Long Positions
this.stopMargin = 3; // 3 ticks margin to prevent stop below price
if (High[0] > strat.Position.AveragePrice + be1trigger * tickSize)
{
double stopPricex = Position.AveragePrice + be1plus * tickSize;
//Test_Line
if (stopPricex > GetCurrentBid()]- this.stopMargin * tickSize) stopPricex = GetCurrentBid() - this.stopMargin * tickSize;
SetStopLoss(labelLong, CalculationMode.Price, stopPricex, false);
}
#endregion BreakEven
#region Rejection Handling
// Code copied from https://ninjatrader.com/es/support/helpGuides/nt8/?realtimeerrorhandling.htm
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice,
OrderState orderState, DateTime time, ErrorCode error, string nativeError)
{
// Assign stopLossOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
// This is more reliable than assigning Order objects in OnBarUpdate,
// as the assignment is not guaranteed to be complete if it is referenced immediately after submitting
if (/*order.Name == "1S" && */ orderState == OrderState.Filled)
{
Print(Time[0] + "> " + order.Name + " " + order.OrderState + " " + order.OrderType + " " + order.AverageFillPrice);
this.exec1.stopLossOrder = order;
}
if (this.exec1.stopLossOrder != null && this.exec1.stopLossOrder == order)
{
// Rejection handling
if (order.OrderState == OrderState.Rejected)
{
Print(Time[0] + " " + order.Name + " " + order.OrderState + " " + order.OrderType + " " + order.AverageFillPrice);
// Stop loss order was rejected !!!!
// Do something about it here
}
}
}
#endregion Rejection Handling
What am I missing?

Comment