Login Page - Create Account

Support Board


Date/Time: Thu, 23 Jan 2025 09:25:30 +0000



Post From: How to limit the number of open trades

[2018-11-13 21:34:24]
Yoda - Posts: 106
I cannot seem to limit the number of open trades. I have tried two methods to limit open trades to only one (1):

Method 1 - sc.MaximumPositionAllowed

Although I have the following line of code in the sc.SetDefaults section:

sc.MaximumPositionAllowed = 1;


the Trade Activity Log is showing thousands of open positions. (see the attached screenshot of my Trader Activity Log)

This is occurring with a Single Chart replay in ver 1841.


Method 2 - PositionQuantity in Buy and Sell code

Following the documentation here: Automated Trading From an Advanced Custom Study: sc.GetTradePosition my code includes the following:

s_SCPositionData PositionData;
sc.GetTradePosition(PositionData);

int Quantity = PositionData.PositionQuantity; // Access the quantity

...

// Buy Order
if (Quantity == 0 && sc.CrossOver(Cross_CloseOrLow, LowOfDay) == CROSS_FROM_TOP)
{
Result = (int)sc.BuyOrder(NewBuyOrder);
...
}

The crossover works fine, but when I print out the Quantity in the Message Log, it is always showing as zero. Therefore the strategy keeps on buying.

Note: Setting sc.AllowOnlyOneTradePerBar to true significantly reduces the number of trades, but I would like to get the above two methods working properly.

Any suggestions on how I can get both Method 1 and 2 working?
imageTrade Activity Log Max Open Quantity 2018-11-13 1508.png / V - Attached On 2018-11-13 21:21:43 UTC - Size: 59.85 KB - 272 views