Support Board
Date/Time: Wed, 30 Apr 2025 07:43:16 +0000
[Programming Help] - I have a programming question(Futures Foot print - Number Bars Calculated Values)
View Count: 42
[2025-04-22 14:32:49] |
Stefan Alexandru Ilie - Posts: 4 |
I would like to be able to extract the Delta , Delta Chg, Max Delta, and Min Delta into a text file -> from the Study Number Bars Calculated Values. The code, that i am using is below: #include "sierrachart.h" #include <fstream> #include <iomanip> SCDLLName("02_Export_Delta_Data") SCSFExport scsf_ExportDeltaData(SCStudyInterfaceRef sc) { SCInputRef ExportInterval = sc.Input[0]; SCInputRef NumbersBarsStudyID = sc.Input[1]; if (sc.SetDefaults) { sc.GraphName = "02_Export_Delta_Data"; sc.StudyDescription = "Exports Delta from Numbers Bars Calculated Values study."; sc.AutoLoop = 0; ExportInterval.Name = "Export Interval (seconds)"; ExportInterval.SetInt(5); // Default every 5 seconds NumbersBarsStudyID.Name = "Numbers Bars Calculated Values Study ID"; NumbersBarsStudyID.SetInt(1); // Update as needed for your chart return; } int& LastExportTime = sc.GetPersistentInt(1); int now = sc.GetCurrentDateTime().GetTimeInSeconds(); if (now - LastExportTime < ExportInterval.GetInt()) return; LastExportTime = now; // Get symbol and last price SCString symbol = sc.Symbol; float lastPrice = sc.Close[sc.ArraySize - 1]; // Adjust time +3 hours (in days) SCDateTime currentDateTime = sc.GetCurrentDateTime(); currentDateTime += (3.0 / 24.0); // 3 hours // Format datetime SCString dateTimeStr; dateTimeStr.Format("%04d-%02d-%02d %02d:%02d:%02d.%03d", currentDateTime.GetYear(), currentDateTime.GetMonth(), currentDateTime.GetDay(), currentDateTime.GetHour(), currentDateTime.GetMinute(), currentDateTime.GetSecond(), currentDateTime.GetMillisecond()); // Clean up symbol description (remove spaces) SCString symbolDescription; sc.GetSymbolDescription(symbolDescription); SCString cleanDesc; for (int i = 0; i < symbolDescription.GetLength(); ++i) { if (symbolDescription != ' ') cleanDesc.Append(symbolDescription); } // Define file path SCString filePath = "C:\\Users\\user\\AppData\\Roaming\\MetaQuotes\\Terminal\\9EF5A5A6EDAA68A3816FEBEE8F574F8B\\MQL5\\Files\\F.US.EU6M25_02_DeltaExport.txt"; // Open file for appending std::ofstream file(filePath.GetChars(), std::ios::app); // Write header (only once, or you can control it differently if needed) static bool headerWritten = false; if (!headerWritten) { file << std::setw(23) << std::left << "DateTime" << "|" << std::setw(15) << std::left << "Symbol" << "|" << std::setw(30) << std::left << "SymbolDescription" << "|" << std::setw(12) << std::left << "LastPrice" << "|" << std::setw(12) << std::left << "BidVolume" << "|" << std::setw(12) << std::left << "AskVolume" << "|" << std::setw(12) << std::left << "Delta" << "\n"; headerWritten = true; } // Access arrays from Numbers Bars Calculated Values study int studyID = NumbersBarsStudyID.GetInt(); int chartNumber = 1; int subgraphIndexDelta = 2; SCFloatArray deltaArray; sc.GetStudyArrayFromChartUsingID(chartNumber, studyID, subgraphIndexDelta, deltaArray); // Volume and delta double BidVolume = 0.0; double AskVolume = 0.0; float delta = 0.0; // Try finding the most recent valid profile n_ACSIL::s_StudyProfileInformation ProfileInfo; const int maxProfilesToCheck = 10; bool profileFound = false; for (int i = 0; i < maxProfilesToCheck; ++i) { if (sc.GetStudyProfileInformation(studyID, i, ProfileInfo) == 1) { profileFound = true; BidVolume = ProfileInfo.m_BidVolume; AskVolume = ProfileInfo.m_AskVolume; delta = static_cast<float>(AskVolume - BidVolume); break; } } if (!profileFound && sc.ArraySize > 1) { delta = deltaArray[sc.ArraySize - 2]; } // Write data file << std::setw(23) << std::left << dateTimeStr.GetChars() << "|" << std::setw(15) << std::left << symbol.GetChars() << "|" << std::setw(30) << std::left << cleanDesc.GetChars() << "|" << std::setw(12) << std::left << lastPrice << "|" << std::setw(12) << std::left << BidVolume << "|" << std::setw(12) << std::left << AskVolume << "|" << std::setw(12) << std::left << delta << "\n"; file.close(); } Question: a) Any sugestions on how to retrieve these values (Delta , Delta Chg, Max Delta, and Min Delta ) ? What function to use so that it does not return 0 Result: 2025-04-22 17:28:38.321|F.US.EU6M25 |EUROFUTURE6EJun2025 |1.15075 |0 |0 |0 |
![]() ![]() |
To post a message in this thread, you need to log in with your Sierra Chart account: