如何将 CSV 值绘制为自定义指标?

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.M.D 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] = 从同一行解析的值查找索引