Metatrader CSV 和 C# StreamWriter CSV 之间的区别。如何解决?

difference between Metatrader CSV and C# StreamWriter CSV. How to solve it?

我在 Metatrader 中有一个代码,可以将一些报价写入 CSV,但是在 C# 中做同样的事情时,专家顾问以不同的方式读取值.... MetaEditor 中的这段代码写入 CSV 文件:

li_40 = FileOpen(ls_32, FILE_CSV|FILE_WRITE|FILE_SHARE_READ, ";");
      if (li_40 > 0) {
         FileWrite(li_40, ls_16);
         FileClose(li_40);

这是用 C# 编写的:

            List<string> listB = new List<string>();
            using (StreamReader reader = new StreamReader(File.OpenRead(oFile)))
            {
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    listB.Add(reader.ReadLine());
                }
                reader.Close();
            }
            using (StreamWriter swOut = new StreamWriter(oFile))
            {

                foreach (var item in listB)
                {
                    swOut.Write(item);
                    swOut.Write(Environment.NewLine);
                }
                for (int i = 0; i <= gridIn.Columns.Count - 1; i++)
                {
                    if (i > 0)
                    {
                        swOut.Write(", ");
                    }

                    value = dr.Cells[i].Value.ToString();
                    string vals = dr.Cells[2].Value.ToString();
                                           int priceDecimalPlaces = vals.Split('.').Count() > 1
                                  ? vals.Split('.').ToList().ElementAt(1).Length
                                  : 0;
                                            string nell = "0";
                                            if (priceDecimalPlaces == 3)
                                            {
                                                nell = "0.001";
                                            }
                                            if (priceDecimalPlaces == 5)
                                            {
                                                nell = "0.00001";
                                            }
                                            if (priceDecimalPlaces == 4)
                                            {
                                                nell = "0.0001";
                                            }

                    //replace comma's with spaces
                    value = value.Replace(',', ' ');
                    //replace embedded newlines with spaces
                    value = value.Replace(Environment.NewLine, "");

如果 C# double 和 Metatrader 当前的 double 值之间的差异是 0.12098-0.12096=2,Metatrader 不会将值视为 2,而是更高的值,例如 18 ,17 等等,但是从 MetaTrader 的代码中写入相同的值会给出正确的值...

我使用 _lread 读取了 CSV:

     uchar chBuff[1024];
     int res = _lread(hFile, chBuff, 1);
     //
     //CreateFileA(
     res = _lread(hFile, chBuff, 350);
     ls_308 = CharArrayToString(chBuff, 0, res, CP_UTF8);
  //Alert(Ls_84);
     ls_308=StringSubstr(ls_308,0,StringFind(ls_308,"\r\n",0));   

     if (_lclose(hFile)<0) Print("Error closing");

我认为 Metatrader 上的 C# 双打与普通 Metatrader 双打之间存在一些差异

错误是由于系统的编码语言与 Metatrader 代码中指定的 UTF-8 不同

ls_308 = CharArrayToString(chBuff, 0, res, CP_UTF8);

所以,我通过这样做将 UTF 更改为系统分配的所有代码页

ls_308 = CharArrayToString(chBuff, 0, res, CP_ACP);

希望有人觉得这有用..