Support Board
Date/Time: Sun, 02 Nov 2025 17:07:32 +0000
Post From: ASCIL use time and sales on multiple studies
| [2025-09-25 08:40:14] |
| User431178 - Posts: 805 |
|
You must be doing something wrong in your code. If you want help with it post it here or send message if you'd rather keep it private. The very basic study below pulls T&S data for up to 4 symbols simultaneously (the current chart and 3 others). It prints the last 3 records for each and repeats 10 times. If no T&S data is available for the symbol it subscribes to market data for that symbol. #include "sierrachart.h" #include <array> SCSFExport scsf_TimeAndSalesSymbols(SCStudyInterfaceRef sc) { if (sc.SetDefaults) { sc.GraphName = "T&S for Symbols"; sc.AutoLoop = 0; sc.GraphRegion = 0; sc.Input[0].Name = "Symbol #1"; sc.Input[0].SetSymbol(""); sc.Input[1].Name = "Symbol #2"; sc.Input[1].SetSymbol(""); sc.Input[2].Name = "Symbol #3"; sc.Input[2].SetSymbol(""); return; } auto& r_Count = sc.GetPersistentInt(0); if (sc.UpdateStartIndex == 0) r_Count = 0; if (r_Count >= 10) return; auto symbols = std::array<SCString, 4>{}; symbols[0] = sc.Symbol; symbols[1] = sc.Input[0].GetSymbol(); symbols[2] = sc.Input[1].GetSymbol(); symbols[3] = sc.Input[2].GetSymbol(); auto ts = c_SCTimeAndSalesArray{}; sc.GetTimeAndSales(ts); if (ts.Size() > 0) { for (auto i = ts.Size() - 1; i >= 0 && i >= ts.Size() - 3; --i) { const auto& record = ts[i]; auto msg = SCString{}; msg.Format("Symbol: %s, DateTime: %s, Price: %.2f, Volume: %u, Type: %d" , sc.Symbol.GetChars() , sc.FormatDateTime(record.DateTime).GetChars() , record.Price * sc.RealTimePriceMultiplier , record.Volume , record.Type); sc.AddMessageToLog(msg, 0); } } for (auto s = 1; s < symbols.size(); ++s) { if (symbols[s].GetLength() == 0) continue; auto tss = c_SCTimeAndSalesArray{}; sc.GetTimeAndSalesForSymbol(symbols[s], tss); if (tss.Size() > 0) { for (auto i = tss.Size() - 1; i >= 0 && i >= tss.Size() - 3; --i) { const auto& record = tss[i]; auto msg = SCString{}; msg.Format("Symbol: %s, DateTime: %s, Price: %.2f, Volume: %u, Type: %d" , symbols[s].GetChars() , sc.FormatDateTime(record.DateTime).GetChars() , record.Price * sc.RealTimePriceMultiplier , record.Volume , record.Type); sc.AddMessageToLog(msg, 0); } } else { auto msg = SCString{}; msg.Format("Symbol: %s, No T&S data, subscribing to symbol data feed", symbols[s].GetChars()); sc.AddMessageToLog(msg, 0); const auto val = sc.GetSymbolDataValue(SymbolDataValuesEnum::SYMBOL_DATA_LAST_TRADE_PRICE , symbols[s] , true , false); } } r_Count++; } |
