初学者的问题 MQL5 MT5 MetaTrader 5 - 页 602

 
Karputov Vladimir:
在一个指标中还是在一个EA/脚本中?
在一个指标中。
 

Yuri Evseenkov:

frommme2you:

另一个问题:如何强调MT4和MQL代码执行环境的开发者,使他(他们)在开发处理异常的语言上花心思,如我的例子或类似的意思?


联系服务台,在论坛上创建一个主题/调查。

不久前,MT4还被埋没了。他们对市场没有明确的看法,他们对市场的监管有明确的看法。

Renat 今天的帖子

雷纳特-法特库林

...

MT4的开发已经停止,只会有修复和美容。

 
Alex:

你好。能否请您告知如何解决这个问题。我需要通过分析过去的50个条形图,找到某个时间段的条形图的开盘价,比如说01:00。我不知道如何在mql5中进行这项工作。


是否通过计算当前日期+将所需时间加入其中,然后加入二十四小时,这种方法在mql4上起作用。

据我所知,mql5有特殊的结构,有时间输出,但由于某些原因我不能使用它们。

提前感谢您的回答。

如果有人能扔给我一点代码以了解思考过程,我将非常感激。
亚历克斯
在指标中。

在这里,为了更好地理解,我建议首先看一下条形图的编号。首先,我们需要确切地了解MQL5指标中最右边的柱子是如何编号的。

要做到这一点,请在OnCalculate的指标中加入以下注释。

//+------------------------------------------------------------------+
//|                                                         test.mq5 |
//|                              Copyright © 2016, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
#property  indicator_type1   DRAW_LINE
#property  indicator_color1  Blue
//--- indicator buffers
double Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Buffer,INDICATOR_DATA);
//---
   ArrayInitialize(Buffer,1);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---
   Comment("rates_total=",IntegerToString(rates_total),
           ", time[rates_total-1]=",TimeToString(time[rates_total-1],TIME_DATE|TIME_MINUTES|TIME_SECONDS));

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

这段代码将产生这样的结果。

MQL5指标数组中的编号,默认为

也就是说,默认情况下,MQL5指标数组中最右边的条形图的索引等于 "rate_total-1"。

回到你的问题--你需要把最后50个小节,通过它们。并分析条形图的开盘时间(time[]数组),如果条形图的时间等于指定的时间,记住条形图的索引。然后从open[]数组中检索出开盘价。

它看起来与此类似。

//+------------------------------------------------------------------+
//|                                                         test.mq5 |
//|                              Copyright © 2016, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
#property indicator_chart_window
#property indicator_plots   0
//--- input parameters
input datetime time_open=D'01:00';     // время искомого бара
//--- parameters
int open_hour;                         // время искомого бара (часы)
int open_min;                          // время искомого бара (минуты)
bool first_start=false;                // false - значит бары ещё не искались
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   MqlDateTime str1;
   TimeToStruct(time_open,str1);
   open_hour=str1.hour;
   open_min=str1.min;
//---
   first_start=false;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---
//Comment("rates_total=",IntegerToString(rates_total),
//        ", time[rates_total-1]=",TimeToString(time[rates_total-1],TIME_DATE|TIME_MINUTES|TIME_SECONDS));
   if(!first_start)
     {
      int index=-1;
      for(int i=rates_total-1;i>rates_total-1-50;i--)
        {
         MqlDateTime str2;
         TimeToStruct(time[i],str2);
         if(str2.hour==open_hour && str2.min==open_min)
           {
            index=i;
            first_start=true;
            Print("Бар ",IntegerToString(i)," имеет время открытия ",TimeToString(time[i],TIME_DATE|TIME_MINUTES|TIME_SECONDS),
                  " и цену открытия ",DoubleToString(open[i],Digits()));
           }
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Karputov Vladimir:

在这里,为了让你以后更好地理解,我建议你先看一下条形图的编号。也就是说,你应该首先了解MQL5指标中最右边的柱子到底是如何编号的。

要做到这一点,在OnCalculate的指标中加入以下注释。

这段代码将产生这样的结果。


也就是说,默认情况下,MQL5指标数组中最右边的条形图的索引等于 "rate_total-1"。

回到你的问题上--你需要把最后50个小节,通过它们。并分析条形图的开盘时间(time[]数组),如果条形图的时间等于指定的时间,记住条形图的索引。然后从open[]数组中检索出开盘价。

它看起来大约是这样的

卡尔普托夫-弗拉基米尔, 非常感谢你。我会处理好的。我认为mql5对时间序列的访问更加灵活,但对于 "新手 "程序员来说,它有点复杂。:))
 
Alex:
卡尔普托夫-弗拉基米尔, 非常感谢你。我真的很感激。我认为mql5对时间序列的访问更加灵活,但对于 "新手 "程序员来说,它有点复杂。:))
这是一个习惯的问题。然后你就会明白,一切都有条不紊,简单而正确。
 
Karputov Vladimir:
这是一个习惯问题。然后你会发现,一切都有条不紊,简单而正确。

另一个问题。参数

const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])


我认为他们对指标所适用的配对负责。所以,不可能获得另一个货币对的相同信息? 换句话说,更普遍的解决方案是只通过Copy函数创建相同的OCHL数组...?
 
Alex:

另一个问题。参数

我理解,他们对应用该指标的配对负责。那么,更普遍的解决方案是通过复制函数创建相同的数组OCHL...?
在访问其他人的符号时,有一些细微的差别是你需要了解和注意的:数据访问的组织。换句话说,如果你请求别人的符号的时间序列数据--你必须首先确保这些数据是准备好的并且存在。这是确定从别人的符号中要求的数据是正确的唯一方法。
 
Karputov Vladimir:
在访问他人的字符时,有一些细微的差别是你需要了解和注意的:组织数据访问。换句话说,如果你请求别人的符号时间序列数据--你必须首先确保这些数据已经被准备好并且存在。只有这样,你才能确定你向外星角色请求的数据是正确的。

明白了。谢谢你。

还有一个问题,你是否总是在Print()函数中把数值转换成字符串类型。这样做的目的是什么?没有翻译,int、double等类型在Print()函数中的显示方式完全相同。

 
Alex:

明白了。谢谢你。

另一个问题,你是否总是在Print()函数中把数值转换成字符串类型。这样做的目的是什么?没有翻译,int、double等类型在Print()中的显示方式完全相同。

一个数字在计算机内存中的存储方式和它的输出方式是两个很大的区别。特别是对于浮点数,最好是限制小数点的数量。

这就是为什么我总是试图正确地格式化输出 - 使用IntegerToStringDoubleToString

 
Karputov Vladimir:

一个数字在计算机内存中的存储方式和它的输出方式是两个很大的区别。特别是对于浮点数,最好是限制小数点的数量。

这就是为什么我总是试图使用IntegerToStringDoubleToString来 正确格式化数字输出。

谢谢你的回答和耐心。


弗拉基米尔,我可能已经厌倦了你 :)但基础工作的进展却非常缓慢。我试图用复制功能做一个测试任务...指标没有画出来,尽管在普林特有数字。我什么都不明白。


//+------------------------------------------------------------------+
//|                                                        Bars.mq5 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot UpBar
#property  indicator_label1  "UpBar"
#property  indicator_type1   DRAW_HISTOGRAM
#property  indicator_color1  clrGreen
#property  indicator_style1  STYLE_SOLID
#property  indicator_width1  6
//--- plot DnBar
#property  indicator_label2  "DnBar"
#property  indicator_type2   DRAW_HISTOGRAM
#property  indicator_color2  clrRed
#property  indicator_style2  STYLE_SOLID
#property  indicator_width2  6
//--- input parameters
input int   Histori=30;
input ENUM_TIMEFRAMES TimeFrame=0; 
input string  Simvol="EURUSD";
//--- indicator buffers
double         UpBar[];
double         DnBar[];
double         O_Price[];
double         C_Price[];



  
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,UpBar,INDICATOR_DATA);
   SetIndexBuffer(1,UpBar,INDICATOR_DATA);
   SetIndexBuffer(2,O_Price,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,C_Price,INDICATOR_CALCULATIONS);



   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
 {
ArraySetAsSeries(O_Price,true);
ArraySetAsSeries(C_Price,true);
CopyOpen(Simvol,TimeFrame,0,Histori,O_Price);
CopyClose(Simvol,TimeFrame,0,Histori,C_Price);

     for (int t=3; t<Histori; t++) 
       {
          UpBar[t]=MathAbs(NormalizeDouble((O_Price[t]-C_Price[t]),Digits()));   
          Print(DoubleToString(UpBar[t],Digits()));
       }

   return(rates_total);
  }