Support Board
Date/Time: Fri, 27 Dec 2024 04:52:44 +0000
Post From: ACSIL OrderStatusCode == SCT_OSC_OPEN not valid for manual market orders
[2024-10-25 19:33:27] |
User321619 - Posts: 26 |
Hello, Currently, trying to write a custom study. This condition if (order.OrderStatusCode == SCT_OSC_OPEN ) is true for manually placed buy limit and sell limit orders. However, this condition is not true for manually placed *market* orders. Basically, in this study, I would place orders manually and then exit based on certain conditions using study. I have trimmed down the code here. As I mentioned, above condition does not return true for manually placed market orders. So activeOrderFound and orderDirection log messages are never printed for manual *market* orders. What am I missing? Please suggest. Also, while we are at it. Should I also check IsWorkingOrderStatus(order.OrderStatusCode) to make sure it is working/active order. And order.ParentInternalOrderID == 0, to make sure it is main order and not stop loss or take profit. Thanks so much for looking in to this. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5 #include "sierrachart.h"
SCDLLName("Flatten Position Based on EMAs for Active Manual Orders") SCSFExport scsf_FlattenManualOrderOnEMACross(SCStudyInterfaceRef sc) { // Define persistent arrays for EMA calculation SCFloatArray EMA5, EMA8; SCString logMessage; if (sc.SetDefaults) { sc.GraphName = "Flatten Position on EMA Crossover for Manual Orders"; // Set this study to run on every tick sc.AutoLoop = 0; // Disable AutoLoop sc.UpdateAlways = 1; // Ensure function is evaluated on every tick // Disable sending orders to trade service sc.SendOrdersToTradeService = 0; return; } // Only execute on new data to prevent repeated execution on the same tick if (sc.Index < sc.ArraySize - 1) return; // Calculate EMAs only once per tick for efficiency sc.ExponentialMovAvg(sc.BaseData[SC_LAST], EMA5, sc.Input[0].GetInt()); sc.ExponentialMovAvg(sc.BaseData[SC_LAST], EMA8, sc.Input[1].GetInt()); // Loop through orders to find an active manual parent order, limited to 100 orders for performance s_SCTradeOrder order; int activeOrderFound = 0; int orderDirection = 0; // 1 for Buy, -1 for Sell const int maxOrdersToCheck = 100; int orderIndex = 0; while (orderIndex < maxOrdersToCheck && sc.GetOrderByIndex(orderIndex, order) != 0) { // Check for an active, working, parent order (excluding stop or target orders) //&& IsWorkingOrderStatus(order.OrderStatusCode) //&& order.ParentInternalOrderID == 0 if (order.OrderStatusCode == SCT_OSC_OPEN ) { activeOrderFound = 1; logMessage.Format("activeOrderFound:%d",activeOrderFound); sc.AddMessageToLog(logMessage,1); logMessage.Format("orderDirection:%d", order.BuySell); sc.AddMessageToLog(logMessage,1); orderDirection = (order.BuySell == BSE_BUY) ? 1 : -1; break; // Exit once an active parent order is found } orderIndex++; } } Date Time Of Last Edit: 2024-10-26 07:03:58
|