Login Page - Create Account

Support Board


Date/Time: Sun, 05 May 2024 08:02:04 +0000



Multiple attached entry orders

View Count: 1478

[2018-05-14 20:56:10]
User39772 - Posts: 311
Hello Support,

on my entry signal I try to execute 2 independent entry orders wit a trailing stops each based on the following code:

sc.AllowMultipleEntriesInSameDirection = true;
sc.AllowOnlyOneTradePerBar = false;
sc.AllowEntryWithWorkingOrders = true;
sc.SupportAttachedOrdersForTrading = true;

if (Entry == true)

{

s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = 1;
NewOrder.OrderType = SCT_ORDERTYPE_MARKET;
sc.CancelAllWorkingOrdersOnExit = true;
NewOrder.AttachedOrderStop1Type = SCT_ORDERTYPE_TRAILING_STOP;
NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;
NewOrder.Stop1Offset = StopValue.GetFloat() * sc.TickSize;
...
Buy Entry(NewOrder);
...

s_SCNewOrder NewOrder1;
NewOrder1.OrderQuantity = 1;
NewOrder1.OrderType = SCT_ORDERTYPE_MARKET;
NewOrder1.AttachedOrderStop1Type = SCT_ORDERTYPE_TRAILING_STOP;
NewOrder1.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;
NewOrder1.Stop1Offset = StopValue.GetFloat() * sc.TickSize;
...
Buy Entry(NewOrder1);
...

}

During Replay I see an open position of 2 (= the sum of both orders) but only a trailing stop with a size = 1.
If that trailing stop is hit, the open position is reduced by 1 but the 2nd positin remains open with no TS.

Do you see any mistake or misunderstanding on my side regarding the use of the functions ?
[2018-05-15 08:55:08]
User39772 - Posts: 311
Hello Support,

please help in this case. In the Orders & Positions Windows there is cleraly only one Trailstop order visible
whereas two Marketorders are executed as I see from the Trade Activity Log.


The Questions is: How can I execute two separate orders with idependent attached trailstops simultaneously.

Since I use two differnetn Objects NewOrder and NewOrder1 my understanding from your documentation is, that there should also be two separate trailstop orders.

Pleass let me know if my understanding is correct. It would also be helpful to have an example.
[2018-05-15 19:36:27]
Sierra Chart Engineering - Posts: 104368
We need some time to test this.
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
[2018-05-16 15:51:28]
Zdislav - Posts: 73
There is this in the first order statement:

sc.CancelAllWorkingOrdersOnExit = true;

Try to remove it. And also check the lines for setting stop offset:
NewOrder.Stop1Offset = StopValue.GetFloat() * sc.TickSize;

If the StopValue is in ticks, it should be an Integer...StopValue.GetInt()


Z.
[2018-05-20 22:55:48]
Sierra Chart Engineering - Posts: 104368
We cannot reproduce the problem. Here is the test function which you can use as an example.

SCSFExport scsf_ACSILTradingTest2(SCStudyInterfaceRef sc)
{
  //Define references to the Subgraphs and Inputs for easy reference
  SCSubgraphRef BuyEntrySubgraph = sc.Subgraph[0];
  SCSubgraphRef BuyExitSubgraph = sc.Subgraph[1];
  SCSubgraphRef SellEntrySubgraph = sc.Subgraph[2];
  SCSubgraphRef SellExitSubgraph = sc.Subgraph[3];

  SCInputRef Enabled = sc.Input[0];


  if (sc.SetDefaults)
  {
    // Set the study configuration and defaults.

    sc.GraphName = "Trading Test 2";

    BuyEntrySubgraph.Name = "Buy Entry";
    BuyEntrySubgraph.DrawStyle = DRAWSTYLE_ARROW_UP;
    BuyEntrySubgraph.PrimaryColor = RGB(0, 255, 0);
    BuyEntrySubgraph.LineWidth = 2;
    BuyEntrySubgraph.DrawZeros = false;

    BuyExitSubgraph.Name = "Buy Exit";
    BuyExitSubgraph.DrawStyle = DRAWSTYLE_ARROW_DOWN;
    BuyExitSubgraph.PrimaryColor = RGB(255, 128, 128);
    BuyExitSubgraph.LineWidth = 2;
    BuyExitSubgraph.DrawZeros = false;

    SellEntrySubgraph.Name = "Sell Entry";
    SellEntrySubgraph.DrawStyle = DRAWSTYLE_ARROW_DOWN;
    SellEntrySubgraph.PrimaryColor = RGB(255, 0, 0);
    SellEntrySubgraph.LineWidth = 2;
    SellEntrySubgraph.DrawZeros = false;

    SellExitSubgraph.Name = "Sell Exit";
    SellExitSubgraph.DrawStyle = DRAWSTYLE_ARROW_UP;
    SellExitSubgraph.PrimaryColor = RGB(128, 255, 128);
    SellExitSubgraph.LineWidth = 2;
    SellExitSubgraph.DrawZeros = false;

    Enabled.Name = "Enabled";
    Enabled.SetYesNo(0);
    Enabled.SetDescription("This input enables the study and allows it to function. Otherwise, it does nothing.");

    // This is false by default. Orders will be simulated.
    sc.SendOrdersToTradeService = false;

    sc.AllowMultipleEntriesInSameDirection = false;

    //This must be equal to or greater than the order quantities you will be submitting orders for.
    sc.MaximumPositionAllowed = 10000;

    sc.SupportReversals = true;
    sc.AllowOppositeEntryWithOpposingPositionOrOrders = true;

    // This variable controls whether to use or not use attached orders that are configured on the Trade Window for the chart.
    sc.SupportAttachedOrdersForTrading = false;

    //This variable controls whether to use the "Use Attached Orders" setting on the Trade Window for the chart
    sc.UseGUIAttachedOrderSetting = false;

    sc.CancelAllOrdersOnEntriesAndReversals = false;
    sc.AllowEntryWithWorkingOrders = false;
    sc.CancelAllWorkingOrdersOnExit = true;
    sc.AllowOnlyOneTradePerBar = false;

    //This needs to be set to true when a trading study uses trading functions.
    sc.MaintainTradeStatisticsAndTradesData = true;

    sc.AutoLoop = true;
    sc.GraphRegion = 0;

    // During development set this flag to 1, so the DLL can be modified. When development is completed, set it to 0 to improve performance.
    sc.FreeDLL = 0;

    return;
  }

  //These must be outside of the sc.SetDefaults code block since they have a dependency upon an actual chart object existing
  sc.SupportTradingScaleIn = 0;
  sc.SupportTradingScaleOut = 0;


  if (!Enabled.GetYesNo())
    return;

  if (sc.LastCallToFunction)
    return;//nothing to do


  // Run the below code only on the last bar
  if (sc.Index < sc.ArraySize - 1)
    return;



  sc.AllowMultipleEntriesInSameDirection = true;
  sc.AllowOnlyOneTradePerBar = false;
  sc.AllowEntryWithWorkingOrders = true;
  sc.SupportAttachedOrdersForTrading = true;
  sc.CancelAllWorkingOrdersOnExit = true;

  s_SCPositionData PositionData;
  sc.GetTradePosition(PositionData);


  if (PositionData.PositionQuantity == 0)
  {

    s_SCNewOrder NewOrder;
    NewOrder.OrderQuantity = 1;
    NewOrder.OrderType = SCT_ORDERTYPE_MARKET;
    NewOrder.AttachedOrderStop1Type = SCT_ORDERTYPE_TRAILING_STOP;
    NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;
    NewOrder.Stop1Offset = 10 * sc.TickSize;
    sc.BuyEntry(NewOrder);

    s_SCNewOrder NewOrder1;
    NewOrder1.OrderQuantity = 1;
    NewOrder1.OrderType = SCT_ORDERTYPE_MARKET;
    NewOrder1.AttachedOrderStop1Type = SCT_ORDERTYPE_TRAILING_STOP;
    NewOrder1.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;
    NewOrder1.Stop1Offset = 15 * sc.TickSize;
    sc.BuyEntry(NewOrder1);
  }
}

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

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account