获取市场深度,比较重要,单独写一节。
//+------------------------------------------------------------------+
//| 获取市场深度信息.mq5 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
//订阅市场深度
MarketBookAdd(NULL);
//可以监控多个货币对
MarketBookAdd("USDCAD");
EventSetTimer(60);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
EventKillTimer();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
MqlBookInfo book[];
ArraySize(book);//获取数组大小
bool isGet = MarketBookGet(NULL,book);
Print(isGet);
Print(sizeof(book));
//取消对货币对的监控
MarketBookRelease("USDCAD");
//Print(book[0],'价',book[0]);
//Print(book[1].price,'价',book[1].volume,'格',book[1].volume_real);
//Print(book[2].price,'价',book[2].volume);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTimer()
{
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnBookEvent(const string &symbol)
{
Print(symbol,"OnBookEvent");
}
//+------------------------------------------------------------------+