Login Page - Create Account

Support Board


Date/Time: Wed, 08 May 2024 16:43:19 +0000



sc.GetOrderByIndex

View Count: 1284

[2014-10-27 16:25:14]
User29404 - Posts: 4
Hallo,
I have a problem with function sc.GetOrderByIndex(i, OrderDetails). This function return allways -1 (SCTRADING_ORDER_ERROR). When I use at the same moment sc.GetOrderByOrderID(15233, OrderDetails) this function return 1
[2014-10-27 16:51:02]
Sierra Chart Engineering - Posts: 104368
Is there a difference between the symbol of the chart and the symbol of the order?

What is the variable 'i' set to?
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-10-27 17:11:23]
User29404 - Posts: 4
Symbol of the chart and the symbol of the order is the same (RLM-MZ4).
Variable i is increment (index) and begin from 0.

[2014-10-28 03:35:46]
Sierra Chart Engineering - Posts: 104368
As we suspected, we tested this and we found no problem. It worked properly.

Here is a code example you can work with:

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;

    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_DAY;

    //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.
    int Result = sc.BuyEntry(NewOrder);
    if(Result > 0)
    {
      s_SCTradeOrder OrderDetails;
      Result = sc.GetOrderByIndex(0, OrderDetails);
    }
  }

}

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-10-29 16:59:35]
User29404 - Posts: 4
Thank You,
your example code helped me to find my fault. I forgot the diference between Trade Simulation Mode and sc.SendOrdersToTradeService.

Can you help me once more? I need get cash balance in the account for assessment of risk in my study. This is same value, you can see in Trade >> Trade orders and Positions >> Balance
Date Time Of Last Edit: 2014-10-29 17:23:52
[2014-10-29 17:24:22]
Sierra Chart Engineering - Posts: 104368
This is sc.TradeServiceAccountBalance
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-01-26 19:15:45]
User14532 - Posts: 6
Hi
I have a problem with the "GetOrderByIndex". In simulation mode it works well. If I switch to live (Interactive Broker). "GetOrderByIndex" does not return any result. Even though live orders are displayed in the "Orders And Positions" window. Can you help me?
thank you.
[2018-01-26 19:24:27]
Sierra Chart Engineering - Posts: 104368
Refer to the documentation for this function:
Automated Trading From an Advanced Custom Study: sc.GetOrderByIndex

Always refer to the documentation. The documentation does explain how this function works.
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: 2018-01-26 19:27:23
[2018-01-26 19:27:44]
Sierra Chart Engineering - Posts: 104368
Prior post has now been made visible.
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