Login Page - Create Account

Support Board


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



Post From: ACSIL and Executing OCO Fails

[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);
      }
    }
  }