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

时间:2017-03-10 06:14:11

标签: csv mql4 metatrader4

我是 echo off del /s D:\FILES\completed\*.nfo del /s D:\FILES\completed\*.wflow del /s D:\FILES\completed\*.workflow del /s "D:\FILES\completed\*." echo complete echo on 和MetaTrader4的新手。我有一个以下格式的CSV文件 -

MQL4

日期格式为2017.2.1 0:00, 120 2017.2.1 0:05, 123 2017.2.1 0:10, 125 。我搜索了其他论坛,但无法获得帮助。我希望将其绘制为指标。

1 个答案:

答案 0 :(得分:1)

关于阅读数据:需要打开数据,然后阅读其内容:

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] =值