返回顶部
  • 发帖数2765
  • 粉丝0

愿您早日建立自己的稳定盈利的交易系统!

  • 最佳新人

    注册账号后积极发帖的会员
  • 活跃会员

    经常参与各类话题的讨论,发帖内容较有主见
  • 热心会员

    经常帮助其他会员答疑
  • 推广达人

    积极宣传本站,为本站带来更多注册会员
  • 宣传达人

    积极宣传本站,为本站带来更多的用户访问量
  • 灌水之王

    经常在论坛发帖,且发帖量较大
  • 突出贡献

    长期对论坛的繁荣而不断努力,或多次提出建设性意见
  • 优秀版主

    活跃且尽责职守的版主
  • EA邦VIP

    EA邦vip会员
  • 论坛元老

    为论坛做出突出贡献的会员

MT5CTP程序化交易开发10:写成函数更方便

[复制链接]
唐老师Lv.9 显示全部楼层 发表于 2021-9-2 13:24:02 |阅读模式 打印 上一主题 下一主题
MT5CTP的视频教学可以到网站上关于我们栏目的EA邦的各视频平台里观看。
这是第10课的代码:EA文件代码: 双均线交叉_EA_v1.0.mq5 (5.94 KB, 下载次数: 8)
  1. //+------------------------------------------------------------------+
  2. //|                                      Copyright 2020, EA邦        |
  3. //|                                     http://www.eabang.com      |
  4. //+------------------------------------------------------------------+
  5. #define __MT5CTP__
  6. // 包含库
  7. #ifdef __MT5CTP__
  8. #include <mt5ctp\mt5toctp.mqh>
  9. #endif

  10. #property copyright "Copyright 2021, MetaQuotes Ltd."
  11. #property link      "https://www.eabang.com"
  12. #property version   "1.00"
  13. //--- input parameters
  14. input int      短均线=5;
  15. input int      长均线=10;
  16. input double   开仓量=1.0;
  17. input int      止盈=100;
  18. input int      止损=100;
  19. //+------------------------------------------------------------------+
  20. //| Expert initialization function                                   |
  21. //+------------------------------------------------------------------+
  22. int OnInit()
  23.   {
  24. //--- create timer
  25.    EventSetTimer(60);

  26. //---
  27.    return(INIT_SUCCEEDED);
  28.   }
  29. //+------------------------------------------------------------------+
  30. //| Expert deinitialization function                                 |
  31. //+------------------------------------------------------------------+
  32. void OnDeinit(const int reason)
  33.   {
  34. //--- destroy timer
  35.    EventKillTimer();

  36.   }
  37. //+------------------------------------------------------------------+
  38. //| Expert tick function                                             |
  39. //+------------------------------------------------------------------+
  40. void OnTick()
  41.   {
  42. //---
  43.    if(ddsl(0)==0)
  44.    {
  45.       //定义均线交叉
  46.    }

  47.    Print("多单数量=",ddsl(0));
  48.    Print("空单数量=",ddsl(1));
  49.   }
  50. //+------------------------------------------------------------------+
  51. //| Timer function                                                   |
  52. //+------------------------------------------------------------------+
  53. void OnTimer()
  54.   {
  55. //---

  56.   }
  57. //+------------------------------------------------------------------+
  58. int ddsl(int path)
  59. {
  60.    int a=0;
  61.    int ddzs=mt5ctp::MT5PositionsTotal();
  62.    for(int i=0; i<ddzs; i++)
  63.      {
  64.       ulong ticket = 0;
  65.       mt5ctp::MT5PositionGetTicket(i,ticket);
  66.       MT5CTPOrders order_mt5;
  67.       ZeroMemory(order_mt5);
  68.       if(!mt5ctp::MT5PositionSelectByTicket(ticket,order_mt5))
  69.          continue;
  70.       string pos_symbol = ::CharArrayToString(order_mt5.symbol);
  71.       int digit_symbol = (int)::SymbolInfoInteger(pos_symbol,SYMBOL_DIGITS);

  72.       if(order_mt5.type==path)
  73.         {
  74.          a++;
  75.         }
  76.       //Print("编号=",i);
  77.       //Print("品种=",pos_symbol);
  78.       //Print("订单号=",order_mt5.ticket);
  79.       //Print("开仓时间=",order_mt5.time);
  80.       //Print("持仓方向=",order_mt5.type);
  81.       //Print("开仓量=",order_mt5.volume);
  82.       //Print("开仓价=",order_mt5.price,digit_symbol);
  83.       //Print("止损价=",order_mt5.sl,digit_symbol);
  84.       //Print("止盈价=",order_mt5.tp,digit_symbol);
  85.       //Print("盈亏=",order_mt5.profit);
  86.       //Print("魔术码=",order_mt5.magic);
  87.       //Print("注释=",CharArrayToString(order_mt5.comment));
  88.      }
  89.      
  90.   return(a);
  91. }
复制代码

脚本文件代码: 测试脚本.mq5 (3.85 KB, 下载次数: 0)
  1. #define __MT5CTP__
  2. // 包含库
  3. #ifdef __MT5CTP__
  4. #include <mt5ctp\mt5toctp.mqh>
  5. #endif
  6. //+------------------------------------------------------------------+
  7. //|                                      Copyright 2020, EA邦        |
  8. //|                                     http://www.eabang.com        |
  9. //+------------------------------------------------------------------+
  10. #property copyright "Copyright 2021, MetaQuotes Ltd."
  11. #property link      "https://www.mql5.com"
  12. #property version   "1.00"
  13. //+------------------------------------------------------------------+
  14. //| Script program start function                                    |
  15. //+------------------------------------------------------------------+
  16. void OnStart()
  17.   {
  18. //---
  19.    Print("多单数量=",ddsl(0));
  20.    Print("空单数量=",ddsl(1));
  21.   }
  22. //+------------------------------------------------------------------+
  23. int ddsl(int path)
  24. {
  25.    int a=0;
  26.    int ddzs=mt5ctp::MT5PositionsTotal();
  27.    for(int i=0; i<ddzs; i++)
  28.      {
  29.       ulong ticket = 0;
  30.       mt5ctp::MT5PositionGetTicket(i,ticket);
  31.       MT5CTPOrders order_mt5;
  32.       ZeroMemory(order_mt5);
  33.       if(!mt5ctp::MT5PositionSelectByTicket(ticket,order_mt5))
  34.          continue;
  35.       string pos_symbol = ::CharArrayToString(order_mt5.symbol);
  36.       int digit_symbol = (int)::SymbolInfoInteger(pos_symbol,SYMBOL_DIGITS);

  37.       if(order_mt5.type==path)
  38.         {
  39.          a++;
  40.         }
  41.       //Print("编号=",i);
  42.       //Print("品种=",pos_symbol);
  43.       //Print("订单号=",order_mt5.ticket);
  44.       //Print("开仓时间=",order_mt5.time);
  45.       //Print("持仓方向=",order_mt5.type);
  46.       //Print("开仓量=",order_mt5.volume);
  47.       //Print("开仓价=",order_mt5.price,digit_symbol);
  48.       //Print("止损价=",order_mt5.sl,digit_symbol);
  49.       //Print("止盈价=",order_mt5.tp,digit_symbol);
  50.       //Print("盈亏=",order_mt5.profit);
  51.       //Print("魔术码=",order_mt5.magic);
  52.       //Print("注释=",CharArrayToString(order_mt5.comment));
  53.      }
  54.      
  55.   return(a);
  56. }
复制代码


+10
要有能够持续稳定盈利的交易策略,再进行实盘交易,建议先用历史数据回测和模拟盘进行仔细验证。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

EA邦和EACTP仅为EA程序化交易软件服务供应商,使用EA工具进行交易,在使用前应该清楚的阅读和浏览软件相关的教程,使用软件是一种自发行为,所引发的一切法律后果,包括用户在使用过程中导致的任何损失均与EA软件开发者无关。
  • 微信

  • 微信公众号

  • 微信视频号

  • Powered by Discuz! X3.5 | Copyright © 2017-2024, Tencent Cloud. | EABANG.COM
  • 和仲科技有限公司| 川公网安备 51019002005489号 | 蜀ICP备17026493号