Login Page - Create Account

Support Board


Date/Time: Sat, 11 May 2024 08:48:37 +0000



[Programming Help] - Automated Trading question on multiple orders

View Count: 570

[2020-10-13 02:58:32]
TriStar Trading - Posts: 116
Hey! Any help would be appreciated. I am writing an order entry control bar with buttons. I have the following code for a Buy Market order:

      s_SCNewOrder EntryOrder;
      EntryOrder.OrderQuantity = OrderQuantity;
      EntryOrder.OrderType = SCT_ORDERTYPE_MARKET;
      EntryOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;
      
      //Specify a Target and a Stop. Specifying one Target and one Stop, additional targets and stops can be specified.
      EntryOrder.Target1Offset = (SwingHighPrice - sc.Close[sc.Index]) + (TargetTicksOffset.GetFloat() * sc.TickSize);
      EntryOrder.Stop1Offset = (sc.Close[sc.Index] - SwingLowPrice) + (StopTicksOffset.GetFloat() * sc.TickSize);
      //EntryOrder.OCOGroup1Quantity = OrderQuantity; // If this is left at the default of 0, then it will be automatically set.
      
      int EntryResult = (int)sc.BuyEntry(EntryOrder);
      if (EntryResult < 0) //Order entry failed
      {
        sc.AddMessageToTradeServiceLog(sc.GetTradingErrorTextMessage(EntryResult), false, true);  
      }
The problem I am having is this. I enter an order for one contract. When I enter a second order for one contract, the position amount updates to two orders at the average price, but the target a stop orders do not seem to trigger for the second order. The quantities remain the same on the original stop and target orders, and alternatively no new stop and target orders are triggered.

Thanks in advance!

Mike
[2020-10-13 04:57:54]
TriStar Trading - Posts: 116
I'm thinking I need to track the target and stop internal order id's and do an update order?
[2020-10-13 14:08:35]
bradh - Posts: 854
I'm thinking I need to track the target and stop internal order id's and do an update order?

You could do that if you want them all to have the same stop and target, but I think there is something else going on that prevents the second attached orders from being submitted.
[2020-10-13 16:20:15]
TriStar Trading - Posts: 116
Thanks bradh. I'm thinking the same as you on why is the second order not triggering the associated target and stop orders. I would rather have the stop and target orders be separate if possible. They would have the same price level as the original stop and target orders as I am using the swing high and swing low as the default price levels for the stop and target. I have wrotten a fair amount of ACSIL but this is my first attempt at sending orders. Always an adventure. :)

Thanks again!

Mike
[2020-10-13 18:44:59]
User99735 - Posts: 234
Hi,
Please check if the second Stop/Target orders are appearing in the Trade List table/window. If not, the orders are not open, any error message logged in the Trade Service log?

Regards

Vivek
[2020-10-14 04:07:38]
TriStar Trading - Posts: 116
Hey Vivek! Thanks so much for suggesting the trade list window. The original stop and target orders were getting canceled on the new entry. Found out I had a default setting wrong. I had sc.CancelAllOrdersOnEntriesAndReversals set to true. Changed that to false and bingo! Kudos my new friend! Virtual beers for you. :)

Thanks again!

Mike

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

Login

Login Page - Create Account