void OnStart()
{
double buy1;
double sell1;
double buyvolume;
double sellvolume;
GetSymbolDOM("hc2310",buy1,buyvolume,sell1,sellvolume);
Print(buy1);
Print(buyvolume);
Print(sell1);
Print(sellvolume);
double buy2;
double sell2;
double buyvolume2;
double sellvolume2;
GetSymbolDOM("rb2310",buy2,buyvolume2,sell2,sellvolume2);
Print(buy2);
Print(buyvolume2);
Print(sell2);
Print(sellvolume2);
}
void GetSymbolDOM(string symbol, double &bidPrice, double &bidVolume, double &askPrice, double &askVolume)
{
MarketBookAdd(symbol);
MqlBookInfo priceArray[];
bool getBook = MarketBookGet(NULL, priceArray);
int size = ArraySize(priceArray);
if(getBook && size > 1)
{
if(priceArray[0].type == BOOK_TYPE_SELL || priceArray[1].type == BOOK_TYPE_BUY)
{
askPrice = priceArray[0].price;
askVolume = priceArray[0].volume;
bidPrice = priceArray[1].price;
bidVolume = priceArray[1].volume;
}
else
{
bidPrice = priceArray[0].price;
bidVolume = priceArray[0].volume;
askPrice = priceArray[1].price;
askVolume = priceArray[1].volume;
}
Print("Symbol: ", symbol, " Bid Price: ", bidPrice, ", Bid Volume: ", bidVolume,
" Ask Price: ", askPrice, " Ask Volume: ", askVolume);
}
else
{
Print("Could not get contents of the symbol DOM ",symbol);
}
}
2023.05.25 09:52:16.800 测试 (m2309,H1) Symbol: hc2310 Bid Price: 3435.0, Bid Volume: 2242.0 Ask Price: 3436.0 Ask Volume: 403.0
2023.05.25 09:52:16.800 测试 (m2309,H1) Symbol: rb2310 Bid Price: 3435.0, Bid Volume: 2242.0 Ask Price: 3436.0 Ask Volume: 403.0
老师,我想同时获取2个品种的买价买量,卖价卖量,获取第一个的时候正常,第二个获取不到,怎么怎么办呢?
|