繁体   English   中英

如何将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.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM