Login Page - Create Account

Support Board


Date/Time: Wed, 14 May 2025 06:43:48 +0000



Post From: Issue with sc.MaximumPositionAllowed

[2017-08-11 06:24:40]
onnb - Posts: 663
The short description of this is that MaximumPositionAllowed is not working as expected when placing market orders with OCO
Just tested this with 1598 but from what we see the same thing is happening in previous versions.

To reproduce:

I set the MaximumPositionAllowed to 2
I then submit market order, qty 2 with target/stop OCO.
I can do this multiple times so that my position size grows beyond 2.

If I do the same without the OCO, then after the first market order I get expected error when submitting more orders.

The script below demonstrates this. It places an order at the close of the bar. When I comment out the stop/target, the MaximumPositionAllowed works as expected.

SCSFExport scsf_maxpostest(SCStudyInterfaceRef sc)
{
  if (sc.SetDefaults)
  {
    sc.GraphName = "MaximumPositionAllowed Test";

    sc.GraphRegion = 0;
    sc.ValueFormat = VALUEFORMAT_INHERITED;
    sc.FreeDLL = 1;
    sc.AutoLoop = 1;

    return;
  }

  sc.MaximumPositionAllowed = 2;
  sc.AllowMultipleEntriesInSameDirection = 1;
  sc.AllowEntryWithWorkingOrders = 1;
  sc.AllowOnlyOneTradePerBar = 0;

  s_SCPositionData pd;
  sc.GetTradePosition(pd);

  if (sc.Index == sc.ArraySize - 2)
  {

    s_SCNewOrder order;
    order.OrderType = SCT_ORDERTYPE_MARKET;
    order.OrderQuantity = 2;
    order.Stop1Offset = 11;
    order.Target1Offset = 11;

    sc.AddMessageToLog(SCString().Format("sc.MaximumPositionAllowed = %i", sc.MaximumPositionAllowed), 1);

    int scerr = sc.BuyEntry(order);
    if (scerr > 0)
      sc.AddMessageToLog(SCString().Format(" the order has been placed", scerr), 1);
    else
      sc.AddMessageToLog(SCString().Format(" the order submission was ignored, SC error %i", scerr), 1);
    
  }
}