Support Board
Date/Time: Wed, 19 Mar 2025 07:35:52 +0000
[Programming Help] - ACSIL - file in use after closing it
View Count: 797
[2022-10-14 21:30:12] |
tomna1993 - Posts: 24 |
I have a function (see below) to open a file I created before and append data to it then close the file. Sometimes if I want to delete the file it shows me that the file is in use by sierra, but it's not. Could you help me figure out what happens and how can I solve this problem? //--------------------------------------------------------------------
// Save data to log file void SaveDataToLogFile(SCStudyInterfaceRef sc, SCString Path, SCString DataToSave) { int FileHandle; sc.OpenFile(Path, n_ACSIL::FILE_MODE_OPEN_TO_APPEND, FileHandle); unsigned int BytesWritten = 0; unsigned int BytesToWrite = DataToSave.GetLength(); sc.WriteFile(FileHandle, DataToSave, BytesToWrite, &BytesWritten); sc.CloseFile(FileHandle); } |
![]() |
[2022-10-15 00:06:15] |
User183724 - Posts: 194 |
are you saving to SC log file? is SC still open?? is SC using the file your attempting to delete???
|
[2022-10-15 22:02:35] |
tomna1993 - Posts: 24 |
I'm saving the file to my desktop; Sierra is still open when I want to delete the file. I think it should not use it because I save data at the end of my program then wait for user input to start the data collection and append the data into the file. The study doesn't autoloop (autoloop = 0).
|
[2022-10-16 06:51:13] |
User183724 - Posts: 194 |
try closing SC before deleting the file. If its a file SC uses, that could be your problem and ya might want to consider using a different file so youre not deleting something important. SC logs are used to trouble shoot software issues.
|
[2022-10-16 09:27:44] |
tomna1993 - Posts: 24 |
It is not an SC log file and also can't see any issue when I debug the study. I create the file to save some information about the price and indicators. I assumed after closing a file with the sc.CloseFile the file shouldn't be used anymore by sierra until I open it again with sc.OpenFile. I use another system programmed by someone else and there it works flawlessly.
|
[2022-10-16 18:31:23] |
User183724 - Posts: 194 |
then it may be a file sharing issue thats different between the two computers. maybe look for a difference in operating systems (windows vs something else), file sharing settings etc.
|
[2022-10-16 18:39:34] |
ForgivingComputers.com - Posts: 1028 |
How is the function being called? Is it every time your custom study runs? That could cause it to appear locked. Also, are you viewing it in Excel? Excel will lock a CSV file even if you are only reading it. |
[2022-10-16 20:16:37] |
tomna1993 - Posts: 24 |
There is no file sharing enabled on my computer for desktop. The function is called every time my study runs, once after reloading a chart. The file is not opened in Excel when I want to delete it, but yes if I want to check it, I open it in excel. I understand that Excel could lock the file when it is open, but I never had problem from excel side. I tried to close the file with sc.CloseFile more times, even debug it and the function returns true when I call that line. |
[2022-10-16 22:34:23] |
User183724 - Posts: 194 |
its got to be something different between you and your buddys machine settings and not this ACSIL file if the file works on his machine and not yours. I'd start by trying to save it as a text file instead of a CSV file and see if that makes a difference... maybe it is a setting in excel on your machine and you'd have to track that down. if it doesnt change when you save as a text file then i'd think its a windows level problem.
|
[2022-10-17 07:59:01] |
tomna1993 - Posts: 24 |
We don't use the same code. He programs is c++, I program in ACSIL so I think he uses the c++ library for file handling. For me it produces the same problem with txt and csv too.
Date Time Of Last Edit: 2022-10-17 07:59:33
|
[2022-10-17 09:21:48] |
User431178 - Posts: 617 |
Maybe you could share the code where the SaveDataToLogFile function is called from?
|
[2022-10-17 12:55:44] |
tomna1993 - Posts: 24 |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// READ PARAMETERS FROM CHART FOR LOGGING AND CREATE LOG FILE WITH HEADER //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if(r_ExportData == 1) { // Get chart bar period in seconds n_ACSIL::s_BarPeriod BarPeriod; sc.GetBarPeriodParameters(BarPeriod); if (BarPeriod.ChartDataType == INTRADAY_DATA && BarPeriod.IntradayChartBarPeriodType == IBPT_DAYS_MINS_SECS) Log_TimeFrame = BarPeriod.IntradayChartBarPeriodParameter1; //-------------------------------------------------------------------- // Get chart symbol Log_Symbol = sc.GetChartSymbol(sc.ChartNumber); //-------------------------------------------------------------------- // Open log file for logging, if file not found create a new file int FileHandle; if(!sc.OpenFile(Input_LogPath.GetPathAndFileName(), n_ACSIL::FILE_MODE_OPEN_EXISTING_FOR_SEQUENTIAL_READING, FileHandle)) { sc.CloseFile(FileHandle); SCString TempString; //-------------------------------------------------------------------- // Get subgraph names from signal and context study //-------------------------------------------------------------------- LogDataToFile.Clear(); TempString.Clear(); //-------------------------------------------------------------------- // Write log header LogDataToFile.Append("Symbol;Direction;Timeframe;OpenDate;OpenTime;CloseDate;CloseTime;BarsInTrade;Qty;Commission"); LogDataToFile.Append(";Grid0;Grid100;IniStop;SignalSize(Tick);TickValue"); LogDataToFile.Append(";OpenPrice;AvgClosePrice;AvgCloseGrid;IniRisk;PnL;RR;MinimumPrice;MinimumGrid;MaximumPrice;MaximumGrid"); LogDataToFile.Append(";LastTargetReachedGrid;LastTargetReachedPrice;LastStopReachedGrid;LastStopReachedPrice"); SCGraphData StudyData; sc.GetStudyArraysFromChartUsingID(sc.ChartNumber, Input_SignalStudy.GetStudyID(), StudyData); int ArraySize = StudyData.GetArraySize(); for(r_LoopCount = 0; r_LoopCount < ArraySize; r_LoopCount++) { TempString = sc.GetStudySubgraphName(Input_SignalStudy.GetStudyID(), r_LoopCount); LogDataToFile.AppendFormat(";%s", TempString.GetChars()); } sc.GetStudyArraysFromChartUsingID(Input_ContextStudy.GetChartNumber(), Input_ContextStudy.GetStudyID(), StudyData); ArraySize = StudyData.GetArraySize(); for(r_LoopCount = 0; r_LoopCount < ArraySize; r_LoopCount++) { sc.GetStudySubgraphNameFromChart(Input_ContextStudy.GetChartNumber(), Input_ContextStudy.GetStudyID(), r_LoopCount, TempString); LogDataToFile.AppendFormat(";%s", TempString.GetChars()); } LogDataToFile.Append("\n"); SaveDataToLogFile(sc, Input_LogPath.GetPathAndFileName(), LogDataToFile); sc.AddMessageToLog("Create log file and header",0); LogDataToFile.Clear(); } } |
[2022-10-17 13:26:45] |
User431178 - Posts: 617 |
How is r_ExportData set (acs button?) and is it then reset to 0 anywhere?
|
[2022-10-17 16:32:31] |
tomna1993 - Posts: 24 |
Yes, at the end of the program all button and variable are set to zero.
|
[2022-10-17 16:46:37] |
User183724 - Posts: 194 |
ACSIL is C++. ACSIL uses sierra chart functions in their own header file (sierrachart.h). you would need to compare your buddys code to your code to see the difference. i notice your close statement is in an if statement. so the only time the file closes is if the if statement is true. // Open log file for logging, if file not found create a new file int FileHandle; if(!sc.OpenFile(Input_LogPath.GetPathAndFileName(), n_ACSIL::FILE_MODE_OPEN_EXISTING_FOR_SEQUENTIAL_READING, FileHandle)) { sc.CloseFile(FileHandle); SCString TempString; you may want to look at puttin a close statement in after the if statement in case the not true condition is met |
To post a message in this thread, you need to log in with your Sierra Chart account: