snelle_moda:
Hi
I try to copy the CLOSE price value of a serie of 1 min BARS to a CSV file.
But the CSV file generates wrong output. see below:
Here is my code:
What is wrong with this code.
Can somebody help me, please?
- This line is not needed and lead to an error in Journal tab :
ArrayResize(aData_Close, nHistoryPeriod);
- You are creating a binary file, not a csv :
file_handle = FileOpen(InpDirectoryName + "//" + InpFileName, FILE_READ|FILE_WRITE|FILE_BIN, ',');
Thanks for your input.
I have Changed the code with your suggestions but now I get an empty CSV file with no data.
I have searched the forum for a few days but I don't understand what I'm doing wrong.
#property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 //--- parameters for writing data to the file input string InpFileName = "Bars.csv"; // file name input string InpDirectoryName = "Data"; // directory name int file_handle; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { // boolean check (The indicator only needs to be calculated 1 time). static bool bData_Calculation_Check = false; // Check if the indicator has not yet been calculated. if(bData_Calculation_Check == false) { // Number of BARS to copy static int nHistoryPeriod = 1; nHistoryPeriod = Bars(Symbol(), PERIOD_M1) - 1; // Data array for storage. double aData_Close[]; // Copy data to array. CopyClose(Symbol(), PERIOD_M1, 1, nHistoryPeriod, aData_Close); // Check/create CSV file file_handle = FileOpen(InpDirectoryName + "//" + InpFileName, FILE_READ|FILE_WRITE|FILE_CSV, ','); // Check if file is valid. if(file_handle != INVALID_HANDLE) { // Write the size of data sample. (Do I need this????) FileWriteDouble(file_handle,(double)nHistoryPeriod); // Loop calculation. for(int i = nHistoryPeriod - 1; i >= 0; i--) { // Variable for CLOSE price value. double dValue = aData_Close[i]; FileWriteDouble(file_handle, dValue); } // Close the file. FileClose(file_handle); // Activate the calculation boolean check (The indicator only needs to be calculated 1 time). bData_Calculation_Check = true; } } //--- return value of prev_calculated for next call return(rates_total); }
snelle_moda:
FileWriteDouble doesn't work with a CSV file. Use FileWrite.
Thanks for your input.
I have Changed the code with your suggestions but now I get an empty CSV file with no data.
I have searched the forum for a few days but I don't understand what I'm doing wrong.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi
I try to copy the CLOSE price value of a serie of 1 min BARS to a CSV file.
But the CSV file generates wrong output. see below:
Here is my code:
What is wrong with this code.
Can somebody help me, please?