Support Board
Date/Time: Wed, 05 Feb 2025 19:51:31 +0000
Post From: ACSIL export to csv
[2025-01-07 06:15:08] |
User373245 - Posts: 47 |
Hmmmmmm cant get it to work. It's all logging correctly. I've tried a bunch of things. Placing the open and close outside the loop will not compile. I am on a Mac also using parallels and there is no letter to the pathway. Ive checked the file and all that to make sure changes can occur and all that to the file. I can send information to the file if I code it in R or python and it works. It's a csv file I make with textEdit and it's all configured to accept changes. The fact that I am going from parallels to the Mac and all the administration is set...would it log the file pathway if it was not accessing it ??? 2025-01-07 06:08:59.126 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | Current price: 82.371002 2025-01-07 06:08:59.126 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | Open Price: 82.364998 2025-01-07 06:08:59.126 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | High Price: 82.403503 2025-01-07 06:08:59.126 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | Low Price: 82.347000 2025-01-07 06:08:59.127 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | Close Price: 1.000000 2025-01-07 06:08:59.127 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | 60 SMA Value: 0.000000 2025-01-07 06:08:59.127 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | Attempting to write to file now... 2025-01-07 06:08:59.127 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | Formatted Data to Write: 82.371002, 82.364998, 82.403503, 82.347000, 1.000000, 0.000000 2025-01-07 06:08:59.127 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | CSV File Path: /Users/philiphoy/Desktop/Test.csv 2025-01-07 06:08:59.128 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | Data written to file. 2025-01-07 06:08:59.128 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | File closed after writing. 2025-01-07 06:09:03.425 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | Current price: 82.371002 2025-01-07 06:09:03.425 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | Open Price: 82.364998 2025-01-07 06:09:03.425 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | High Price: 82.403503 2025-01-07 06:09:03.425 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | Low Price: 82.347000 2025-01-07 06:09:03.425 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | Close Price: 1.000000 2025-01-07 06:09:03.425 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | 60 SMA Value: 0.000000 2025-01-07 06:09:03.425 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | Attempting to write to file now... 2025-01-07 06:09:03.425 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | Formatted Data to Write: 82.371002, 82.364998, 82.403503, 82.347000, 1.000000, 0.000000 2025-01-07 06:09:03.425 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | CSV File Path: /Users/philiphoy/Desktop/Test.csv 2025-01-07 06:09:03.425 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | Data written to file. 2025-01-07 06:09:03.425 | Chart: AUDJPY[M] 5 Min #1 | Study: File Export | File closed after writing. #include "sierrachart.h" #include <fstream> // For file operations #include <iostream> // For input/output operations SCDLLName("FILE Export11111"); SCSFExport scsf_FunctionName(SCStudyInterfaceRef sc) { // Set subgraph reference to OHLC SCInputRef Input_240StoAngle = sc.Input[1]; SCInputRef OutputFile = sc.Input[3]; // Initialization code: Runs once when the study is added to the chart if (sc.SetDefaults) { sc.GraphName = "File Export"; // Name of the study sc.StudyDescription = "A basic example of an ACSIL study."; sc.AutoLoop = 0; // Enables auto-loop mode for processing each bar Input_240StoAngle.Name = "240 Rsi Angle"; Input_240StoAngle.SetChartStudySubgraphValues(1, 6, 0); OutputFile.Name = "Output File"; // Name the input for file path OutputFile.SetPathAndFileName("/Users/philiphoy/Desktop/Test.csv"); return; } // Prepare the arrays for study data SCFloatArray sma60Array; sc.GetStudyArrayUsingID(Input_240StoAngle.GetStudyID(), Input_240StoAngle.GetSubgraphIndex(), sma60Array); // Main calculation code: Runs for each bar if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED){ // Get price data for logging float currentPrice = sc.BaseData[SC_LAST][sc.Index]; float openPrice = sc.BaseData[SC_OPEN][sc.Index]; float closePrice = sc.BaseData[SC_CLOSE][sc.Index]; float highPrice = sc.BaseData[SC_HIGH][sc.Index]; float lowPrice = sc.BaseData[SC_LOW][sc.Index]; // Log variables to string for logging data SCString openPriceLog, currentPriceLog, closePriceLog, highPriceLog, lowPriceLog, sma60Log; currentPriceLog.Format("Current price: %2f", currentPrice); sc.AddMessageToLog(currentPriceLog, 0); openPriceLog.Format("Open Price: %2f", openPrice); sc.AddMessageToLog(openPriceLog, 0); highPriceLog.Format("High Price: %2f", highPrice); sc.AddMessageToLog(highPriceLog, 0); lowPriceLog.Format("Low Price: %2f", lowPrice); sc.AddMessageToLog(lowPriceLog, 0); closePriceLog.Format("Close Price: %2f", closePrice); sc.AddMessageToLog(closePriceLog, 0); sma60Log.Format("60 SMA Value: %2f", sma60Array[sc.Index]); sc.AddMessageToLog(sma60Log, 0); sc.AddMessageToLog("Attempting to write to file now...", 0); // Use the dynamically set file path for CSV output SCString csvFilePath = OutputFile.GetString(); // Get file path from the input // Convert SCString to C-style string const char* filePath = csvFilePath.GetChars(); SCString formattedData; formattedData.Format("%2f, %2f, %2f, %2f, %2f, %2f\n", currentPrice, openPrice, highPrice, lowPrice, closePrice, sma60Array[sc.Index]); // Log the formatted data before writing to the file SCString logMessage; logMessage.Format("Formatted Data to Write: %s", formattedData.GetChars()); sc.AddMessageToLog(logMessage, 0); // Open the file in append mode (to avoid overwriting existing data) std::ofstream file(filePath, std::ios::app); // Log the file path for debugging purposes SCString filePathLog; filePathLog.Format("CSV File Path: %s", filePath); sc.AddMessageToLog(filePathLog, 0); // Check if the file opened successfully if (file.is_open()){ file << "Test Line, 1, 2, 3, 4, 5\n"; // Write the values to the CSV file file << currentPrice << ", " << openPrice << ", " << highPrice << ", " << lowPrice << ", " << closePrice << ", " << sma60Array[sc.Index] << "\n"; sc.AddMessageToLog("Data written to file.", 0); file.close(); // Close the file after writing sc.AddMessageToLog("File closed after writing.", 0); } else { // If the file didn't open, log an error message sc.AddMessageToLog("Failed to open file for writing.", 0); } } } |