Support Board
Date/Time: Mon, 03 Feb 2025 00:58:22 +0000
[Programming Help] - How to get ClosedProfitLoss of an order. in ACSIL, given the InternalOrderID
View Count: 1056
[2019-10-20 03:19:54] |
User272786 - Posts: 13 |
Dear Support, GetOrderByIndex(s_SCTradeOrder) => s_SCTradeOrder does not have ClosedProfitLoss values. GetTradeListEntry(s_ACSTrade) => has s_ACSTrade.ClosedProfitLoss values, but can not be searched for the order using InternalOrderID. I tried a work around using s_ACSTrade.OpenDateTime to find the order, as from GetOrderByOrderID(s_SCTradeOrder), we can access s_SCTradeOrder.EntryDateTime when a new order was created. Used something like s_ACSTrade.OpenDateTime.GetTimeWithoutMilliseconds() == s_SCTradeOrder.EntryDateTime.GetTimeWithoutMilliseconds() this, sometimes does not work, as it seems sometimes the TimeStamp differs a bit when an order is fillted.It would have worked if that comaprison worked at millisecond level, as it would most probably be unique accross orders for most of the requirements. What am I missing here? What is the easiest way to get ClosedProfitLoss of an order, when it's InternalOrderID is known? Thanks Date Time Of Last Edit: 2019-10-20 03:55:45
|
[2019-10-20 13:03:21] |
ForgivingComputers.com - Posts: 994 |
s_SCTradeOrder TradeOrderData; int Result = sc.GetOrderByOrderID(InternalOrderID, TradeOrderData); int OrderStatusCode = TradeOrderData.OrderStatusCode; if (OrderStatusCode == SCT_OSC_FILLED) { // The order has completely filled double FillPrice = TradeOrderData.LastFillPrice; } |
[2019-10-21 01:44:00] |
User272786 - Posts: 13 |
Thanks for that. Your reply helped me to refine my work-around I mentioned on my original post and solved the issue! So the steps: 1) Keep the InternalOrderID (say orderID) when an order is created. The order s_SCTradeOrder::EntryDateTime will differ from the later updated s_SCOrderFillData::FillDateTime.2) Use sc.GetOrderFillEntry(fillIndex, s_SCOrderFillData) to get s_SCOrderFillData::FillDateTime, using: if (s_SCOrderFillData.InternalOrderID == orderID)
3) Use sc.GetTradeListEntry(Index, s_ACSTrade) to get s_ACSTrade::OpenDateTime4) Choose the required Trade using: if (s_ACSTrade::OpenDateTime.IsSameTimeToMilliSecond(s_SCOrderFillData::FillDateTime))
5) Read s_ACSTrade::ClosedProfitLossSo basically, I am using s_SCOrderFillData::FillDateTime as the key|link, as this value is unique, for most purposes, if considered to the millisecond.If you know a better way and can use InternalOrderID to query Trade data directly, please let us know, thanks. Date Time Of Last Edit: 2019-10-21 02:42:32
|
[2019-10-21 02:08:49] |
ForgivingComputers.com - Posts: 994 |
If you know a better way and can use InternalOrderID to query Trade data directly, please let us know, thanks.
I suppose you can get there the way you describe, but it all you are looking for is the price, date, and time the order was filled, those are part of the TradeOrder structure. You can use TradeOrderData.LastActivityTime (Automated Trading From an Advanced Custom Study: [Type: SCDateTime] LastActivityTime). You declare an SCDateTime variable and assign it like this: SCDateTime FillTime = TradeOrderData.LastActivityTime
So the new code snippet would look like this: s_SCTradeOrder TradeOrderData; int Result = sc.GetOrderByOrderID(InternalOrderID, TradeOrderData); int OrderStatusCode = TradeOrderData.OrderStatusCode; if (OrderStatusCode == SCT_OSC_FILLED) { // The order has completely filled double FillPrice = TradeOrderData.LastFillPrice; SCDateTime FillTime = TradeOrderData.LastActivityTime } I haven't worked with millisecond timing, but I think you can substitute SCDateTimeMS for SCDateTime above and get ms results. |
[2019-10-21 02:34:31] |
User272786 - Posts: 13 |
I was only trying to get ClosedProfitLoss of an order, when it's InternalOrderId, at the creation of the order is known.
|
To post a message in this thread, you need to log in with your Sierra Chart account: