CreateEntryOrder Function

The CreateOrder() Function allows you to place an entry order. It has 9 parameters:

1.Instrument: TInstrument – the instrument.
2.Account: TAccount – the account.
3.Amount: Double — the number of lots.
4.BuySell: TBuySell — buy or sell.
5.Rate: Double — the entry rate.
6.StopRate: Double – the predefined stop order rate (enter 'NullRate' if you do not want to place a stop order).
7.LimitRate: Double – the predefined limit order rate (enter 'NullRate' if you do not want to place a limit order).
8.OrderType: TOrderType — the order type. Values: otEStop, otELimit.
9.OperationTag: String — the custom order tag.

Custom order tags are used to make it easier to identify and access the individual orders and consequent positions. Note that tags should have unique names. You may want to use a counter for tagging the orders and positions.

Example: Let us create a strategy that will place 2 entry orders: one to buy at the rate 30 points higher than the current rate, and the other one to sell at the rate 50 points higher than the current rate. The strategy should place orders when the Close rate of the last (current) candle is higher than the Close rate of the previous candle.

 

We will use the procedure OnNewCandle as it runs every time a new candle appears in the chart. Remember, that you must set this function in the procedure OnCreate().

 

The script will be as follows:

 

const

StrategyName='My Strategy';

 

var

History: TCandleHistory;

Account: TAccount;

Amount, Point: Double;

ESrate, ELrate, Stop, Limit: Integer;

 

procedure OnCreate;

begin

AddCandleHistorySetting(@History, 'Candle History', '', CI_5_Minutes, 100);

History.OnNewCandleEvent := @OnNewCandle;

AddAccountSetting(@Account, 'Account', '');

AddFloatSetting(@Amount, 'Amount(:Lots)', 5);

AddIntegerSetting(@ESRate, 'ES in pips', 30);

AddIntegerSetting(@ELRate, 'EL in pips', 50);

AddIntegerSetting(@Stop, 'Stop', 15);

AddIntegerSetting(@Limit, 'Limit', 20);

end;

 

procedure OnNewCandle;

begin

Point := History.Instrument.PointSize;

if History.Last.Close>History.Last(1).Close then

 begin

  CreateEntryOrder(History.Instrument, Account, Amount, bsSell, History.Instrument.Sell+ELRate*Point,

History.Instrument.Buy+ELRate*Point+Stop*Point,

History.Instrument.Buy+ELRate*Point-Limit*Point,

otELimit, 'EntryLimitSell');

  CreateEntryOrder(History.Instrument, Account, Amount, bsBuy, History.Instrument.Buy+ESRate*Point,

History.Instrument.Sell+ESRate*Point-Stop*Point,

History.Instrument.Sell+ESRate*Point+Limit*Point,

otEStop, 'EntryStopBuy');

 end;

end;