Login Page - Create Account

Support Board


Date/Time: Thu, 30 Jan 2025 19:00:07 +0000



[Programming Help] - Acsil TP Management Assistance

View Count: 1361

[2019-03-26 22:03:07]
User920967 - Posts: 62
Hello!

Currently having a small issue with our TP management in acsil, clearly the mistake is on our end, hoping someone can shed light on a solution that has eluded us.

Attached image explains the issue much more concisely than words, please have a look.

Essentially, the situation is that our TP's are closing the incorrect parent orders. Please note, we are not using buyexit or sellexit order actions, but rather setting fixed targets when declaring our s_SCNewOrder object.

Any hints are appreciated.

Thanks!
imagesierra help pic.png / V - Attached On 2019-03-26 22:01:15 UTC - Size: 38.3 KB - 315 views
[2019-03-26 22:23:51]
User525733 - Posts: 126
how were the orders/targets implemented?...i would advise you to attach the code in order to help root cause the issue.
[2019-03-26 23:04:10]
User920967 - Posts: 62
This is essentially what we are using . . .


//Create an s_SCNewOrder object
s_SCNewOrder Order;
Order.OrderQuantity = 2;
Order.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;
Order.OrderType = SCT_ORDERTYPE_LIMIT; // set order type to LIMIT

  if(condition) {
    Order.Price1 = Price;
    Order.Target1Price = Price_TP1;
    Order.Target2Price = Price_TP2;

  int Result;
Result = Long == true ? (int)sc.BuyEntry(Order) : (int)sc.SellEntry(Order);

}

[2019-03-26 23:32:42]
User525733 - Posts: 126
nothing in what you shared is a problem.....need to see the rest of it
[2019-03-27 16:57:00]
User920967 - Posts: 62
This is the code we are using to test shorts only. Error is the same as pic in post 1, mismatching of TP with parent order.

We are thinking either 1) we are missing some sort of setting within sierra, or 2)we must use sellexit to achieve our desired outcome.

Thanks in advance...very much appreciated




// The top of every source code file must include this line
#include "sierrachart.h"

// For reference, refer to this page:
// Advanced Custom Study Interface and Language (ACSIL)

// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies.
SCDLLName("xxxx Studies")

SCSFExport scsf_TradingExampleWithStopAllAttachedOrdersDirectlyDefined(SCStudyInterfaceRef sc) {
  // Define references to the Subgraphs and Inputs for easy reference
  SCSubgraphRef BuyEntrySubgraph = sc.Subgraph[0];
  SCSubgraphRef SellEntrySubgraph = sc.Subgraph[2];
  SCSubgraphRef SimpMovAvgSubgraph = sc.Subgraph[4];
  SCInputRef Enabled = sc.Input[0];


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

    sc.GraphName = "Trading Example: With Hardcoded Attached Orders (uses Stop All)";

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


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


    SimpMovAvgSubgraph.Name = "Simple Moving Average";
    SimpMovAvgSubgraph.DrawStyle = DRAWSTYLE_LINE;
    SimpMovAvgSubgraph.DrawZeros = false;

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

    sc.StudyDescription = "This study function is an example of how to use the ACSIL Trading Functions. This example uses Attached Orders defined directly within this function. This function will display a simple moving average and perform a Buy Entry when the Last price crosses the moving average from below and a Sell Entry when the Last price crosses the moving average from above. A new entry cannot occur until the Target or Stop has been hit. When an order is sent, a corresponding arrow will appear on the chart to show that an order was sent. This study will do nothing until the Enabled Input is set to Yes.";

    sc.AllowMultipleEntriesInSameDirection = true;
    sc.MaximumPositionAllowed = 6;
    sc.SupportReversals = false;

    // This is false by default. Orders will go to the simulation system always.
    sc.SendOrdersToTradeService = false;

    sc.AllowOppositeEntryWithOpposingPositionOrOrders = false;

    sc.SupportAttachedOrdersForTrading = false; // This can be false in this function because we specify Attached Orders directly with the order which causes this to be considered true when submitting an order.

    sc.CancelAllOrdersOnEntriesAndReversals= false;
    sc.AllowEntryWithWorkingOrders = true;
    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.FreeDLL = 1;
    sc.AutoLoop = 1;
    sc.GraphRegion = 0;

    return;
  }

  if (!Enabled.GetYesNo())
    return;


  SCFloatArrayRef Last = sc.Close;

  // Use persistent variables to remember attached order IDs so they can be modified or canceled.
  int& Target1OrderID = sc.GetPersistentInt(0);
  int& Target2OrderID = sc.GetPersistentInt(1);
  int& StopAllOrderID = sc.GetPersistentInt(2);

  int & ExecuteModifyOrder = sc.GetPersistentInt(3);

  // Calculate the moving average
  sc.SimpleMovAvg(Last, SimpMovAvgSubgraph, sc.Index, 10);

  if (sc.IsFullRecalculation)
    return;

  // Create an s_SCNewOrder object.
  s_SCNewOrder NewOrder;
  NewOrder.OrderQuantity = 2;
  NewOrder.OrderType = SCT_ORDERTYPE_MARKET;
  NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;

  //Specify Targets and Stops
  NewOrder.Target1Offset = 8*sc.TickSize;
  NewOrder.Target2Offset = 111*sc.TickSize;
  NewOrder.StopAllOffset = 35*sc.TickSize;
  
  
  // Buy when the last price crosses the moving average from below.
  if (sc.CrossOver(Last, SimpMovAvgSubgraph) == CROSS_FROM_BOTTOM && sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED) {
    
  }
  
  // Sell when the last price crosses the moving average from above.
  else if (sc.CrossOver(Last, SimpMovAvgSubgraph) == CROSS_FROM_TOP && sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED)
  {
    //NewOrder.Price1 = Last[sc.Index] - 2*sc.TickSize;
    int Result = (int)sc.SellEntry(NewOrder);
    if (Result > 0) //If there has been a successful order entry, then draw an arrow at the high of the bar.
    {
      SellEntrySubgraph[sc.Index] = sc.High[sc.Index];
      ExecuteModifyOrder =1;

      // Remember the order IDs for subsequent modification and cancellation
      Target1OrderID = NewOrder.Target1InternalOrderID;
      Target2OrderID = NewOrder.Target2InternalOrderID;
      StopAllOrderID = NewOrder.StopAllInternalOrderID;
    }

  }
}


Date Time Of Last Edit: 2019-03-27 18:00:13
[2019-03-28 00:15:02]
User920967 - Posts: 62
Perhaps sierra engineering can chime-in. . . How do you keep child orders closing the correct parent orders?

The simple code above just closes orders that are furthest away, with no regard for the parent.

What is the solution: 1) we are missing some sort of setting within sierra, or 2)we must use sellexit to achieve our desired outcome 3) we must use NewOrder.OCOGroup1Quantity and NewOrder.OCOGroup2Quantity 4) we must use or create another function to keep track of all the parent/child orders?

Any assistance is appreciated, we just want to make sure we are headed on the correct path before starting.

Thanks in advance

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

Login

Login Page - Create Account