else { comment="Error with exporting: "+fileName; } return (comment); } return(""); }
comment is declared and returned in the for loop
You need to return something after the loop.
Hi David,
It looks like you got your answer from Keith. I'd also like to offer some advice... Whenever you hard-code symbols you will have a bad time when switch to ECN brokers since most of them will append different chars to the end of the symbol name. It's always best practice to do sub string comparisons instead. I've actually written a similar script to yours in the past... maybe this can help you with some ideas...
//+------------------------------------------------------------------+ //| history_dump_to_csv.mq4 | //| nicholishen | //| https://www.forexfactory.com/nicholishen | //+------------------------------------------------------------------+ #property copyright "nicholishen" #property link "https://www.forexfactory.com/nicholishen" #property version "1.00" #property strict #ifdef __MQL4__ #define __VERSION__ "MQL4" #else #define __VERSION__ "MQL5" #endif #define __FILES_PATH__ "\\" + __VERSION__+ "\\Files\\" #define __DIRECTORY__ "HistoryCsv" #define ERR_INVALID_SYMBOL ERR_USER_ERROR_FIRST + 1 //+------------------------------------------------------------------+ #include <Files\File.mqh> //+------------------------------------------------------------------+ // common template function for membership testing template <typename T> bool in(T item, T &array[]) { for(int i=ArraySize(array)-1; i>=0; --i) if(item == array[i]) return true; return false; } //+------------------------------------------------------------------+ class MajorsHistoryFile : public CFile { public: bool dump(string symbol){ ResetLastError(); string currencies[] = { "AUD", "CAD", "CHF", "EUR", "GBP", "JPY", "NZD", "USD" }; ENUM_TIMEFRAMES timeframes[] = { PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1 }; if(!this._is_allowed_symbol(symbol, currencies)){ SetUserError(1); return false; } bool res = true; for(int i=ArraySize(timeframes)-1; i>=0; --i){ MqlRates rates[]; ArraySetAsSeries(rates, true); int copied = CopyRates(symbol, timeframes[i], 0, 10000, rates); if(copied < 1){ res = false; continue; } string file_name = StringConcatenate( __DIRECTORY__, "\\", symbol, "\\", symbol, "_", EnumToString(timeframes[i]), ".csv" ); if(this.Open(file_name, FILE_CSV|FILE_WRITE, ',') == INVALID_HANDLE) return false; FileWrite(this.Handle(), "Time","Open","High","Low","Close","Tick Volume","Real Volume","Spread" ); for(int j=0; j<copied; j++){ FileWrite(this.Handle(), rates[j].time, rates[j].open, rates[j].high, rates[j].low, rates[j].close, rates[j].tick_volume, rates[j].real_volume, rates[j].spread ); } } return res; } string abs_path() const { return StringConcatenate( TerminalInfoString(TERMINAL_DATA_PATH), __FILES_PATH__, this.FileName() ); } protected: bool _is_allowed_symbol(string symbol, string &allowed_currencies[]) { return(in(StringSubstr(symbol, 0, 3), allowed_currencies) && in(StringSubstr(symbol, 3, 3), allowed_currencies) ); } }; //+------------------------------------------------------------------+ void OnStart() { for(int i=SymbolsTotal(false)-1; i>=0; --i){ MajorsHistoryFile file; if(file.dump(SymbolName(i, false))){ Print("SUCCESS: ", file.abs_path()); }else if(_LastError != ERR_INVALID_SYMBOL){ Print("FAILED: ", _LastError); } } } //+------------------------------------------------------------------+

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
I'm getting an "'}' - not all control paths return a value" error with my code but when I take out a for loop its fine. Here's the code:
It feels like I've tried every solution.