Support Board
Date/Time: Sun, 27 Apr 2025 20:38:38 +0000
Custom Study TOSSignalReaderV2 Fails with Error -8996 (Quantity 0)
View Count: 111
[2025-03-31 02:49:39] |
User936941 - Posts: 28 |
I’m using a custom study (TOSSignalReaderV2) to place a simulated short order via sc.SellEntry() for [Sim]MNQM25-CME. It consistently fails with error -8996 ("Order quantity is zero or invalid"), despite setting TradeQuantity to 1 in sc.SetDefaults and enforcing it in code. The log shows Order Details: Symbol=[Sim]MNQM25-CME, Qty=0, Type=0, TIF=0, and no position opens in the Trade Window. Relevant Log Snippet (21:38:20 CDT, March 30, 2025): 2025-03-30 21:38:20.516 | Chart: MNQM25-CME[M] 1 Min #1 | Study: TOS Signal Reader V2 | Initial position check for [Sim]MNQM25-CME (Chart Symbol: MNQM25-CME): Result=1, Position Quantity=0 2025-03-30 21:38:20.516 | Chart: MNQM25-CME[M] 1 Min #1 | Study: TOS Signal Reader V2 | Double-check position for [Sim]MNQM25-CME (Chart Symbol: MNQM25-CME): Result=1, Position Quantity=0 2025-03-30 21:38:20.516 | Chart: MNQM25-CME[M] 1 Min #1 | Study: TOS Signal Reader V2 | Failed to execute SellEntry for [Sim]MNQM25-CME, Error: -8996, Position Quantity=0 2025-03-30 21:38:20.516 | Chart: MNQM25-CME[M] 1 Min #1 | Study: TOS Signal Reader V2 | Failed to execute ShortSignalPlot for [Sim]MNQM25-CME, Error: -8996 2025-03-30 21:38:20.523 | Chart: MNQM25-CME[M] 1 Min #1 | Study: TOS Signal Reader V2 | Updated LastProcessedTimestampIndex to 45746.000000 and cleared trade_signals.txt 2025-03-30 21:38:20.523 | Chart: MNQM25-CME[M] 1 Min #1 | Study: TOS Signal Reader V2 | Finished reading trade_signals.txt 2025-03-30 21:38:20.670 | Chart: MNQM25-CME[M] 1 Min #1 | Study: TOS Signal Reader V2 | Update interval not reached, skipping | Number times message added: 4 2025-03-30 21:38:25.067 | Chart: MNQM25-CME[M] 1 Min #1 | Study: TOS Signal Reader V2 | Time difference: 5.000000 seconds 2025-03-30 21:38:25.067 | Chart: MNQM25-CME[M] 1 Min #1 | Study: TOS Signal Reader V2 | Attempting to open trade_signals.txt 2025-03-30 21:38:25.067 | Chart: MNQM25-CME[M] 1 Min #1 | Study: TOS Signal Reader V2 | Successfully opened trade_signals.txt 2025-03-30 21:38:25.073 | Chart: MNQM25-CME[M] 1 Min #1 | Study: TOS Signal Reader V2 | Finished reading trade_signals.txt Steps Tried: Forced newOrder.OrderQuantity = 1 at startup, pre-signal, and final assignment (tradeQty > 0 ? tradeQty : 1). Renamed DLL to TOSSignalReaderV2.dll, rebuilt via Remote Build, deleted old DLLs, and restarted Sierra Chart. Reset Study Settings, manually set Trade Quantity to 1, confirmed Send Orders to Trade Service = No (simulation). Added detailed logging (Order Details) to verify parameters—still shows Qty=0. Attachments: TOSSignalReader.cpp source code. Screenshot of Study Settings (Trade Quantity = 1, Send Orders to Trade Service = No). Request: Why is TradeQuantity.GetInt() returning 0 despite being set to 1 in code and Study Settings? Is a Sierra Chart configuration overriding this? Please check the Trade Service Log for additional clues (I’ll attach it if needed). |
![]() ![]() |
[2025-03-31 04:23:24] |
Sierra_Chart Engineering - Posts: 19355 |
The order quantity has to be set through this member of the new order structure: s_SCNewOrder.OrderQuantity
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 |
[2025-03-31 07:45:09] |
User431178 - Posts: 656 |
1. Your logging messages are wrong. // Detailed order logging before execution LogMessage.Format("Order Details: Symbol=%s, Qty=%d, Type=%d, TIF=%d", newOrder.Symbol.GetChars(), newOrder.OrderQuantity, newOrder.OrderType, newOrder.TimeInForce); newOrder.OrderQuantity is type double not int, Qty=%f would be needed not %d. LogMessage.Format("Initial position check for %s (Chart Symbol: %s): Result=%d, Position Quantity=%d", adjustedSymbol.GetChars(), chartSymbol.GetChars(), positionResult, position.PositionQuantity); position.PositionQuantity is type double not int, Position Quantity=%f would be needed not %d. 2025-03-30 21:38:20.516 | Chart: MNQM25-CME[M] 1 Min #1 | Study: TOS Signal Reader V2 | Failed to execute ShortSignalPlot for [Sim]MNQM25-CME, Error: -8996 2. Error -8996 means you specified an invalid index when using sc.SellEntry and/or sc.SellExit. This is wrong result = sc.SellEntry(newOrder, SendOrdersToTradeService.GetYesNo()); as is this result = sc.SellExit(newOrder, SendOrdersToTradeService.GetYesNo()); SendOrdersToTradeService.GetYesNo() has no place in that function call, it should be a bar index. Here are the doc links for order entry/exit: Automated Trading From an Advanced Custom Study: Submitting and Modifying An Order Through the Advanced Custom Study Interface You could save yourself some time by looking at the trading system examples in sierrachart/ACS_Source/tradingsystem.cpp, that would give you some clues as to where you are going wrong. |
To post a message in this thread, you need to log in with your Sierra Chart account: