Strategy.doSell() Back Testing Functions
doSell() is a method of the Strategy Object that submits an order to close or sell a portion of an existing long position for back testing analysis through the Strategy Analyzer (Tools-->Back Testing). The Strategy Object is for back testing purposes only and is not intended for real time trading.
Syntax
Strategy .doSell( sDescription , FillType , FillBar [, nLotSize ][, nStopOrLimit ] )
Parameters
Parameter: | Description: | Default: |
sDescription | Required. String describing the type of signal for the trade. | n/a |
FillType | Required. Constant that specifies the type of fill for the trade (see Notes). | n/a |
FillBar | Required. Constant that specifies the bar where the fill for the trade will be recorded (see Notes). | n/a |
nLotSize | [Optional] Number of contracts/shares for the trade or lot size constant (see Notes). Back Testing | Preferences default |
nStopOrLimit | [Optional] Number for the Stop or Limit price of the trade if the fill type constants .STOP or .LIMIT are specified. | n/a |
Return Value(s)
Boolean true if filled, false if not filled.
Notes
Strategy must be long in order to use Strategy.doSell().
If the Fill Type of Strategy.LIMIT or Strategy.STOP is specified, the nStopOrLimit price parameter must be specified. Also, the formula logic used to determine the stop or limit price should ensure that the price is realistic. For example, if the price used is outside the range of the fill bar, the trade will still be recorded with that price, which will produce unrealistic back testing results.
Fill Bar Constants: | Description: |
Strategy. THISBAR | Records the trade on the current bar. |
Strategy. NEXTBAR | Records the trade on the next bar. |
Lot Size Constants: | Description: |
Strategy.DEFAULT | Specifies the lot size for the trade based on the default used in the Strategy Analyzer's Back Testing Preferences. |
Strategy.ALL | Specifies the position's entire lot size for closing trades. |
Starting with version 10.5 Strategy.doSell() will no longer reverse a position if the defined number of shares/contracts exceeds those held in a long position. If for example the strategy is long 200 shares/contracts and the amount set in Strategy.doSell() is for 600 shares/contracts the strategy object will now close the long position of 200 shares/contracts and discard the remainder instead of creating a short position of 400 shares/contracts.
Code Examples
// Exits a long position at the open of the current bar. // Trade condition should evaluate data on the previous bar.Strategy.doSell( "Exit Long Signal", Strategy.MARKET, Strategy.THISBAR ); // Exits a long position at the open of the next bar. // Trade condition should evaluate data at the close of the current bar.Strategy.doSell( "Exit Long Signal", Strategy.MARKET, Strategy.NEXTBAR ); // Exits a long position at the close of the current bar. // Trade condition may evaluate data on the current bar.Strategy.doSell( "Exit Long Signal", Strategy.CLOSE, Strategy.THISBAR ); // Exits a long position at the specified stop price on the current bar. // Trade condition should evaluate data on the current bar. var nStop = hl2(); Strategy.doSell( "Exit Long Signal", Strategy.STOP, Strategy.THISBAR , Strategy.ALL, nStop); // or the following, which assumes the position has at least 200 shares/contracts. Strategy.doSell( "Exit Long Signal", Strategy.STOP, Strategy.THISBAR , 200, nStop);
See Also
Back Testing Functions
EFS Library: Back Testing
Strategy Analyzer
eSignal Bulletin Board Search Engine
Help Guides and Tutorials