Login Page - Create Account

Support Board


Date/Time: Sat, 22 Feb 2025 03:13:44 +0000



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

View Count: 124

[2025-02-19 17:57:13]
LTSys - Posts: 42
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-21 19:51:50
[2025-02-19 18:23:38]
cmet - Posts: 640
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]
LTSys - Posts: 42
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
[2025-02-21 19:46:40]
LTSys - Posts: 42
UPDATE: I'm back to square one... today I noticed the "sc.GetOrderForSymbolAndAccountByIndex(...)" function will all of a sudden just stop looping through market orders that are only a few seconds old. If I play around with the chart update interval setting the orders will start looping again but that solution only seems to work for a while. Anyone have any possible ideas why that is happening? Perhaps some flag that needs to be set in the default section of the study?

TIA
Date Time Of Last Edit: 2025-02-21 19:56:27

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

Login

Login Page - Create Account