NinjaScript > Language Reference > Strategy > Order Methods > Managed Approach >

ExitShort()

Print this Topic Previous pageReturn to chapter overviewNext page

Definition
Generates a buy to cover market order to exit a short position.

 

Method Return Value

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

Syntax
ExitShort()

ExitShort(int quantity)
ExitShort(string fromEntrySignal)

ExitShort(string signalName, string fromEntrySignal)

ExitShort(int quantity, string signalName, string fromEntrySignal)

 

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

 

ExitShort(int barsInProgressIndex, int quantity, string signalName, string fromEntrySignal)

 

Parameters

signalName

User defined signal name identifying the order generated. Max 50 characters.

fromEntrySignal

The entry signal name. This ties the exit to the entry and exits the position quantity represented by the actual entry.

quantity

Entry order quantity.

barsInProgressIndex

The index of the Bars object the order is to be submitted against. See the BarsInProgress property. This determines what instrument the order is submitted for.

 

 

Examples

protected override void OnBarUpdate()
{
    if (CurrentBar < 20)
        return;
 
    // Only enter if at least 10 bars has passed since our last entry
    if (BarsSinceEntry() > 10 && CrossAbove(SMA(10), SMA(20), 1))
         EnterShort("SMA Cross Entry");

 

    // Exits position

    if (CrossBelow(SMA(10), SMA(20), 1))

         ExitShort();
}

 

 

Tips (also see Overview)

This method is ignored if a short 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