NinjaScript > Language Reference > Strategy >

RealtimeErrorHandling

Print this Topic Previous pageReturn to chapter overviewNext page

Definition

Defines the behaviour of a strategy when a strategy generated order is returned from the broker's server in a "Rejected" state. Default behaviour is to stop the strategy, cancel any remaining working orders, and then close any open positions managed by the strategy by submitting one "Close" order for each unique position.

 

Setting this property value to "TakeNoAction" can have *serious* adverse affects on a running strategy unless you have programmed your own order rejection handling in the OnOrderUpdate() method
User defined rejection handling is advanced and should *only* be addressed by experienced programmers

 

Property Value

RealtimeErrorHandling.TakeNoAction

RealtimeErrorHandling.StopStrategyCancelOrdersClosePosition (Default value of a strategy)

 

Syntax

RealtimeErrorHandling

 

 

Examples

protected override void Initialize()
{
   RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction;
}

 
private IOrder stopLossOrder = null;

 

protected override void OnBarUpdate()
{
    if (entryOrder == null && Close[0] > Open[0])
         EnterLong();
 

    if (stopLossOrder == null)
         stopLossOrder = ExitLongStop(Position.AvgPrice - 10 * TickSize);
}

 

protected override void OnOrderUpdate(IOrder order)
{
    if (stopLossOrder != null && stopLossOrder == order)
    {
        // Rejection handling
        if (order.OrderState == OrderState.Rejected)
         {
              // Stop loss order was rejected !!!!
              // Do something about it here
         }
    }
}