Support Board
Date/Time: Fri, 27 Jun 2025 21:24:17 +0000
[Programming Help] - OCO orders still showing after a filled sell order is bought using ACSIL
View Count: 554
[2021-09-21 05:31:58] |
User133994 - Posts: 81 |
Support, I am trying to scale out of a 4 contract position. I'm using ACSIL with all the settings for Unmanaged Automated trading and have succeeded in entering a position with 4 contracts (sell entries) each with their own OCO groups (4 total). When I get to a price when I'm ready to *exit* the 1st contract (i.e. only flatten 1 of the 4) I tried moving the OCO group to a nearby price so that it would convert to a market order and flatten only the 1 contract...but that didn't work. This is a situation when the OCO group didn't trigger, but I need to get out of 1 contract "now." Then I tried several other things--including manually "buying" one contract from the chart. And that didn't work until I changed the quantity to 1 on the chart that the ACSIL Trading study was attached to. After much effort (I'm still confused as to how many orders I should see and positions (via ACSIL variables): simple math is 4 initially then 3...but I'm seeing 1 and 0 and 13...etc.) I finally got it to do what I want...but in an unconventional method> I simply did a sc.buyentry (SC_ordertype_market) and that action got me down to 3; however, the Trade Orders Window still showed the 1st sell entry as "open" even though the trade window chart position was reduced to 3? So the Trade Orders window also still had the OCO group 1 still active even though there were really only 3 open sell positions (with their 3 OCO groups). And, after all positions were "flat" the OCO group 1 was still "working" on the Trade Orders window... Please let me know the correct way to do this...it seems I've discovered a way to accomplish what I want..but I don't think it is using the code properly because the Trade Orders window isn't displaying as expected and the OCO group 1 isn't being cancelled automatically as expected. Would you please provide an example Trading System that uses a "market" order to flatten only 1 out of 4+ existing open contracts or maybe an ACSIL "flatten only 1 contract" function (when there 4 or more open contracts) that would be wonderful. I need to be able to use OCO groups as well...so this would be a separate override ACSIL function that operates similarly to the "flatten" button on the trade window, but only affects 1 contract at a time ( or more) of a larger total # of open positions. Put another way...if I could do a "modify order" function that immediately changes the current open "filled" position so that it exits at current market value and cancels its associated OCO group. But, I know modify only works on "working" orders...not filled orders. Please let me know. Please help. Thanks in advance. Date Time Of Last Edit: 2021-09-21 05:33:24
|
[2021-09-21 15:11:21] |
ForgivingComputers.com - Posts: 1071 |
I finally got it to do what I want...but in an unconventional method> I simply did a sc.buyentry (SC_ordertype_market) and that action got me down to 3; however, the Trade Orders Window still showed the 1st sell entry as "open" even though the trade window chart position was reduced to 3?
When the orders are filled, save the parent order IDs for each as persistent variables. Then when it is time to exit one of them: NewOrder.InternalOrderID = ParentOrderID1;
// Use sc.SellExit for sc.SellEntry orders, and sc.BuyExit for sc.BuyEntry orders sc.SellExit(NewOrder); When the Exit order fills, the OCO orders for that trade will be canceled and you will be left with 3 sets of orders. |
[2021-09-22 17:58:26] |
User133994 - Posts: 81 |
Support, Thanks for the idea. It didn't quite work, but led me to a solution. Paradigm: a) 1 trade with 4 orders and 4 OCO groups vs b) 4 trades with 1 OCO group each Your solution works for the b) paradigm. I need the a) paradigm to work...so I discovered I needed to go ahead with this: 1) use the sc.BuyOrder() to exit my sell 2) manually cancel the associated OCO group orders: sc.CancelOrder(Target1OrderID), sc.CancelOrder(Stop1OrderID) That allowed for the other 3 open positions with their OCO groups to remain active and working--while I "manually" exited 1 position. If I am using these functions in a manner that wasn't intended please let me know. Just because it works doesn't mean it is "correct" or the appropriate way to do something. Thanks for thinking through this with me. If there is a better way please let me know--I'm all about efficiency. |
[2021-09-22 19:03:44] |
ForgivingComputers.com - Posts: 1071 |
I am not "Support", just a fellow ACSIL developer. Whatever works for you.
|
[2021-09-22 19:48:29] |
User133994 - Posts: 81 |
Bradh--many thanks! Apologies for the misspeak. Thanks again for your assistance.
|
To post a message in this thread, you need to log in with your Sierra Chart account: