简体   繁体   English

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

[英]How to plot CSV values as a Custom Indicator?

I am new to MQL4 and MetaTrader4. 我是MQL4和MetaTrader4的新手。 I have a CSV file in a following format - 我有以下格式的CSV文件-

2017.2.1 0:00, 120
2017.2.1 0:05, 123
2017.2.1 0:10, 125    

The date format is YYYY.MD H:MM . 日期格式为YYYY.MD H:MM I searched other forums, but couldn't get help. 我搜索了其他论坛,但无法获得帮助。 I want this to be plotted as an indicator. 我希望将其绘制为指标。

about reading data: need to open data, then read its content: 关于读取数据:需要打开数据,然后读取其内容:

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;
    }

about parsing each line of the above obtained text: 关于解析以上获得的文本的每一行:

  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

after that - find index using iBarShift() that corresponds to your date and Buffer[i] = value that is parsed from the same line 之后-使用与您的日期对应的iBarShift()查找索引,并且Buffer [i] =从同一行分析的值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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