MT5CTP的视频教学可以到网站上关于我们栏目的EA邦的各视频平台里观看。
这是第9课的代码:
这是最开始出现的获取订单数据的脚本:
- //+------------------------------------------------------------------+
- //| Copyright 2020, EA邦 |
- //| http://www.eabang.com |
- //+------------------------------------------------------------------+
- #define __MT5CTP__
- // 包含库
- #ifdef __MT5CTP__
- #include <mt5ctp\mt5toctp.mqh>
- #endif
- #property copyright "Copyright 2021, MetaQuotes Ltd."
- #property link "https://www.eabang.com"
- #property version "1.00"
- //+------------------------------------------------------------------+
- //| Script program start function |
- //+------------------------------------------------------------------+
- void OnStart()
- {
- //---
- int ddzs=mt5ctp::MT5PositionsTotal();
- for(int i=0; i<ddzs; i++)
- {
- ulong ticket = 0;
- mt5ctp::MT5PositionGetTicket(i,ticket);
- MT5CTPOrders order_mt5;
- ZeroMemory(order_mt5);
- if(!mt5ctp::MT5PositionSelectByTicket(ticket,order_mt5))
- continue;
- string pos_symbol = ::CharArrayToString(order_mt5.symbol);
- int digit_symbol = (int)::SymbolInfoInteger(pos_symbol,SYMBOL_DIGITS);
- Print("编号=",i);
- Print("品种=",pos_symbol);
- Print("订单号=",order_mt5.ticket);
- Print("开仓时间=",order_mt5.time);
- Print("持仓方向=",order_mt5.type);
- Print("开仓量=",order_mt5.volume);
- Print("开仓价=",order_mt5.price,digit_symbol);
- Print("止损价=",order_mt5.sl,digit_symbol);
- Print("止盈价=",order_mt5.tp,digit_symbol);
- Print("盈亏=",order_mt5.profit);
- Print("魔术码=",order_mt5.magic);
- Print("注释=",CharArrayToString(order_mt5.comment));
- }
- }
- //+------------------------------------------------------------------+
复制代码 文件下载:
获取账户订单信息.mq5
(3.45 KB, 下载次数: 6)
上面文件是脚本,应该放到mt5的scripts的脚本目录,该目录跟ea目录一样,在mql目录下面,具体可以看ea安装教学。
这是双均线EA到目前为止的代码:
- //+------------------------------------------------------------------+
- //| Copyright 2020, EA邦 |
- //| http://www.eabang.com |
- //+------------------------------------------------------------------+
- #define __MT5CTP__
- // 包含库
- #ifdef __MT5CTP__
- #include <mt5ctp\mt5toctp.mqh>
- #endif
- #property copyright "Copyright 2021, MetaQuotes Ltd."
- #property link "https://www.eabang.com"
- #property version "1.00"
- //--- input parameters
- input int 短均线=5;
- input int 长均线=10;
- input double 开仓量=1.0;
- input int 止盈=100;
- input int 止损=100;
- //+------------------------------------------------------------------+
- //| Expert initialization function |
- //+------------------------------------------------------------------+
- int OnInit()
- {
- //--- create timer
- EventSetTimer(60);
- //---
- return(INIT_SUCCEEDED);
- }
- //+------------------------------------------------------------------+
- //| Expert deinitialization function |
- //+------------------------------------------------------------------+
- void OnDeinit(const int reason)
- {
- //--- destroy timer
- EventKillTimer();
- }
- //+------------------------------------------------------------------+
- //| Expert tick function |
- //+------------------------------------------------------------------+
- void OnTick()
- {
- //---
- int ddsl=0;
- int ddzs=mt5ctp::MT5PositionsTotal();
- for(int i=0; i<ddzs; i++)
- {
- ulong ticket = 0;
- mt5ctp::MT5PositionGetTicket(i,ticket);
- MT5CTPOrders order_mt5;
- ZeroMemory(order_mt5);
- if(!mt5ctp::MT5PositionSelectByTicket(ticket,order_mt5))
- continue;
- string pos_symbol = ::CharArrayToString(order_mt5.symbol);
- int digit_symbol = (int)::SymbolInfoInteger(pos_symbol,SYMBOL_DIGITS);
- if(order_mt5.type==0)
- {
- ddsl++;
- }
- //Print("编号=",i);
- //Print("品种=",pos_symbol);
- //Print("订单号=",order_mt5.ticket);
- //Print("开仓时间=",order_mt5.time);
- //Print("持仓方向=",order_mt5.type);
- //Print("开仓量=",order_mt5.volume);
- //Print("开仓价=",order_mt5.price,digit_symbol);
- //Print("止损价=",order_mt5.sl,digit_symbol);
- //Print("止盈价=",order_mt5.tp,digit_symbol);
- //Print("盈亏=",order_mt5.profit);
- //Print("魔术码=",order_mt5.magic);
- //Print("注释=",CharArrayToString(order_mt5.comment));
- }
-
- Print("多单数量=",ddsl);
- }
- //+------------------------------------------------------------------+
- //| Timer function |
- //+------------------------------------------------------------------+
- void OnTimer()
- {
- //---
- }
- //+------------------------------------------------------------------+
复制代码 EA文件下载:
双均线交叉_EA_v1.0.mq5
(6.54 KB, 下载次数: 4)
|