本例子演示了EA如何获得期货的持仓。
EA是通过调用mt5ctp.dll进行期货交易,所以EA需要先引用mt5ctp.dll,该DLL头文件mt5ctp.mqh在\MQL5\Include目录下。
#property copyright "www.wewin28.com 1145412@qq.com"
#property link "http://www.wewin28.com"
#property version "1.00"
#include <mt5ctp.mqh>
ushort splitCommma=StringGetCharacter(",",0);
EA通过mt5ctp.dll得到交易所的各种回调(如报单回调,成交回调,撤单回调,错误回调,仓位回调,资金回调),然后会把这些回调作为MQL图表事件发送给全部图表,EA 通过MQL中的图表事件响应函数OnChartEvent得到这些回调,所以EA需要在OnChartEvent函数中只处理ID是3000的事件。
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{