Close Position

This command will close a position and requires an account name value and an instrument name value. The instrument name value is the name of the NinjaTrader instrument including the exchange name. For equities, the symbol is sufficient.

This command will cancel any account-level working or pending orders and flatten the position if the position exists.

It is important to note that open or pending orders will not be canceled unless a position already exists that can be closed.

Advanced Usage - Scaling out

The generic CLOSEPOSITION command will close the entire position. It is also possible to scale out of a position by specifying the quantity or percent of contracts that should be closed.

The percentage of contracts to be closed is specific as a decimal number between 0 and 1. For example, percent=0.25; would be used to close 25% of the remaining contracts.

Percentages are always rounded up. So 10% of 1 remaining contract will close 1 contract. Quantities will close up to the remaining contract quantity. So if quantity=4; with 1 remaining contract, the 1 contract will be closed.

Example Payloads

Close the entire ES 09-25 positions in account Sim101.

key=your-secret-key;
command=CLOSEPOSITION;
account=Sim101;
instrument=ES 09-25;

Close 2 contracts of however many are remaining in account Sim101:

key=your-secret-key;
command=CLOSEPOSITION;
account=Sim101;
instrument=ES 09-25;
quantity=2;

Close 50% of the remaining contracts in account Sim101:

key=your-secret-key;
command=CLOSEPOSITION;
account=Sim101;
instrument=ES 09-25;
percent=0.5;

The instrument name value is the name of the NinjaTrader instrument, including the exchange name. For equities, the symbol is sufficient. This command will cancel any working orders and flatten the position.

Last updated