Support

Equilla Formula Language

ExitPosition

Places an order to exit, or partially exit, the current position irrespective of whether the position is currently long or short.

Syntax

ExitPosition [("Name")] [From Entry ("EntryName")] [Quantity Shares|Contracts [Total]] [TradeMode] [Trading Symbol]

Inputs

Name
: (Optional) Specifies the name of this order. Can be any valid constant string. String variables are not allowed here. Please note that the brackets are mandatory here. Naming orders is especially useful when using pyramiding.
EntryName
: (Optional) Specifies the name of the order that this closing order refers to. Any valid constant string. String variables are not allowed here. Please note that the brackets are mandatory here.
Quantity
: (Optional) The quantity of shares/contracts that will be traded. If omitted the complete position is closed. If quantity is used then the current position is reduced by the number of shares specified in amount.
Total
: (Optional) If the Total keyword is used, the complete position is reduced by the number of shares specified in amount. If total is not used then each order in the current position is reduced by the number of shares specified in amount. Example: A system goes short with 2 shares and another 2 shares in a second order. Pyramiding is enabled. A "ExitPosition 1 share" would reduce each order by one so you are still 2 shares short (1+1). A "ExitPosition 1 share total" order would reduce only one order (the first one) by one share, so you are 3 shares short (1+2).
TradeMode
: (Optional) The trademode controls how the actual trade is being processed. There are several modes available. The table below describes the different trademodes in more detail. If the trade mode is omitted, "Next Bar at Market" is taken as the default.
Symbol
: (Optional) The symbol the order should be generated for. The default value is Data1.

Remarks

Trade Modes

Mode Description
This Bar at Market The trade is executed immediately.
This Bar on Close The trade is executed when the current bar closes.
Next Bar at Market The trade is executed at the next bar's opening price.
Next Bar at price Stop Places a stop order. If the price is equal or higher than price on the next bar, the order is executed. Otherwise it gets cancelled. This order is only valid on the next bar
Next Bar at price Limit Places a limit order. If the price is equal or lower than price on the next bar, the order is executed. Otherwise it gets cancelled. This order is only valid on the next bar
This Bar at price The trade is executed at the specified price. The order is executed regardless of the current price, however the price will be adjusted to fit into the current bar's high/low price range. If the order can not be filled immediately it will get cancelled. WARNING: This order type is entirely artificial and, if used for realtime trade generation, will lead to results that do not mimic real trades. This order type is best used to produce orders during backtesting that are synchronised with actual, previously executed orders.

Examples

Close any open position when the bar closes
ExitPosition This Bar on Close;
Close any open position when the next bar starts
ExitPosition Next Bar at Market;
Decrease every open entry by 10 shares
ExitPosition 10 Shares Next Bar at Market;
Decrease the open position by 10 shares in total
ExitPosition 10 Shares Total Next Bar at Market;
Generate an exit order based on the next bars open price
ExitPosition Next Bar at Open of Next Bar + 10 Stop;
A simple trading strategy
Input: Price( Close ), Period( 10, 1 ), MaxBarsPerPosition( 5, 1 ); If Average( Price, Period ) Crosses Price Then Cover Next Bar at Market Else If Price Crosses Average( Price, Period ) Then Short Next Bar at Market; If MarketPosition <;>; MarketPositionFlat Then Begin If BarsSinceEntry() >; MaxBarsPerPosition Then ExitPosition Next Bar At Market; End;
Trade Data2 depending on its price compared to the price of Data1
If Close of Data2 >; Close of Data1 Then Buy This Bar At Market Trading Data2; If Close of Data2 <; Close of Data1 Then Short This Bar At Market Trading Data2; ExitPosition This Bar On Close Trading Data2;