Login Page - Create Account

Support Board


Date/Time: Sat, 04 May 2024 15:29:20 +0000



ACSIL and Executing OCO Fails

View Count: 721

[2020-07-16 03:19:00]
User684204 - Posts: 1
Hello,

First, I just wanted to say I am super impressed with what you have managed to do with SC. It's really impressive.

Anyways, I have an issue when I'm trying to create a OCO order and I bet this will be user error. So I am able to get my proper signals for long/short. I then want to submit an order at the current price with a 20 tick profit and a 30 tick stop, which I have tried to do below.

To verify the logic code is working, I have a boolean variable `Input_PreviewCrosses` that when enabled, just draws some arrows for me where it would take entries and they show up correctly so that part is working. However, when I set the `Input_PreviewCrosses` to false, and the OCO order fires, I get a Result of 0 (hence my debug message saying the order failed). I'm not sure how to debug this further or figure out what parts of a NewOrder need to be set or configured.

I was following `SCSFExport scsf_ACSILTradingOCOExample(SCStudyInterfaceRef sc)` from the examples - thanks for providing the samples by the way.

Thanks for your help!

  
// Only evaluate when the bar closes
  if(sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_NOT_CLOSED )
    return;
  

  // Declare the NewOrder to be executed, should we meet criteria
  s_SCNewOrder NewOrder;
  NewOrder.OrderQuantity = 1;
  NewOrder.OrderType = SCT_ORDERTYPE_OCO_BUY_STOP_SELL_STOP;
  NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;

  NewOrder.AttachedOrderTarget1Type = SCT_ORDERTYPE_LIMIT;
  NewOrder.Target1Offset = Input_TargetTicks.GetInt()*sc.TickSize; // 20 ticks
  NewOrder.AttachedOrderStop1Type = SCT_ORDERTYPE_STOP;
  NewOrder.Stop1Offset = Input_StopTicks.GetInt()*sc.TickSize; // 30 tick stop



  if(IsLong && IsEntrySignal)
  {
    // We use the PreviewCrosses variable that just draws where we would have entries.
    // This is mainly just to help us debug
    if(Input_PreviewCrosses.GetYesNo()) {
      // Apply offset so the arrows don't draw on candles
      Subgraph_BuyEntry[sc.Index] = sc.Close[sc.Index] - Input_OffsetArrowDisplay.GetFloat();
    } else {
      int Result = (int)sc.SubmitOCOOrder(NewOrder);
      if (Result > 0)
      {
        //If there has been a successful order entry, then draw an arrow
        // Apply offset so the arrows don't draw on candles
        Subgraph_BuyEntry[sc.Index] = sc.Close[sc.Index] - Input_OffsetArrowDisplay.GetFloat();

        // Remember the order IDs for subsequent modification and cancellation
        // Target1OrderID = NewOrder.Target1InternalOrderID;
        // Stop1OrderID = NewOrder.Stop1InternalOrderID;
      } else {
        sc.AddMessageToLog("Long entry OCO failed!", 1);
      }
    }
  } else if(!IsLong && IsEntrySignal)
  {
    // We use the PreviuewCrosses variable that just draws where we would have entries.
    // This is mainly just to help us debug
    if(Input_PreviewCrosses.GetYesNo()) {
      // Apply offset so the arrows don't draw on candles
      Subgraph_SellEntry[sc.Index] = sc.Close[sc.Index] + Input_OffsetArrowDisplay.GetFloat();
    } else {
      int Result = (int)sc.SubmitOCOOrder(NewOrder);
      if (Result > 0)
      {
        //If there has been a successful order entry, then draw an arrow
        // Apply offset so the arrows don't draw on candles
        Subgraph_SellEntry[sc.Index] = sc.Close[sc.Index] + Input_OffsetArrowDisplay.GetFloat();
      } else {
        sc.AddMessageToLog("Short entry OCO failed!",1);
      }
    }
  }

[2020-07-17 07:43:16]
Sierra Chart Engineering - Posts: 104368
Refer to the section here:
Automated Trading From an Advanced Custom Study: Debugging/Troubleshooting Automated Trading Systems
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
[2020-07-17 08:21:55]
Marmany - Posts: 303
Hi, from a quick look at your code why us sc.SubmitOCOOrder?
When entering long you only need to use sc.BuyOrder. This will simultaneously place the entry order together with the stop and target as OCOs.
[2020-07-18 16:00:23]
User622324 - Posts: 4
Marmany,

Oh I was following a sample and presumed I needed to execute it as a OCO to get the limit target and stop order initiated.

So if I do buyorder or sellorder (as I go both directions at times), that should suffice?
[2020-07-19 11:03:55]
Marmany - Posts: 303
That is correct.
It looks like the example you worked from was for OCO orders to open a position, whereas you require them to exit.

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

Login

Login Page - Create Account