Can somebody please provide a working solution.
The snippets can be found in the above URL, but here is what I have. Sorry for the horrible formatting.
int start() { IsNewBar(); } // Create an array with all the info you need and write to excel void WriteToExcel(string fileName, double arrayToWrite[]) { int handle = FileOpen(fileName, FILE_CSV|FILE_WRITE|FILE_READ, ','); for(int i = 0; i < ArraySize(arrayToWrite); i++) FileWrite(handle, arrayToWrite[i]); FileClose(handle); return; } bool IsNewBar() { //each tick, check if it's a new 1 hour candle static datetime barTime; bool result = false; if(barTime != iTime(NULL,PERIOD_M1,0)) { barTime = iTime(NULL,PERIOD_M1,0); //you'll need to create a function to populate arrOHLCV WriteToExcel("myHistory.csv", arrOHLCV[]); result = true; } return(result); }
Here it is updated. I also changed arrOHLCV to double type because I have no idea why it was a string in the original example. I'm still getting the "'arrOHLCV' - parameter conversion not allowed" error, and i'm getting two warnings:
arrays passed by reference only
not all control paths return a value
double arrOHLCV[]; int start() { IsNewBar(); } // Create an array with all the info you need and write to excel void WriteToExcel(string fileName, double arrayToWrite[]) { int handle = FileOpen(fileName, FILE_CSV|FILE_WRITE|FILE_READ, ','); for(int i = 0; i < ArraySize(arrayToWrite); i++) FileWrite(handle, arrayToWrite[i]); FileClose(handle); return; } bool IsNewBar() { //each tick, check if it's a new 1 hour candle static datetime barTime; bool result = false; if(barTime != iTime(NULL,PERIOD_M1,0)) { barTime = iTime(NULL,PERIOD_M1,0); //you'll need to create a function to populate arrOHLCV WriteToExcel("myHistory.csv", arrOHLCV[100]); result = true; } return(result); }
1) Your array has size 0 you need to ArrayResize() your arrOHLC[].
2) I don't see how and where it gets its values.
Because your code seems very odd to me, I am not sure if you know more than me or that you are doing it wrong.
First of all I think that your function header/parameters
void WriteToExcel(string fileName, double arrayToWrite[]
should be
void WriteToExcel(string fileName, double &arrayToWrite[]
Also, your function call
WriteToExcel("myHistory.csv", arrOHLCV[100]);
The array should already be sized and given values, so the call should be
WriteToExcel("myHistory.csv", arrOHLCV);
I had to just set arrOHLCV to a fixed size because ArrayResize() was returning a "declaration without type" error. Otherwise, there are no other errors. I tried to backtest with 1 minute bars (as markets are currently closed) and it is not writing the file "myHistory.csv" under any MT4 directory that I can see. Is it possible that it is not writing to CSV because I am backtesting? All I want to do is create a CSV file that will update with OHLC data as each new bar comes in. If someone can show me how I can modify the below code to do this it would be appreciated.
double arrOHLCV[10000]; int start() { IsNewBar(); } // Create an array with all the info you need and write to excel void WriteToExcel(string fileName, double &arrayToWrite[]) { int handle = FileOpen(fileName, FILE_CSV|FILE_WRITE|FILE_READ, ','); for(int i = 0; i < ArraySize(arrayToWrite); i++) FileWrite(handle, arrayToWrite[i]); FileClose(handle); return; } bool IsNewBar() { //each tick, check if it's a new 1 hour candle static datetime barTime; bool result = false; if(barTime != iTime(NULL,PERIOD_M1,0)) { barTime = iTime(NULL,PERIOD_M1,0); //you'll need to create a function to populate arrOHLCV WriteToExcel("myHistory.csv", arrOHLCV); result = true; } return(result); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am trying to implement the example found here:
https://www.mql5.com/en/forum/143616
But i'm getting the following errors:
'arrOHLCV' - undeclared identifier
'arrOHLCV' - parameter conversion not allowed
I though for the first error I need to simply declare arrOHLCV in the global scope, but this creates new errors. Can somebody please provide a working solution.