MT5CTP的视频教学可以到网站上关于我们栏目的EA邦的各视频平台里观看。
这是第10课的代码:EA文件代码:
双均线交叉_EA_v1.0.mq5
(5.94 KB, 下载次数: 8)
- //+------------------------------------------------------------------+
- //| 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()
- {
- //---
- if(ddsl(0)==0)
- {
- //定义均线交叉
- }
- Print("多单数量=",ddsl(0));
- Print("空单数量=",ddsl(1));
- }
- //+------------------------------------------------------------------+
- //| Timer function |
- //+------------------------------------------------------------------+
- void OnTimer()
- {
- //---
- }
- //+------------------------------------------------------------------+
- int ddsl(int path)
- {
- int a=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==path)
- {
- a++;
- }
- //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));
- }
-
- return(a);
- }
复制代码
脚本文件代码:
测试脚本.mq5
(3.85 KB, 下载次数: 0)
- #define __MT5CTP__
- // 包含库
- #ifdef __MT5CTP__
- #include <mt5ctp\mt5toctp.mqh>
- #endif
- //+------------------------------------------------------------------+
- //| Copyright 2020, EA邦 |
- //| http://www.eabang.com |
- //+------------------------------------------------------------------+
- #property copyright "Copyright 2021, MetaQuotes Ltd."
- #property link "https://www.mql5.com"
- #property version "1.00"
- //+------------------------------------------------------------------+
- //| Script program start function |
- //+------------------------------------------------------------------+
- void OnStart()
- {
- //---
- Print("多单数量=",ddsl(0));
- Print("空单数量=",ddsl(1));
- }
- //+------------------------------------------------------------------+
- int ddsl(int path)
- {
- int a=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==path)
- {
- a++;
- }
- //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));
- }
-
- return(a);
- }
复制代码
|