基础的市场信息获取 :时间 高开敌手价 成绩量 k线序列
void Test()
{
int shift = 0;
datetime time = iTime(Symbol(),Period(),shift);
double open = iOpen(Symbol(),Period(),shift);
double high = iHigh(Symbol(),Period(),shift);
double low = iLow(Symbol(),Period(),shift);
double close = iClose(NULL,PERIOD_CURRENT,shift);
long volume= iVolume(Symbol(),0,shift);
int bars = iBars(NULL,0);
Comment(Symbol(),",",EnumToString(Period()),"\n",
"Time: ",TimeToString(time,TIME_DATE|TIME_SECONDS),"\n",
"Open: ",DoubleToString(open,Digits()),"\n",
"High: ",DoubleToString(high,Digits()),"\n",
"Low: ",DoubleToString(low,Digits()),"\n",
"Close: ",DoubleToString(close,Digits()),"\n",
"Volume: ",IntegerToString(volume),"\n",
"Bars: ",IntegerToString(bars),"\n"
);
}
获取开盘价数组,CopyOpen函数获取开盘价数据 赋值给open数组,
函数第三个 第四个参数是开始和结束k线排序,open获取的数据是倒着的
调用ArraySetAsSeries函数,设置open数组方向才得到正序数据(去看函数文档就更好理解)
double open[];
//设置数组方向 很重要
ArraySetAsSeries(open, true);
CopyOpen(Symbol(),Period(),0,10,open);
Print(open[0]);
写一个数据data类
封装获取数据函数
//+------------------------------------------------------------------+
//| ProjectName |
//| Copyright 2020, CompanyName |
//| http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
class OwnMarketData
{
public:
string symbol;
double open[];//开盘价数组
double maINDI[];//ma 指标数据数组
OwnMarketData(string symbol)
{
this.symbol = symbol;
}
~OwnMarketData()
{
}
double getAsk()
{
return SymbolInfoDouble(this.symbol, SYMBOL_ASK);
}
double getAsk(string symbol)
{
return SymbolInfoDouble(symbol, SYMBOL_ASK);
}
//获取开盘价数组
int getOpenData(string 品种,ENUM_TIMEFRAMES 时间周期,int 起始位置, int 数量)
{
//double open[];
//设置数组方向 很重要
ArraySetAsSeries(open, true);
int openNum =CopyOpen(品种,时间周期,起始位置,数量,open);
//openNum 返回数据长度
return openNum;
}
//---获取ma指标数据
void getEMaINDIData(string 品种,ENUM_TIMEFRAMES 时间周期,int 周期总数, int 起始位置, int 数量)
{
int ma_h;
ArraySetAsSeries(maINDI,true);
ma_h = iMA(品种,时间周期,周期总数,0,MODE_EMA,PRICE_CLOSE);
CopyBuffer(ma_h,0,起始位置,数量,maINDI);
}
//---获取ma指标数据
void getEMaINDIData(string 品种,ENUM_TIMEFRAMES 时间周期,int 周期总数, int 起始位置, int 数量, double &ayyay[])
{
int ma_h;
ArraySetAsSeries(ayyay,true);
ma_h = iMA(品种,时间周期,周期总数,0,MODE_EMA,PRICE_CLOSE);
CopyBuffer(ma_h,0,起始位置,数量,ayyay);
}
};
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+