ExitLongStopLimit()

View as Markdown

Definition

Generates a sell stop limit order to exit a long position.

Method Return Value

An Order read-only object that represents the order. Reserved for experienced programmers, additional information can be found within the Advanced Order Handling section.

Syntax

ExitLongStopLimit(double limitPrice, double stopPrice)

ExitLongStopLimit(int quantity, double limitPrice, double stopPrice)

ExitLongStopLimit(double limitPrice, double stopPrice, string fromEntrySignal)

ExitLongStopLimit(double limitPrice, double stopPrice, string signalName, string fromEntrySignal)

ExitLongStopLimit(int quantity, double limitPrice, double stopPrice, string signalName, string fromEntrySignal)

The following method variation is for experienced programmers who fully understand Advanced Order Handling concepts:

ExitLongStopLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, double stopPrice, string signalName, string fromEntrySignal)

Parameters

ParameterDescription
signalNameUser defined signal name identifying the order generated. Max 50 characters.
fromEntrySignalThe entry signal name. This ties the exit to the entry and exits the position quantity represented by the actual entry. Note: Using an empty string will attach the exit order to all entries.
limitPriceThe limit price of the order.
stopPriceThe stop price of the order.
quantityEntry order quantity.
isLiveUntilCancelledThe order will NOT expire at the end of a bar but instead remain live until the CancelOrder() method is called or its time in force is reached.
barsInProgressIndexThe index of the Bars object the order is to be submitted against. Used to determine what instrument the order is submitted for. See the BarsInProgress property.

Examples

1private double stopPrice = 0;
2
3protected override void OnBarUpdate()
4{
5 if (CurrentBar < 20)
6 return;
7
8 // Only enter if at least 10 bars has passed since our last entry
9 if ((BarsSinceEntryExecution() > 10 || BarsSinceEntryExecution() == -1) && CrossAbove(SMA(10), SMA(20), 1))
10 {
11 EnterLong("SMA Cross Entry");
12 stopPrice = Low[0] - 5 * TickSize;
13 }
14
15 // Exits position
16 ExitLongStopLimit(stopPrice - (10 * TickSize), stopPrice);
17}

Tips

  • This method is ignored if a long position does not exist
  • It is helpful to provide a signal name if your strategy has multiple exit points to help identify your exits on a chart
  • You can tie an exit to an entry by providing the entry signal name in the parameter “fromEntrySignal”
  • If you do not specify a quantity the entire position is exited rendering your strategy flat
  • If you do not specify a “fromEntrySignal” parameter the entire position is exited rendering your strategy flat