Login Page - Create Account

Support Board


Date/Time: Sat, 18 May 2024 18:26:01 +0000



Post From: Can I modify using s_SCNewOrder ModifyOrder an order given by the spreadsheet?

[2015-03-05 00:31:19]
Sierra Chart Engineering - Posts: 104368
Here is an example:

/*==========================================================================*/
SCSFExport scsf_TradingExampleModifyStopAttachedOrders(SCStudyInterfaceRef sc)
{
  // Define references to the Subgraphs and Inputs for easy reference
  SCSubgraphRef BuyEntrySubgraph = sc.Subgraph[0];
  SCSubgraphRef SellEntrySubgraph = sc.Subgraph[1];
  SCSubgraphRef FastSimpMovAvgSubgraph = sc.Subgraph[4];
  SCSubgraphRef SlowSimpMovAvgSubgraph = sc.Subgraph[5];

  SCInputRef Enabled = sc.Input[0];


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

    sc.GraphName = "Trading Example: Modify Stop Attached Orders";

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

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

    FastSimpMovAvgSubgraph.Name = "Fast Moving Average";
    FastSimpMovAvgSubgraph.DrawStyle = DRAWSTYLE_LINE;
    FastSimpMovAvgSubgraph.PrimaryColor = RGB(255, 255, 255);
    FastSimpMovAvgSubgraph.DrawZeros = false;
    FastSimpMovAvgSubgraph.LineWidth = 2;

    SlowSimpMovAvgSubgraph.Name = "Slow Moving Average";
    SlowSimpMovAvgSubgraph.DrawStyle = DRAWSTYLE_LINE;
    SlowSimpMovAvgSubgraph.PrimaryColor = RGB(0, 255, 0);
    SlowSimpMovAvgSubgraph.DrawZeros = false;
    SlowSimpMovAvgSubgraph.LineWidth = 2;

    Enabled.Name = "Enabled";
    Enabled.SetYesNo(0);


    sc.AllowMultipleEntriesInSameDirection = false;
    sc.MaximumPositionAllowed = 2;
    sc.SupportReversals = false;

    // This is false by default.
    sc.SendOrdersToTradeService = false;

    sc.AllowOppositeEntryWithOpposingPositionOrOrders = false;

    sc.SupportAttachedOrdersForTrading = false;

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

    // Only 1 trade for each Order Action type is allowed per bar.
    sc.AllowOnlyOneTradePerBar = true;

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

    sc.AutoLoop = 1;
    sc.GraphRegion = 0;

    sc.FreeDLL = 0;

    return;
  }

  if (!Enabled.GetYesNo())
    return;

  int OrderIndex = 0;
  while (true)
  {
    // Get the next order details structure.
    s_SCTradeOrder OrderDetails;
    if (sc.GetOrderByIndex(OrderIndex, OrderDetails) == SCTRADING_ORDER_ERROR)
      break;

    ++OrderIndex;

    // Skip if not a working order.
    if (!OrderDetails.IsWorking())
      continue;

    // Skip if not an attached order.
    if (!OrderDetails.IsAttachedOrder())
      continue;

    // Skip if not a stop order.
    if (OrderDetails.OrderTypeAsInt != SCT_ORDERTYPE_STOP)
      continue;

    //Modify order
    s_SCNewOrder ModifyOrder;
    ModifyOrder.InternalOrderID = OrderDetails.InternalOrderID;
    //Modify order to same price. Since the price is the same, it will be ignored, but this only serves as an example of an order modification.
    ModifyOrder.Price1 = OrderDetails.Price1;

    sc.ModifyOrder(ModifyOrder);
  }
}

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