比如,我想创建前天中午12点的1分钟或3分钟的时间周期图表在主窗口下方的子窗口,请问要调用哪些函数?可以给个参考吗?
hini:
比如,我想创建前天中午12点的1分钟或3分钟的时间周期图表在主窗口下方的子窗口,请问要调用哪些函数?可以给个参考吗?
比如,我想创建前天中午12点的1分钟或3分钟的时间周期图表在主窗口下方的子窗口,请问要调用哪些函数?可以给个参考吗?
获取行情
copyopen, copyclose,copyhigh,copylow
直接代入指标中,指标类型是K线
DRAW_CANDLES 帮助里面有例子 hini:
比如,我想创建前天中午12点的1分钟或3分钟的时间周期图表在主窗口下方的子窗口,请问要调用哪些函数?可以给个参考吗?
比如,我想创建前天中午12点的1分钟或3分钟的时间周期图表在主窗口下方的子窗口,请问要调用哪些函数?可以给个参考吗?
//+------------------------------------------------------------------+ //| other_time.mq5 | //| 这个指标修改自 MT5 帮助手册. | //+------------------------------------------------------------------+ #property copyright "Copyright 2023, 这个指标修改自 MT5 帮助手册." #property link " " #property version "1.00" #property description "An indicator to demonstrate DRAW_CANDLES." #property description "It draws candlesticks of a selected symbol in a separate window" #property description " 在副图中显示另一个品种 K 线。" #property description "The color and width of candlesticks, as well as the symbol are changed" #property description "randomly every N ticks" #property indicator_separate_window #property indicator_buffers 4 #property indicator_plots 1 //--- 标图柱形 #property indicator_label1 "DRAW_CANDLES1" #property indicator_type1 DRAW_CANDLES #property indicator_color1 clrGreen,clrWhite,clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- 输入参数 //--- 交易品种名称 input string symbol="XAUUSD"; input datetime start=__DATETIME__; input ENUM_TIMEFRAMES period=PERIOD_CURRENT; input int N=5; // 改变类型的订单号数量 input int bars=500; // 显示的柱形数量 input bool messages=false; // 在"EA交易"日志显示信息 //--- 指标缓冲区 double CandleOpen[]; double CandleHigh[]; double CandleLow[]; double CandleClose[]; //--- 存储颜色的数组0到5的 color colors[]={clrRed,clrBlue,clrGreen,clrPurple,clrBrown,clrIndianRed}; //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| 自定义指标初始化函数 | //+------------------------------------------------------------------+ int OnInit() { //--- 如果柱形非常小 - 提前完成工作 if(bars<50) { Comment("Please specify a larger number of bars! The operation of the indicator has been terminated"); return(INIT_PARAMETERS_INCORRECT); } //--- 指标缓冲区映射 SetIndexBuffer(0,CandleOpen,INDICATOR_DATA); SetIndexBuffer(1,CandleHigh,INDICATOR_DATA); SetIndexBuffer(2,CandleLow,INDICATOR_DATA); SetIndexBuffer(3,CandleClose,INDICATOR_DATA); //--- 空值 PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0); //--- 绘制柱形的交易品种名称 //symbol=_Symbol; //--- 设置交易品种的展示 PlotIndexSetString(0,PLOT_LABEL,symbol+" Open;"+symbol+" High;"+symbol+" Low;"+symbol+" Close"); IndicatorSetString(INDICATOR_SHORTNAME,"DRAW_CANDLES("+symbol+")"); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 自定义指标迭代函数 | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { static int ticks=INT_MAX-100; //--- 计算订单号改变样式,颜色和线型宽度 ticks++; //--- 如果足够数量的订单号被积累 if(ticks>=N) { //--- 选择来自市场报价窗口的新交易品种 int tries=0; //--- 试图5 次填充缓冲区plot1的交易品种价格 while(!CopyFromSymbolToBuffers(symbol,rates_total,0, CandleOpen,CandleHigh,CandleLow,CandleClose) && tries<5) { //--- CopyFromSymbolToBuffers() 函数调用的计数器 tries++; } //--- 重置0计数器 ticks=0; } //--- 返回 prev_calculated值以便下次调用函数 return(rates_total); } //+------------------------------------------------------------------+ //| 填充指定蜡烛图 | //+------------------------------------------------------------------+ bool CopyFromSymbolToBuffers(string name, int total, int plot_index, double &buffOpen[], double &buffHigh[], double &buffLow[], double &buffClose[] ) { //--- 在rates[] 数组中,我们将复制开盘价,最高价,最低价和收盘价 MqlRates rates[]; //--- 尝试计数器 int attempts=0; //--- 已复制多少 int copied=0; //--- 试图25次获得所需交易品种的时间帧 while(attempts<25 && (copied=CopyRates(name,period,start,bars,rates))<0) { Sleep(100); attempts++; if(messages) PrintFormat("%s CopyRates(%s) attempts=%d",__FUNCTION__,name,attempts); } //--- 如果复制足够数量的柱形失败 if(copied!=bars) { //--- 形成信息字符串 string comm=StringFormat("For the symbol %s, managed to receive only %d bars of %d requested ones", name, copied, bars ); //--- 在主图表窗口的注释中显示信息 Comment(comm); //--- 显示信息 if(messages) Print(comm); return(false); } else { //--- 设置交易品种的展示 PlotIndexSetString(plot_index,PLOT_LABEL,name+" Open;"+name+" High;"+name+" Low;"+name+" Close"); } //--- 初始化空值缓冲区 ArrayInitialize(buffOpen,0.0); ArrayInitialize(buffHigh,0.0); ArrayInitialize(buffLow,0.0); ArrayInitialize(buffClose,0.0); //--- 在每个订单号上复制缓冲区价格 for(int i=0;i<copied;i++) { //--- 计算缓冲区相应的标引 int buffer_index=total-copied+i; //--- 写下缓冲区的价格 buffOpen[buffer_index]=rates[i].open; buffHigh[buffer_index]=rates[i].high; buffLow[buffer_index]=rates[i].low; buffClose[buffer_index]=rates[i].close; } return(true); } //+------------------------------------------------------------------+ // //+------------------------------------------------------------------+