Support Board
Date/Time: Fri, 14 Mar 2025 15:18:24 +0000
[Programming Help] - Entry order submission failed. BuyEntry returned: -1
View Count: 283
[2024-12-26 23:02:32] |
User425576 - Posts: 16 |
Can anyone add any assistance in troubleshooting this error? The code should be getting OrderQuantity from the TraderWindow, which returns as 0, although the TraderWindow is set to 1 contract. Previously, we had issues with it being set to anything other than 1, 2 and above, which would cause the entry to fail. When it was working the quantity returned 0 also, yet it would still execute the trade in Sim mode. My entry code: int HMA11_CA_HMA21 = sc.CrossOver(HMA11, HMA21); // Long Entry Logic if (!signalExecuted && PositionData.PositionQuantity == 0 && // Ensure no current position HMA11_CA_HMA21 == CROSS_FROM_BOTTOM && // Use the correct crossover condition for entry HMA_D_T) // Check if HMA distance conditions are met { // Log the entry conditions sc.AddMessageToLog("Entry conditions met. Preparing to submit entry order.", 1); // Create a market order to enter a new long position s_SCNewOrder NewEntryOrder; // Set the order quantity directly from the trade window NewEntryOrder.OrderQuantity = sc.TradeWindowOrderQuantity; //log order quantity SCString orderQuantityLog; orderQuantityLog.Format("Order quantity set to: %d", sc.TradeWindowOrderQuantity); sc.AddMessageToLog(orderQuantityLog, 1); // Define the order type and time in force NewEntryOrder.OrderType = sc.GetTradeWindowOrderType(); NewEntryOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED; // Log the order details SCString entryOrderDetails; entryOrderDetails.Format("Entry order details: OrderType=%d, OrderQuantity=%d, TimeInForce=%d", NewEntryOrder.OrderType, NewEntryOrder.OrderQuantity, NewEntryOrder.TimeInForce); sc.AddMessageToLog(entryOrderDetails, 1); // Submit Buy Entry Order int EntryOrderID = static_cast<int>(sc.BuyEntry(NewEntryOrder)); // Check if order submission was successful if (EntryOrderID > 0) { signalExecuted = true; SCString message; message.Format("Entry order submitted successfully. Order ID: %d", EntryOrderID); sc.AddMessageToLog(message, 1); } else { SCString failureMessage; failureMessage.Format("Entry order submission failed. BuyEntry returned: %d", EntryOrderID); sc.AddMessageToLog(failureMessage, 1); } } Message Log: 2024-12-26 14:37:02.663 | Chart: Replay 5.00X: NQH5.CME [C] 2.50 Range | Study: HMACross_2_1ChartTrader | HMA distance checks are disabled. 2024-12-26 14:37:02.663 | Chart: Replay 5.00X: NQH5.CME [C] 2.50 Range | Study: HMACross_2_1ChartTrader | Position Quantity: 0, Position Average Price: 0.00, Position Profit/Loss: 0.00 2024-12-26 14:37:02.663 | Chart: Replay 5.00X: NQH5.CME [C] 2.50 Range | Study: HMACross_2_1ChartTrader | Entry conditions met. Preparing to submit entry order. 2024-12-26 14:37:02.663 | Chart: Replay 5.00X: NQH5.CME [C] 2.50 Range | Study: HMACross_2_1ChartTrader | Order quantity set to: 0 2024-12-26 14:37:02.663 | Chart: Replay 5.00X: NQH5.CME [C] 2.50 Range | Study: HMACross_2_1ChartTrader | Entry order details: OrderType=32, OrderQuantity=0, TimeInForce=1 2024-12-26 14:37:02.663 | Chart: Replay 5.00X: NQH5.CME [C] 2.50 Range | Study: HMACross_2_1ChartTrader | Entry order submission failed. BuyEntry returned: -1 Date Time Of Last Edit: 2024-12-27 03:25:47
|
[2024-12-27 11:07:47] |
User431178 - Posts: 613 |
As you said it will execute in sim mode, I would ask what is sc.SendOrdersToTradeService set to in your code? Automated Trading Management: SendOrdersToTradeService Automated Trading From an Advanced Custom Study: Going from Simulation Mode to Live Trading sc.SendOrdersToTradeService = sc.GlobalTradeSimulationIsOn ? 0 : 1; |
[2024-12-27 15:42:13] |
Sierra_Chart Engineering - Posts: 18784 |
A trading error of -1 equals SCTRADING_ORDER_ERROR: "General order error. Refer to 'Trade >> Trade Service Log' for specific message for this trading action error"; 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, use the Teton service: Sierra Chart Teton Futures Order Routing Date Time Of Last Edit: 2024-12-27 15:42:32
|
[2024-12-27 18:39:33] |
User425576 - Posts: 16 |
@User431178, I am not getting executions in sim mode either, this is why I asked the question. I did have it working in sim mode but now it has halted. // Trade Management Settings
sc.AllowMultipleEntriesInSameDirection = false; sc.MaximumPositionAllowed = 1; // Only one position at a time sc.SupportReversals = true; sc.SendOrdersToTradeService = false; // Use simulation system sc.AllowOppositeEntryWithOpposingPositionOrOrders = false; sc.SupportAttachedOrdersForTrading = true; // Enable attached orders sc.CancelAllOrdersOnEntriesAndReversals = true; sc.AllowEntryWithWorkingOrders = false; sc.CancelAllWorkingOrdersOnExit = true; sc.AllowOnlyOneTradePerBar = true; sc.MaintainTradeStatisticsAndTradesData = true; return; This is what I am using currently and I also uploaded the cpp file for any interested in taking a look. |
![]() |
[2024-12-27 18:41:46] |
User425576 - Posts: 16 |
I just set the Programming Help on the thread. Thanks everyone! |
[2024-12-27 19:19:09] |
User425576 - Posts: 16 |
Oh my, I can not believe that the "AutoTrading Enabled - Chart" was not enabled, and now I am getting the executions... How that got turned off is a mystery to me, but it cost me a lot of time... Oysh! That one hurt! |
[2024-12-29 01:04:52] |
User142482 - Posts: 2 |
Programming ASCIL Hello, In programming ASCIL, is a way of having study syntax and Systems syntax in as a single file for possible execution on chart. Example, a call procedure of a study indicator like the RSI into a System file that consist of "entry", buy/ sell , exit, Profit codes all in one cpp file ?. |
[2024-12-29 02:05:21] |
Sierra_Chart Engineering - Posts: 18784 |
Yes this makes sense in regards to post #7. For examples, refer to: Automated Trading From an Advanced Custom Study: Example Trading Systems and Code 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, use 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: