Click or drag to resize

Unmanaged Order Methods

Unmanaged method is meant for users with advanced coding concept only. User with rudimentary coding concept or new user of ArthaChitra should prefer the Managed method.

If user wants to manage the orders by himself/herself, then he/she can do so by setting the IsUserManaged property to true when the strategy state is in Initialize state. The below code further demonstrates it

Example
C#
protected override void OnStateChange()
{
    switch (base.State)
    {
        case State.Initialize:
            base.IsUserManaged = true;
            break;

        //other codes
    }
}

Unmanaged Orders are meant for users with advanced coding concepts only as any rogue code (as written by user) may result in overfills, submission of multiple orders etc as the internal order handling rules are not followed here. For example the below code will submit a market order whenever the condition is fulfilled resulting in redundant orders/trades. A Managed Order on the other hand will ignore any redundant calls.

Example
C#
protected override void OnBarUpdate()
{
    if (Close[0] > 100.0d)
    {
        SubmitOrder("buy", OrderAction.Buy, OrderType.Market, 0.0d, 0.0d);
    }
}

To overcome the above scenario user can set a bool check to submit only once. The below code further demonstrates it.

Example
C#
bool isOrderSubmitted = false;

protected override void OnBarUpdate()
{
    if (this.State != State.Realtime) //Make sure to evaluate the orders when the state is in realtime only
        return;

        if (!isOrderSubmitted && Close[0] > 100.0d)
        {
            isOrderSubmitted = true; //making sure the order is not submitted twice
            SubmitOrder("buy", OrderAction.Buy, OrderType.Market, 0.0d, 0.0d);
        }
}
Order methods

The Unmanaged Methods have 3 (three) methods namely SubmitOrder, ChangeOrder(IOrder, Int32, Double, Double) and CancelOrder(IOrder). As the name suggest the SubmitOrder method is used to place an order, the ChangeOrder method is used to change an order and CancelOrder is used to cancel a specified order. We further discusses the various parameters of the mentioned methods.

SubmitOrder - Submits a new order based on the input parameters

Bars indexBars index for which the order is meant for.
NameName of the order
Order ActionOrderAction of the order
Order TypeOrderType of the order
QuantityQuantity of the order
Limit priceLimit price of the order. In case of a market order or stop market order set the value to 0.0d (zero)
Stop priceStop price in case of stop orders. For market and limit orders set the value to 0.0d (zero)
OCO stringOne cancels other string. If connection supports OCO simulation then OCO is set at sever side else it is simulated locally.

ChangeOrder(IOrder, Int32, Double, Double) - Modify an existing order

Order The order which is to be changed.
QuantityThe new order quantity. If you do not want to change the quantity then just specify the order quantity
Limit priceThe new limit price for limit and stop limit orders. For market, stop market orders set the value to 0.0d (zero)
Stop priceThe new stop price for stop orders. For limit and market orders set it to 0.0d (zero)

CancelOrder(IOrder) - Cancel an existing order

Order The order which is to be cancelled.

Note : In unmanaged method the Entry() methods like EnterLong, EnterShortLimit etc and the exit methods like SetStop, ClosePosition etc methods will be ignored