4.6.1 Orders

Order objects can be created and generated only by signals. All orders inherit from the basic interface.

public interface IOrderObject
	{
		int ID { get; } //unique order number
		Order Info { get; }//Basic order information (direction, type, category etc.)
	}

There are three types of orders:

1) Market orders executed at current market price.

	public interface IOrderMarket : IOrderObject
	{
		void Send(); 
		void Send(int numLots);
	}

2) Price orders executed when market price touches or crosses order price level.

 
        public interface IOrderPriced : IOrderObject
	{
		void Send(double price);
		void Send(double price, int numLots);
	}

3) Algorithmic Stop-Limit orders executed as price Limit orders, but only after market price touches or crosses the stop price.

        public interface IOrderStopLimit : IOrderObject
	{
		void Send(double stopPrice, double limitPrice);
		void Send(double stopPrice, double limitPrice, int numLots);
	}

Order objects are created only in Create() method using OrderCreator:

1) IOrderMarket OrderCreator.MarketNextBar(SOrderParameters orderParams); - creates a Market order that should be sent at the Open of the next bar, the one after the bar where the order was generated.
2) IOrderMarket OrderCreator.MarketThisBar(SOrderParameters orderParams); - creates a Market order that should be sent on the Close of the bar where it was generated.
3) IOrderPriced OrderCreator.Limit(SOrderParameters orderParams); - creates a price Limit order that should be sent at the Open of the next bar, the one after the bar where the order was generated. A Limit order can be filled at the price set, or better, in Send() method when generating the order where buy equals order price and lower and sell equals order price and higher.
4) IOrderPriced OrderCreator.Stop(SOrderParameters orderParams); - creates a price Stop order that should be sent at the Open of the next bar, the one after the bar where the order was generated. Stop order can be filled at the price set, or worse, in Send () when generating the order buy equals order price and lower and sell equals order price and higher.
5) IOrderStopLimit OrderCreator.StopLimit(SOrderParameters orderParams); - creates algorithmic Limit order with a Stop condition that should be sent at the Open of the next bar, the one after the bar where the order was generated.

The following structure is used to create an order object in all the OrderCreator() methods:

SOrderParameters:
SOrderParameters(EOrderAction action);
SOrderParameters(Contracts lots, EOrderAction action);
SOrderParameters(EOrderAction action, string name);
SOrderParameters(Contracts lots, EOrderAction action, OrderExit exitInfo);
SOrderParameters(Contracts lots, string name, EOrderAction action);
SOrderParameters(Contracts lots, string name, EOrderAction action, OrderExit exitInfo);

Settings:

  • EOrderAction:

Buy – long position entry (buying). If the short position is currently opened, then it will be closed and the long one will be opened.

Sell – long position exit (selling). This order cannot be sent, if the long position is not opened. Also, this position cannot be reversed into short.

SellShort – short position entry (selling). If the long position is currently opened, then it will be closed, and the short one will be opened.

BuyToCover – short position exit (buying). This order cannot be sent, if the short position is not opened.

  • Contracts:

Default – the quantity of contracts is calculated, according to the strategy settings in Strategy Properties window.

CreateUserSpecified(int num) – the default quantity of contracts for the order is set in the method settings.

name – Custom name of the order.

  • OrderExit:

FromAll – closes all entries, which opened the position. If the quantity of contracts is specified, then close each entry partially on the quantity of contracts specified.

Total – closes the position on ONLY the specified quantity of contracts. The entries will be closed accordingly, starting from the first one, up to the last one, until the exit is executed upon the quantity of contracts specified.

FromEntry(IOrderObject entry) – closes the particular entry, in the entry setting, created earlier, in the same signal.