Login Page - Create Account

Support Board


Date/Time: Sat, 20 Apr 2024 10:20:44 +0000



Cancel attached order with sc.BuyExit()

View Count: 1531

[2014-04-17 18:43:14]
VF56002 - Posts: 27
In my strategy I have set this
sc.CancelAllWorkingOrdersOnExit = true;
and on exit I also use
sc.CancelAllOrders();
when I use sc.BuyExit() function during replay backtesting my strategy an attached stop and target order remain open but should be canceled ... it seems it worked before. I am on pre-release 1121. Can you check that? Thanks
Date Time Of Last Edit: 2014-04-17 19:27:07
[2014-04-17 20:12:49]
VF56002 - Posts: 27
problem seems to be solved by referencing order by ID ... sc.CancelOrder(StopLossOrderID) and sc.CancelOrder(ProfitTargetOrderID)
I expected setting sc.CancelAllWorkingOrdersOnExit = true in MANAGED mode will also do that job on BuyExit call but it does not seem to be so ...

Date Time Of Last Edit: 2014-04-17 20:15:47
[2014-04-20 07:46:19]
sbsierra - Posts: 71
It seems like, that sc.CancelAllWorkingOrderyOnExit is not working on versions above 1120. I am on 1122 and it does not work for ACSIL and not for Spreadsheet Systems! Please SC Support check this.
Date Time Of Last Edit: 2014-04-20 07:47:41
[2014-04-20 19:34:00]
Sierra Chart Engineering - Posts: 104368
Checking on this. Give us about two hours to get a new release out.

This must be from a Trade Account ID check when canceling orders that we have added. This was tested and confirmed to work, so we are not quite sure at this point what the problem is.
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
[2014-04-20 21:05:49]
Sierra Chart Engineering - Posts: 104368
Using the below function, we could not duplicate the problem. We are releasing 1123 now. There have been no changes which would affect the problem.

However, please test the below code in version 1123. What you will see is that there will be a position created with attached orders and then it will be exited . This will continuously occur. It is easiest to test this during a slow playing replay.

SCSFExport scsf_ACSILTradingTest(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";

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

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

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

    SellExitSubgraph.Name = "Sell Exit";
    SellExitSubgraph.DrawStyle = DRAWSTYLE_ARROWUP;
    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 = true;

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

    sc.SupportReversals = false;
    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 = true;
    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;

    //sc.OnExternalDataImmediateStudyCall= true;//Increases CPU load. Use with caution.

    return;
  }

  //return;

  //These must be outside of the sc.SetDefaults code block
  sc.SupportTradingScaleIn = 1;
  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;


  s_SCPositionData PositionData;
  sc.GetTradePosition( PositionData);
  if (PositionData.PositionQuantity== 0)
  {
    // Create an s_SCNewOrder object.
    s_SCNewOrder NewOrder;
    NewOrder.OrderQuantity = 1;
    NewOrder.OrderType = SCT_MARKET;
    NewOrder.TimeInForce = SCT_TIF_GTC;

    //Specify a Target and a Stop with 8 tick offsets. We are specifying one Target and one Stop, additional targets and stops can be specified as well.
    NewOrder.Target1Offset = 8*sc.TickSize;
    NewOrder.Stop1Offset = 8*sc.TickSize;
    NewOrder.OCOGroup1Quantity = 1; // If this is left at the default of 0, then it will be automatically set.
    sc.BuyEntry(NewOrder);
  }
  else
  {
    s_SCNewOrder NewOrder;
    NewOrder.OrderQuantity = 0; //Flatten
    NewOrder.OrderType = SCT_MARKET;
    sc.BuyExit(NewOrder);
  }
}

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
[2014-04-20 21:06:26]
Sierra Chart Engineering - Posts: 104368
We need about 30 more minutes before we get 1123 released.
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
[2014-04-21 07:37:02]
sbsierra - Posts: 71
I compiled your code and it works as expected with version 1123.
My own ACSIL code, which only uses attached orders created by the system, also seems to work as expected.

But ...
When I use a Spreadsheet System, which just opens a position and attached orders come from the trade window,
a spreadsheet exit signal does not cancel the attached order.

With version 1117 all orders where canceled.
[2014-04-21 07:49:36]
Sierra Chart Engineering - Posts: 104368
We just tested this on version 1123 and when using Buy Exit, the Attached Orders set up on the Trade Window were canceled and the position was flattened:

Auto-Trading: Replay 30.0X: 6A-201406-CME 5 Min #1 | DefaultSpreadsheetStudy | Canceled all orders for symbol: [Sim]6A-201406-CME | Bar Start Time: 2014-04-17 06:40:00 | 2014-04-21 03:47:02


How do you have this input set:
Cancel All Working Orders on Exit


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: 2014-04-21 07:50:13
[2014-04-21 08:46:16]
sbsierra - Posts: 71
Cancel All Working Orders on Exit is set to true
[2014-04-21 09:04:05]
sbsierra - Posts: 71
I mean it is set to Yes
[2014-04-21 16:46:40]
Sierra Chart Engineering - Posts: 104368
We have to do more testing. Not quite sure about this at the moment.
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
[2014-04-22 09:42:36]
Sierra Chart Engineering - Posts: 104368
When you notice this problem, what is the Trade Account set to on the Trade Window.? For reference refer to:
http://www.sierrachart.com/index.php?l=doc/doc_TradeWindow.html#SelectingTradeAccount

For the orders that are not canceling, look in the Trade >> Trade Orders and Positions >> Orders tab. What is the Trade Account for those orders?
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
[2014-04-23 09:16:30]
sbsierra - Posts: 71
I am unsure, currently I can not reproduce the problem with 1123.
[2014-04-23 09:24:21]
Sierra Chart Engineering - Posts: 104368
This is good, because really there should not be this issue after careful code review.

When you do have the problem, we do think it has something to do with the Trade Account not matching between the Trade Window and the orders. Although this should never be a problem in simulation mode.

So check to make sure the Trade accounts match when you have the issue, assuming you do again.
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: 2014-04-23 09:24:49

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

Login

Login Page - Create Account