Login Page - Create Account

Support Board


Date/Time: Wed, 08 Dec 2021 09:14:38 +0000



Post From: Now Released: Upcoming CME / EUREX Direct Routing

[2021-05-08 06:31:59]
Sierra Chart Engineering - Posts: 98846
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. If possible please keep your questions brief and to the point. Please be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

If your question/request has been answered and you do not have anything further, then it is easiest for us if you do not reply again to say thank you.
Date Time Of Last Edit: 2021-05-08 23:23:56