Save and Load data New comment UnknownInnocent 2021.09.27 11:53 Hello, In my Expert I have this list: CArrayList<ClickDatapoint *> *clickData; ClickDatapoint has these for us relevant funtions: ClickDatapoint::ClickDatapoint(const MqlRates &price_data, const CLICK_TYPE &click_type) { priceData = price_data; ArrayResize(clickType, 1); clickType[0] = click_type; } void ClickDatapoint::addClickType(CLICK_TYPE click_type) { if(!hasClickType(click_type)) { int size = ArraySize(clickType); ArrayResize(clickType, size + 1); clickType[size] = click_type; } } const string ClickDatapoint::toString(const string sep) const { string res = TimeToString(priceData.time, TIME_DATE | TIME_MINUTES | TIME_SECONDS); for(unsigned int i = 0; i < (unsigned int) ArraySize(clickType); ++i) { res += sep + EnumToString(clickType[i]); } return res; } Now I save the CArrayList like this: bool save() { string file = filepath + Symbol() + (string)Period() + ".csv"; int file_handle = FileOpen(file, FILE_WRITE | FILE_CSV); if(file_handle != INVALID_HANDLE) { for(unsigned int i = 0; i < (unsigned int) clickData.Count(); ++i) { ClickDatapoint *temp; clickData.TryGetValue(i, temp); FileWrite(file_handle, temp.toString(CharToString(separator))); } FileClose(file_handle); return true; } else { return false; } } The result is something like that: 2021.09.24 03:00:00,OPEN_LONG 2021.09.27 09:00:00,OPEN_LONG 2021.09.27 12:00:00,OPEN_LONG 2021.09.24 17:00:00,OPEN_SHORT,CLOSE_SHORT 2021.09.27 06:00:00,OPEN_SHORT So far everything works. But now I want to load the data from a csv-file to my CArrayList. For that I have following functions: bool load() { string file = filepath + Symbol() + (string)Period() + ".csv"; int file_handle = FileOpen(file, FILE_READ | FILE_CSV); if(file_handle != INVALID_HANDLE) { while(!FileIsEnding(file_handle)) { string line = FileReadString(file_handle); clickData.Add(parseString(line)); } FileClose(file_handle); return true; } else { return false; } } ClickDatapoint *parseString(const string &str) { string arr[]; int size = StringSplit(str, (ushort)separator, arr); datetime time = StringToTime(arr[0]); CLICK_TYPE click_type = (CLICK_TYPE) arr[1]; MqlRates rate = getRate(Period(), time); ClickDatapoint *res = new ClickDatapoint(rate, click_type); for(unsigned int i = 2; i < (unsigned int) size; ++i) { CLICK_TYPE c = (CLICK_TYPE) arr[i]; res.addClickType(c); } return res; } MqlRates getRate(const ENUM_TIMEFRAMES timeframe, const datetime &time) { MqlRates rates[]; int index = iBarShift(Symbol(), timeframe, time, true); CopyRates(Symbol(), timeframe, (index >= 0 ? index - 1 : 0), 1, rates); if(index < 0) { SetUserError(4001); } return rates[0]; } It seems like the error is in parseString somewhere here: MqlRates rate = getRate(Period(), time); ClickDatapoint *res = new ClickDatapoint(rate, click_type); but I can't find it. New comment
Hello, In my Expert I have this list:
ClickDatapoint has these for us relevant funtions:
Now I save the CArrayList like this:
The result is something like that:
So far everything works. But now I want to load the data from a csv-file to my CArrayList. For that I have following functions:
It seems like the error is in parseString somewhere here:
but I can't find it.