Support Board
Date/Time: Tue, 15 Apr 2025 14:21:34 +0000
Creating a Custom Trade Log
View Count: 92
[2025-03-29 18:30:14] |
User352984 - Posts: 2 |
Looking for assistance with development. From what I gather, you can not add columns to the current trade log system that comes with Sierra Chart. An example of one of the data points I'm looking to capture at the time of order/fill is CCI. I have many data points I want to capture but if I can get this working with CCI I am confident I can get it to work with the rest. I'm an amateur/not very good coder. I have the compiler working with visual studio and using ChatGPT to help. Any input or guidance is most appreciated: If anyone enjoys teaching I'm open to paying for your time as well. =========================================================== #include "sierrachart.h" SCDLLName("Custom Trade Logger") // Custom Trade Logging Study SCSFExport scsf_CustomTradeLogger(SCStudyInterfaceRef sc) { if (sc.SetDefaults) { sc.GraphName = "Custom Trade Logger"; sc.StudyDescription = "Logs trade details to a CSV file."; sc.AutoLoop = 0; // Disable auto-loop, we only log trades when they occur return; } // Define the file path SCString filePath = sc.DataFilePathAndName("RyanTradeLog.csv"); // Check if the file is empty, and if so, add a header row if (!sc.FileExists(filePath)) { SCString header = "Time, Price, Quantity, OrderType, Symbol, CCI\n"; sc.AppendTextToFile(filePath, header); } // Retrieve the most recent filled trade s_SCTradeOrder tradeOrder; int tradeIndex = sc.GetTradeOrderListSize() - 1; // Get the last trade index if (tradeIndex >= 0 && sc.GetOrderByIndex(tradeIndex, tradeOrder)) { if (tradeOrder.OrderStatusCode == SCT_OSC_FILLED) // Only log filled orders { // Get CCI Study ID int CCI_StudyID = 7; // match your CCI study ID int CCI_SubgraphIndex = 1; // Usually 0 for main output of a study SCFloatArray CCI_Array; // Get CCI values from the study sc.GetStudyArrayUsingID(CCI_StudyID, CCI_SubgraphIndex, CCI_Array); // Find the CCI value at the time of order execution int Index = sc.GetNearestMatchForSCDateTime(sc.ChartNumber, tradeOrder.OrderFilledTime); float CCI_Value = (Index >= 0) ? CCI_Array[Index] : 0.0f; // Get the closest CCI value SCString logEntry; logEntry.Format("%s, %.2f, %d, %s, %s\n", tradeOrder.OrderFilledTime.Format("%Y-%m-%d %H:%M:%S"), // Time tradeOrder.AvgFillPrice, // Price tradeOrder.Quantity, // Quantity tradeOrder.OrderTypeText, // Order Type sc.Symbol.GetChars() // Symbol CCI_Value // CCI value at trade execution ); // Append trade log entry to file sc.AppendTextToFile(filePath, logEntry); } } } |
[2025-03-29 21:20:01] |
ForgivingComputers.com - Posts: 1040 |
You can use: NewOrder.TextTag = String;
Where the String variable can be whatever you want. These appear as the Note column on the Trade Activity Log. Automated Trading From an Advanced Custom Study: [Type: SCString] s_SCNewOrder::TextTag I would be happy to give you ACSIL lessons. Brad@ForgivingComputers.com |
To post a message in this thread, you need to log in with your Sierra Chart account: