Login Page - Create Account

Support Board


Date/Time: Fri, 21 Feb 2025 09:15:42 +0000



[Programming Help] - [Programming Help] Issues trying to to read all orders on each study interval.

View Count: 91

[2025-02-19 17:57:13]
LTSystems - Posts: 38
Hi, I'm having issues reading all orders each time a study function is called.

If I place some orders and start the study the code below can see the orders, but only once on the first call to the study function. If I place a new order while the study is running, the code doesn't see the newly added order?

The following study code is called every second when enabled on a chart. I expected it to print all the orders as they are placed but it doesn't. It only prints the orders on the first startup call to the function. I'm I missing some extra step?

TIA


SCSFExport scsf_TradeCopierFunction(SCStudyInterfaceRef sc) {

int orderIndex = 0;

while(true) {

s_SCTradeOrder order;

if(sc.GetOrderForSymbolAndAccountByIndex(EMPTY_STRING, tradeAccount, orderIndex, order) < 0)
break;
    
orderIndex++;

// code that prints details about each order
}
}

Date Time Of Last Edit: 2025-02-19 18:05:52
[2025-02-19 18:23:38]
cmet - Posts: 639
Try adding sc.UpdateAlways = 1; and using sc.GetOrderByIndex() instead.

Something like this:

SCSFExport scsf_TradeCopierFunction(SCStudyInterfaceRef sc)
{
sc.AutoLoop = 0;
sc.UpdateAlways = 1;

int orderIndex = 0;

while (true)
{
s_SCTradeOrder order;

//next order
if (sc.GetOrderByIndex(orderIndex, order) == 0)
{
break;
}

//order info
SCString msg;
msg.Format("Order #%d | Account: %s | Symbol: %s | Qty: %d | Type: %d | Status: %d | Price: %.2f",
orderIndex, order.TradeAccount.GetChars(), order.Symbol.GetChars(), order.Quantity,
order.OrderType, order.OrderStatusCode, order.Price1);
sc.AddMessageToLog(msg, 1);

orderIndex++;
}
}

Date Time Of Last Edit: 2025-02-19 19:17:28
[2025-02-19 20:39:50]
LTSystems - Posts: 38
and using sc.GetOrderByIndex() instead

That works great but it only get orders for the symbol on the chart. For example I have 2 orders open: EURUSD and BTCUSD... the study is on the EURUSD chart and only orders happening for EURUSD are being seen by the code.

UPDATE: I just rebuilt everything and restarted SierraChart and changed my original code...


SCSFExport scsf_TradeCopierFunction(SCStudyInterfaceRef sc) {

int orderIndex = 0;

while(true) {

s_SCTradeOrder order;

if(sc.GetOrderForSymbolAndAccountByIndex(EMPTY_STRING, tradeAccount, orderIndex, order) < 0)
break;

orderIndex++;

// code that prints details about each order
}
}

to use this from your example...

while(sc.GetOrderForSymbolAndAccountByIndex(EMPTY_STRING, tradeAccount, orderIndex, order) != SCTRADING_ORDER_ERROR)

and now it works... I get all order actions for all symbols on one chart.

Thanks
Date Time Of Last Edit: 2025-02-19 20:52:14

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account