Login Page - Create Account

Support Board


Date/Time: Sat, 20 Apr 2024 13:48:41 +0000



Post From: Now Released: Upcoming CME Direct Routing

[2021-05-08 06:31:59]
Sierra Chart Engineering - Posts: 104368
Quantity Calculations For Risk Management


How the quantity of the existing Position for a particular Trade Account and Symbol and the quantities of working orders are calculated to ensure a preset Position Limit is not exceeded by the trader is explained here. In the code below, this variable is named MaximumPotentialPositionQuantity. When this variable exceeds the Position Limit, then the order is rejected or an order modification increase is rejected.

First the total quantity of all buy working orders (including market orders) is calculated. This is AllWorkingBuyOrdersQuantity. And the quantity of all sell working orders (including market orders) is calculated. This is AllWorkingSellOrdersQuantity.

In the case of where two orders are in an OCO group and these are Attached Orders, then the quantity of only one of them is used, and it is the larger of the two. Since one order will cancel the other.

MaximumPotentialLongPositionQuantity = AllWorkingBuyOrdersQuantity.

MaximumPotentialShortPositionQuantity = AllWorkingSellOrdersQuantity.

if (CurrentPositionQuantity.IsPositive())
{
MaximumPotentialLongPositionQuantity += CurrentPositionQuantity;

MaximumPotentialShortPositionQuantity += std::min(CurrentPositionQuantity, MaximumPotentialShortPositionQuantity.GetAbs());
}
else if (CurrentPositionQuantity.IsNegative())
{
MaximumPotentialShortPositionQuantity += CurrentPositionQuantity;

MaximumPotentialLongPositionQuantity -= std::min(CurrentPositionQuantity.GetAbs(), MaximumPotentialLongPositionQuantity);

}

// MaximumPotentialPositionQuantity will always be positive
MaximumPotentialPositionQuantity = std::max(MaximumPotentialLongPositionQuantity.GetAbs(), MaximumPotentialShortPositionQuantity.GetAbs());

if (MaximumPotentialPositionQuantity < CurrentPositionQuantity.GetAbs())
{
MaximumPotentialPositionQuantity = CurrentPositionQuantity.GetAbs();
}

// MaximumPotentialPositionQuantity will always be positive
MaximumPotentialPositionQuantity = max(MaximumPotentialLongPositionQuantity.GetAbs(), MaximumPotentialShortPositionQuantity.GetAbs());

if (MaximumPotentialPositionQuantity < CurrentPositionQuantity.GetAbs())
{
MaximumPotentialPositionQuantity = CurrentPositionQuantity.GetAbs();
}

Note: The below information has been updated.

Additional information:

Modifying the price of an existing order or reducing the quantity of existing order, are always allowed to pass the margin check even if the trader is under margin. The position limit check is still always enforced, but will allow these changes because there is no increase in quantity.

MaximumPotentialPositionQuantity is also calculated without considering a new submitted order. This is called MaximumPotentialPositionQuantityWithoutNewOrder.

If MaximumPotentialPositionQuantity is not larger than MaximumPotentialPositionQuantityWithoutNewOrder, the order type is a market order type, and the side of the order is opposite the current position quantity (it is reducing the quantity of the position), then this order is allowed to pass the margin check because there is not an increase in risk with this new order. There still is a recalculation of the required margin in this case. The Position Limit check still always applies.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2021-05-08 23:23:56