交易中的机器学习:理论、模型、实践和算法交易 - 页 2938

 
Mikhail Mishanin #:

2023.02.28 05:27:35.269 存储 成功加入 "ONNX.Price.Prediction "项目

2023.02.28 05:27:56.191 存储 MQL5 存储已激活

2023.02.28 05:27:56.191 存储 为 MQL5 开始签出

2023.02.28 05:27:56.635 存储 找不到请求的 SVN 文件系统 (720003)

2023.02.28 05:28:32.432 存储 MQL5 存储的所有者是 "dinpae@gmail.com",请更改 MQL5 帐户

什么意思?无法连接。

2023.02.28 05:36:25.147 存储 所有者MQL5 存储为'dinpae@gmail.com',更改 MQL5 帐户


您登录 MQL5 Storage 的账户是什么?

您是否指定了电子邮件或精确的区分大小写的登录名?

不接受电子邮件。

 
Aleksey Nikolayev #:

右键点击项目名称。应该是这样的


是的,有这么一个东西,但它会写入一个错误
2023.02.28 13:05:45.151 Storage checkout started for MQL5\Shared Projects\ONNX.Price.Prediction
2023.02.28 13:05:45.667 Storage Not authorized to open root of edit operation  (220000)
有某种授权
 
Evgeny Dyuka #:
是的,是有这么个东西,但它给出的错误信息是: There's some sort of authorisation somewhere.

我也不知道。试着离开并删除项目,然后重新加入,再从版本库中获取更新。

当你离开一个项目时,日志会显示:

2023.02.28 16:31:47.481 Storage successfully left the project 'ONNX.Price.Prediction'

删除时,不会写入任何内容。加入项目时:

2023.02.28 16:31:59.970 Storage successfully joined to the project 'ONNX.Price.Prediction'

接收更新时:

2023.02.28 16:41:43.985 Storage checkout started for MQL5\Shared Projects\ONNX.Price.Prediction
2023.02.28 16:41:44.750 Storage added MQL5\Shared Projects\ONNX.Price.Prediction\Python
2023.02.28 16:41:44.750 Storage added MQL5\Shared Projects\ONNX.Price.Prediction\Python\PricePredictionTraining.py
2023.02.28 16:41:44.750 Storage added MQL5\Shared Projects\ONNX.Price.Prediction\Python\PricePrediction.py
2023.02.28 16:41:44.750 Storage added MQL5\Shared Projects\ONNX.Price.Prediction\Python\model.onnx
2023.02.28 16:41:44.750 Storage added MQL5\Shared Projects\ONNX.Price.Prediction\ONNX.Price.Prediction.mq5
2023.02.28 16:41:44.750 Storage added MQL5\Shared Projects\ONNX.Price.Prediction\ONNX.Price.Prediction.mqproj
2023.02.28 16:41:44.784 Storage checkout completed successfully in 797 ms

只有在连接到版本库时才会授权--没有授权就不可能加入项目。

我帮不了你了。除非你用的是旧版本--我用的是最新版本(测试版和发行版)。

 
Aleksey Nikolayev #:

我也不知道。试着离开并删除项目,然后重新加入,再从版本库中获取更新。

当你离开日志中的项目时:

删除时,不会写入任何内容。加入项目时:

接收更新时:

只有在连接到版本库时才需要授权--没有授权基本上就无法加入项目。

其他的我就帮不了你了。除非你用的是旧版本--我用的是最新版本(测试版和发行版)。

明白了,谢谢
 
Evgeny Dyuka #:
明白了,谢谢。

为了以防万一,我把项目发布到了存档中。

附加的文件:
 
Renat Fatkhullin #:

您登录 MQL5 存储的账户是什么?

您是否指定了您的电子邮件或精确的区分大小写的登录名?

不接受电子邮件。

关于登录名,只有我的登录名最初是歪的,有圆点 dr.mr.mom,我很久以前就有了,您能更改登录名吗?

 

发布测试版 3589,您可以在上面测试 ONNX 型号的运行。

操作步骤

  1. 通过帮助 -> 检查桌面更新 -> 最新测试版更新到 3589

  2. 以区分大小写的形式指定正确的 MQL5 登录(非电子邮件),激活 MQL5 存储:






  3. 如果您的配置已损坏,MQL5 存储无法工作,请通过文件 -> 打开数据文件夹打开资源管理器,转到 MQL5 目录并删除以下文件:


    。然后转到步骤 2。

  4. 使用 "加入 "命令从上下文菜单加入 ONNX.Price.Prediction 项目。



  5. 打开导航器,打开共享项目部分,在 ONNX.Price.Prediction 项目上,从上下文菜单中选择从存储更新:



    项目将从 MQL5 存储(Subversion)下载。

  6. 打开项目并点击 ONNX.Price.Prediction.mqproj - 这就是项目文件



  7. 复制项目并在 EURUSD、H1 上运行。

  8. 得到结果:
    2023.02.28 21:54:43.316 Scripts script ONNX.Price.Prediction (EURUSD,H1) loaded successfully
    2023.02.28 21:54:43.348 ONNX    initialized [API version 1.14.0]
    
    в журнале Experts: важны две последние строки, а остальное - специально включенные отладочные логи по флагу ONNX_DEBUG_LOGS
    
    2023.02.28 22:11:53.441 ONNX.Price.Prediction (EURUSD,H1)       ONNX: Creating and using per session threadpools since use_per_session_threads_ is true
    2023.02.28 22:11:53.441 ONNX.Price.Prediction (EURUSD,H1)       ONNX: Dynamic block base set to 0
    2023.02.28 22:11:53.442 ONNX.Price.Prediction (EURUSD,H1)       ONNX: Initializing session.
    2023.02.28 22:11:53.442 ONNX.Price.Prediction (EURUSD,H1)       ONNX: Adding default CPU execution provider.
    2023.02.28 22:11:53.442 ONNX.Price.Prediction (EURUSD,H1)       ONNX: Total shared scalar initializer count: 0
    2023.02.28 22:11:53.443 ONNX.Price.Prediction (EURUSD,H1)       ONNX: Total fused reshape node count: 0
    2023.02.28 22:11:53.443 ONNX.Price.Prediction (EURUSD,H1)       ONNX: Total shared scalar initializer count: 0
    2023.02.28 22:11:53.443 ONNX.Price.Prediction (EURUSD,H1)       ONNX: Total fused reshape node count: 0
    2023.02.28 22:11:53.444 ONNX.Price.Prediction (EURUSD,H1)       ONNX: Use DeviceBasedPartition as default
    2023.02.28 22:11:53.444 ONNX.Price.Prediction (EURUSD,H1)       ONNX: Saving initialized tensors.
    2023.02.28 22:11:53.444 ONNX.Price.Prediction (EURUSD,H1)       ONNX: Done saving initialized tensors
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: Session successfully initialized.
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: Number of streams: 1
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: Begin execution
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 0
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: ort value 1 released
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 1
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: ort value 2 released
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 3
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: ort value 6 released
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 4
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: ort value 8 released
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 5
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: ort value 9 released
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 6
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 7
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 2
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: ort value 3 released
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: ort value 11 released
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 8
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 9
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: ort value 16 released
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 10
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 11
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: ort value 22 released
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 12
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: ort value 25 released
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 13
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: ort value 27 released
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 27
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 17
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 18
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: ort value 28 released
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 28
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: ort value 30 released
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       ONNX: stream 0 launch kernel with idx 26
    
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       [-1.5921557]
    2023.02.28 22:11:53.445 ONNX.Price.Prediction (EURUSD,H1)       predicted 1.0591759612759748
    
  9. 如果无法运行,则表示 ONNX Runtime 版本过旧或缺少

    在这种情况下,下载由微软签名的ONNX Runtime 1.14 压缩包,将其扩展到终端根目录下的 terminal64.exe 旁边,然后重启终端:

在该项目中,为了便于演示,将立即附上经过最简单训练的 model.onnx。



要自己训练模型,需要使用项目中包含的 python 脚本:

  1. 安装 Python 3(例如 Python 3.10)并交付/更新软件包:
    python.exe -m pip install --upgrade pip
    pip install --upgrade tensorflow
    pip install --upgrade pandas
    pip install --upgrade scikit-learn
    pip install --upgrade matplotlib
    pip install --upgrade tqdm
    pip install --upgrade metatrader5
    pip install --upgrade onnx==1.12
    pip install --upgrade tf2onnx
    在 onnx 软件包中明确说明版本为 1.12,以免与 tensorflow 的要求相冲突。

  2. 运行 MetaEditor 并确保 Python 在 "工具"->"选项"->"编译器 "中被识别:



    如有必要,如果编辑器无法自行确定路径,请自行指定路径。

  3. 交易终端应连接到欧元兑美元服务器(例如 MetaQuotes-Demo)

    确保在终端设置中启用了与 Python 的集成。如果已关闭,请打开并重新启动终端:




  4. 转到导航器中的 ONNX.Price.Prediction 项目,打开 PricePredictionTraning.py 文件


  5. 运行脚本进行编译,对于 Python 脚本而言,这意味着启动。

    脚本将借助 MetaTrader5 软件包连接到终端(如果已关闭,将自动启动),并开始对欧元兑美元、H1 进行训练:


    完成后,日志编辑器将包含:
    2023.02.28 22:24:16.876 Python  107/107 [==============================] - 0 s 1 ms/step - loss: 1.9167 - mae: 0.8553
    2023.02.28 22:24:16.876 Python  test_loss=1.917
    2023.02.28 22:24:16.876 Python  test_mae=0.855
    2023.02.28 22:24:17.179 Python  saved model to C:\Users\sys\AppData\Roaming\MetaQuotes\Terminal\8 D1E0A7047FFD62A8C00B09AEC1F3004\MQL5\Shared Projects\ONNX.Price.Prediction\Python\model.onnx
    2023.02.28 22:24:17.291 Storage modify MQL5\Shared Projects\ONNX.Price.Prediction\Python\model.onnx to base
    
    新的 model.onnx 将保存/更新在项目中。它已经可以使用。

  6. 运行 PricePrediction.py 脚本以确保模型正常运行:
    2023.02.28 22:27:46.078 Python  data path to load onnx model C:\Users\sys\AppData\Roaming\MetaQuotes\Terminal\8 D1E0A7047FFD62A8C00B09AEC1F3004\MQL5\Shared Projects\ONNX.Price.Prediction\Python\
    2023.02.28 22:27:46.078 Python  [[[1.061412 1.062328 1.060358 1.061169]]]
    2023.02.28 22:27:46.078 Python  [[[0.00105361 0.00119785 0.00074662 0.00125179]]]
    2023.02.28 22:27:46.078 Python  [[[ 0.18792516  0.17698306  0.01607251 -0.45455042]
    2023.02.28 22:27:46.078 Python    [-0.77068297 -0.50757406  0.2839477   0.36827372]
    2023.02.28 22:27:46.078 Python    [ 0.21639867 -0.3823502   0.48485409 -0.19891574]
    2023.02.28 22:27:46.078 Python    [-0.46696554 -0.31556414  0.33752274  0.48011389]
    2023.02.28 22:27:46.078 Python    [ 0.3302927   0.7196198   1.36884221  1.56656129]
    2023.02.28 22:27:46.078 Python    [ 1.63058293  1.46261473  1.39562973  1.74231014]
    2023.02.28 22:27:46.078 Python    [ 1.82040632  1.84663458 -0.26519644 -0.52644768]
    2023.02.28 22:27:46.078 Python    [-0.84661232 -0.50757406 -0.45270907 -0.86995678]
    2023.02.28 22:27:46.078 Python    [-1.27371495 -1.11699687 -1.10900328 -0.48650476]
    2023.02.28 22:27:46.078 Python    [-0.82762998 -1.37579285 -2.0599602  -1.62088366]]]
    2023.02.28 22:27:46.094 Python  [[-1.6349795]]
    2023.02.28 22:27:46.094 Python  predict:  [1.05912]
    
  7. 测试示例正常运行!




您可以使用 python 软件包 onnx 和 tf2onnx 将自己的 TensorFlow 模型转换为 ONNX 格式:

import tf2onnx
...
onnx_model = tf2onnx.convert.from_keras(model, output_path=output_path)

注意:请使用最新版本的项目,因为旧版本中的函数原型已经更改。
 

成功了

2023.03.01 06:54:34.987 ONNX.Price.Prediction (EURUSD,H1)       [-0.20001383]
2023.03.01 06:54:34.988 ONNX.Price.Prediction (EURUSD,H1)       predicted 1.0581684510582798
 
Renat Fatkhullin #:
  1. 放入 Python 3(如 Python 3.10)并交付/更新软件包:
    软件包 onnx,明确提及版本 1.12,以免与 tensorflow 要求冲突。

无法安装该软件包。首先需要安装 CMake。现在又要求安装 Visual Studio?

CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
 
Aleksey Nikolayev #:

无法安装此软件包。他们先是要求安装 CMake。现在又要求安装 Visual Studio?

您还处在与互不兼容的地狱搏斗和为 Python 任务创建独立环境的起步阶段。

有些软件包的目标构建需要编译器。

原因: