NinjaScript > Language Reference > Strategy >

OnExecution()

Print this Topic Previous pageReturn to chapter overviewNext page

Definition
The OnExecution() method is called on an incoming execution. An execution is another name for a fill of an order.

 

Programming to this method is considered advanced programming and exposed for experienced programmers
An order can generate multiple executions (partial fills)
OnExecution is always called after OnOrderUpdate() is called

 

If you are relying on the OnExecution() method to trigger actions such as the submission of a stop loss order when your entry order is filled ALWAYS reference the properties on the IOrder object property attached to the IExecution object passed into the OnExecution() method.

 

Method Return Value

This method does not return a value.

 

Method Parameters

IExecution execution

 

Syntax
You must override the method in your strategy with the following syntax.

 

protected override void OnExecution(IExecution execution)
{
 
}

 

 

Examples

// Example #1

// Finding the executions of a particular IOrder object

private IOrder entryOrder = null;

 

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

 

protected override void OnExecution(IExecution execution)
{
    if (entryOrder != null && entryOrder == execution.Order)
         Print(execution.ToString());
}

 

 

// Example #2

// Generic execution logic not specific to a particular IOrder object

protected override void OnExecution(IExecution execution)
{

    // Remember to check the underlying IOrder object for null before trying to access its properties
    if (execution.Order != null && execution.Order.OrderState == OrderState.Filled)
         Print(execution.ToString());
}

 
Additional Reference Samples
Additional reference code samples are available the NinjaScript Educational Resources section of our support forum.