Login Page - Create Account

Support Board


Date/Time: Sun, 22 Dec 2024 05:54:17 +0000



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

[2015-03-05 20:12:24]
Sierra Chart Engineering - Posts: 104368
Use this updated 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 to same price. Since the price is the same, it will be ignored by the next line of code. This code only serves as an example of an order modification.
    double NewPrice = OrderDetails.Price1;

    //If modifying to the same price as previously, then do not perform the modification
    if(NewPrice == OrderDetails.LastModifyPrice1)
      continue;

    //Modify order
    s_SCNewOrder ModifyOrder;

    ModifyOrder.InternalOrderID = OrderDetails.InternalOrderID;
    
    ModifyOrder.Price1 = NewPrice;

    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