[英]How to plot CSV values as a Custom Indicator?
我是MQL4
和MetaTrader4的新手。 我有以下格式的CSV文件-
2017.2.1 0:00, 120
2017.2.1 0:05, 123
2017.2.1 0:10, 125
日期格式為YYYY.MD H:MM
。 我搜索了其他論壇,但無法獲得幫助。 我希望將其繪制為指標。
關於讀取數據:需要打開數據,然后讀取其內容:
bool ReadFile(const string fileName, string &data){
const int handle=FileOpen(fileName,FILE_READ|FILE_TXT);
if (handle==INVALID_HANDLE) return false;
string collector = "";
int SIZE = (int)FileSize(handle);
int size=StringLen(collector);
while(size < SIZE && !IsStopped()){
collector = StringConcatenate(collector, "\n", FileReadString(handle, SIZE - size));
size = StringLen(collector);
}
FileClose(handle);
if (!FileDelete(fileName))
Print("FileDelete(", fileName, ") FAILED"); // to delete this file after it is read
data = collector;
return true;
}
關於解析以上獲得的文本的每一行:
MqlTime mql;
int st_pos=0,end_pos=0;
int year = 0;
end_pos = StringFind(line, ".", st_pos);
int year = StrToInteger(StringSubStr(line,st_pos+1,end_pos-st_pos-1));
mql.year = year;
// same with month, day, hour and minute
datetime time = StructToTime(mql); - this is your date
之后-使用與您的日期對應的iBarShift()
查找索引,並且Buffer [i] =從同一行分析的值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.