Support Board
Date/Time: Tue, 25 Mar 2025 21:04:57 +0000
[Programming Help] - Assistance Differentiating Open (Active PnL) vs. Closed (Finalized PnL) Orders in Simulati
View Count: 83
[2025-03-22 21:20:10] |
User329576 - Posts: 14 |
Hello, I am currently experiencing an issue during my trading simulation tests. In my ACSIL study, I send simulated orders that are immediately filled. However, I would like to clearly distinguish in the log between: Orders that remain “open” (i.e., those whose PnL is still fluctuating and are awaiting closure), and “Closed” orders (i.e., those that have been closed via a flat order or an opposing order of the same quantity and whose PnL is now finalized). In simulation, all orders are filled immediately, which causes the entry orders to appear as “closed” as soon as they are executed. Nevertheless, I would like to obtain an actionable indicator—either a function or constant within ACSIL—that allows me to directly identify whether an order is still “open” (with non-finalized PnL) or definitively closed. My goal is to avoid having to create my own flags or derivation conditions that could introduce errors or might not be robust enough to handle a high and rapid flow of different orders. This functionality would be very useful. Alternatively, please let me know if there is any method to achieve this within ACSIL. Please note that this issue concerns trading simulation tests only. I am seeking a reliable method that allows me to display in my logs, for example: “BUY Order pending closure” (when a buy order remains open with fluctuating PnL), “BUY Order closed” (when a flat order or an opposing order closes the position), and so on for other order types. Thank you in advance for your advice and recommendations. Sincerely, |
[2025-03-23 09:14:35] |
User431178 - Posts: 622 |
Is that not the purpose of the order status code, which is part of s_SCTradeOrder? Automated Trading From an Advanced Custom Study: Getting Order Information Date Time Of Last Edit: 2025-03-23 09:16:38
|
[2025-03-23 18:17:47] |
User329576 - Posts: 14 |
Real Mode vs. Simulation In real trading mode, once an order is executed, it remains in the order list with an OrderStatusCode indicating its state (for example, SCT_OSC_FILLED for a fully filled order, SCT_OSC_OPEN for an order still pending, etc.). In simulation mode, however, market orders are filled instantly, which means their OrderStatusCode is generally SCT_OSC_FILLED even though the position remains active (i.e., the PnL fluctuates). No Dedicated Built-In Function Based on my thorough research in the documentation, there is currently no built-in function or constant in ACSIL that uniquely distinguishes an order with a fluctuating PnL (an active position) from an order with a fixed PnL (orders offset by an opposite or flat order). This means that the API simply returns the order data as is: in simulation mode, all orders are filled immediately and their data indicates that they are “filled,” without any explicit marking to signify that an “open” order (in terms of PnL tracking) is still active. |
[2025-03-23 18:59:55] |
User431178 - Posts: 622 |
You are conflating orders and positions. Once an order is filled it is done, there is no such thing as an order with a fluctating PnL. Order to enter >>> Live position >>> Order to exit 1. You can query the active orders uisng sc.GetOrderByOrderID or sc.GetOrderByIndex. 2. You can query the fills using sc.GetOrderFillEntry. Between those two you can find the status of your orders. |
[2025-03-23 22:31:20] |
User329576 - Posts: 14 |
it's ok i use sc.GetTradePosition(PositionData) thank you !
|
To post a message in this thread, you need to log in with your Sierra Chart account: