新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 - 页 695

 
psyman:

由于某些原因,我无法在15点钟方向开始的循环中抓到一个棒子。

如果我把if(i<24)写成一个条件,日志就会显示当天每个柱子的时间,但所需的条件却没有得到满足。


你是在什么时间段运行该指标的?

 

在这两种情况下都是顺时针。

 
psyman:

这两种情况下的哨兵。

它是有效的。

//+------------------------------------------------------------------+
//|                                                     TestHour.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                             https://mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://mql5.com/ru/users/artmedia70"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
#property strict
//--- plot Hour
#property indicator_label1  "Hour"
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  #ifdef __MQL4__ 2 #else 6 #endif 
//--- input parameters
input uchar    InpHour  =  15;   // The required hour
//--- indicator buffers
double         BufferHour[];
//--- global variables
int            hour_req;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- set global variables
   hour_req=int(InpHour>23 ? 23 : InpHour);
//--- indicator buffers mapping
   SetIndexBuffer(0,BufferHour,INDICATOR_DATA);
//--- setting indicator parameters
   IndicatorSetString(INDICATOR_SHORTNAME,"Hour("+(string)hour_req+")");
#ifdef __MQL4__
   SetIndexLabel(0,"Hour("+(string)hour_req+")");
#else 
   PlotIndexSetString(0,PLOT_LABEL,"Hour("+(string)hour_req+")");
   ArraySetAsSeries(BufferHour,true);
#endif 
   IndicatorSetInteger(INDICATOR_DIGITS,0);
//---
   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[])
  {
//--- Установка массивов буферов как таймсерий
#ifdef __MQL5__
   ArraySetAsSeries(time,true);
#endif 
//--- Проверка количества доступных баров
   if(rates_total<1) return 0;
//--- Проверка и расчёт количества просчитываемых баров
   int limit=rates_total-prev_calculated;
   if(limit>1)
     {
      limit=rates_total-1;
      ArrayInitialize(BufferHour,0);
     }
//--- Подготовка данных

//--- Расчёт индикатора
   for(int i=limit; i>=0 && !IsStopped(); i--)
     {
      int hour=GetTimeHour(time[i]);
      BufferHour[i]=(hour==hour_req ? (hour>0 ? hour : 0.1) : 0);
     }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Возвращает час указанного времени                                |
//+------------------------------------------------------------------+
int GetTimeHour(const datetime time)
  {
   #ifdef __MQL4__
   return TimeHour(time);
   #endif 
   MqlDateTime tm;
   if(!TimeToStruct(time,tm)) return WRONG_VALUE;
   return tm.hour;
  }
//+------------------------------------------------------------------+
 

谢谢你,但对于没有经验和知识负担的人来说,这太复杂了,简直是一团糟 :-)


BufferHour[i]=(hour==hour_req ? (hour>0 ? hour : 0.1) : 0);

为什么在向缓冲区传输数据时要做一个小时>0 的检查?如果不是这样,为什么要指定0.1?



我想在主图表上做高亮显示,但不是按行显示,而是按一周的 序号Mon, Wed, Wed...通过SetIndexArrow(0, 140);(也许有更简单的方法,但到目前为止没有其他办法),但由于某些原因,我不能使你的代码在主窗口中的四分之一处工作,而在五分之一处没有这样的属性。

 
psyman:

谢谢你,但对于没有经验和知识负担的人来说,这太复杂了,简直是一团糟 :-)


为什么在向缓冲区传输数据时要做一个小时>0检查?如果不是这样,为什么要指定0.1?



我想在主图表上做高亮显示,但不是按行显示,而是按一周的 序号Mon, Wed, Wed...通过SetIndexArrow(0, 140);(也许有更简单的方法,但到目前为止还没有想到),但由于某些原因,我不能使你的代码在主窗口中的四分之一处工作,而在五分之一处已经没有这样的属性。

缓冲区被填上了小时值。而如果小时为零,直方图将不会被画出来。因此,我们必须检查小时是否为零(我们在设置中设置为搜索零小时),如果是零,我们必须在缓冲区输入0.1,而不是小时值(零),以显示直方图栏。这将在数据窗口中显示一个0的值,而不是0.1,因为指标Digits被设置为零。

 
psyman:

谢谢你,但对于没有经验和知识负担的人来说,这太复杂了,简直是一团糟 :-)


为什么在向缓冲区传输数据时要做一个小时>0 的检查?如果不是这样,为什么要指定0.1?



我想在主图表上做高亮显示,但不是按行显示,而是按一周的 序号Mon, Wed, Wed...通过 SetIndexArrow(0, 140);(也许有更简单的方法,但到目前为止还没有想到),但由于某些原因,我不能使你的代码在主窗口中的四分之一处工作,而在五分之一处已经没有这样的属性

PlotIndexSetInteger(0,PLOT_ARROW,140)。

但你需要创建一个与周数相等的缓冲区。而每个缓冲区都有一个箭头代码,从140到149--1,2,3,4,5,6,7,8,9,10--十个星期足够一年了?这只有70天。或者你想怎么做?

 
祝大家今天愉快
请帮助我们!
这个用于MetaTrader 4的BB MACD指标是我从这里下载的https://www.mql5.com/en/code/9325
该指标分两个周期计算。
使用前一个MACD缓冲区的数据来计算布林线。

试图改变主周期的计数方向,在一个周期内一次性计算所有内容,同时摆脱
同时为了摆脱计算布林线时的额外周期,以惨败告终。
该指标产生的结果与未触及的同类指标相同,但在计算历史时疯狂地制动终端。
如果你把它放在一个月的时间范围内,你不会注意到它,但如果你把它放在15分钟内

我必须重新启动它。

我不能确定该如何处理它。

我可以问问谁能建议如何计算程序中最慢的位置?

提前感谢您的提示!


这是原文,下面是经过我修改的原文。

//+------------------------------------------------------------------+
//|                                               Custom BB_MACD.mq4 |
//|                                     Copyright © 2005, adoleh2000 |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+

#property  copyright "Copyright © 2005, adoleh2000"
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 4
#property  indicator_color1  Lime    //bbMacd up
#property  indicator_color2  Magenta //bbMacd up
#property  indicator_color3  Blue    //Upperband
#property  indicator_color4  Red     //Lowerband
//---- indicator parameters
extern int FastLen = 12;
extern int SlowLen = 26;
extern int Length = 10;
extern double StDv = 2.5;
//----
int loopbegin;
int shift;
double zeroline;
//---- indicator buffers
double ExtMapBuffer1[];  // bbMacd
double ExtMapBuffer2[];  // bbMacd
double ExtMapBuffer3[];  // Upperband Line
double ExtMapBuffer4[];  // Lowerband Line
//---- buffers
double bbMacd[];
double Upperband[];
double Lowerband[];
double avg[];
double bbMacdline;
double sDev;
double mean;
double sumSqr;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 6 additional buffers are used for counting.
   IndicatorBuffers(8);   
//---- drawing settings     
   SetIndexBuffer(0, ExtMapBuffer1); // bbMacd line
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexArrow(0, 108);
   IndicatorDigits(Digits + 1);
//----
   SetIndexBuffer(1, ExtMapBuffer2); // bbMacd line
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(1, 108);
   IndicatorDigits(Digits + 1);
//----   
   SetIndexBuffer(2, ExtMapBuffer3); // Upperband line
   SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 1);
   IndicatorDigits(Digits + 1);
//----   
   SetIndexBuffer(3, ExtMapBuffer4); // Lowerband line
   SetIndexStyle(3, DRAW_LINE, STYLE_SOLID, 1);
   IndicatorDigits(Digits + 1);
//----
   SetIndexBuffer(4, bbMacd);
   SetIndexBuffer(5, Upperband);        
   SetIndexBuffer(6, Lowerband);
   SetIndexBuffer(7, avg);    
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("BB MACD(" + FastLen + "," + SlowLen + "," + Length+")");
   SetIndexLabel(0, "bbMacd");
   SetIndexLabel(1, "Upperband");
   SetIndexLabel(2, "Lowerband");  
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom BB_MACD                                                   |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars = IndicatorCounted();
//---- check for possible errors
   if(counted_bars < 0) 
       return(-1);
//---- last counted bar will be recounted
   if(counted_bars > 0) 
       counted_bars--;
   limit = Bars - counted_bars;
//----
   for(int i = 0; i < limit; i++)
       bbMacd[i] = iMA(NULL, 0, FastLen, 0, MODE_EMA, PRICE_CLOSE, i) - 
                   iMA(NULL, 0, SlowLen, 0, MODE_EMA, PRICE_CLOSE, i);
//----
   for(i = 0; i < limit; i++)
     {
       avg[i] = iMAOnArray(bbMacd, 0, Length, 0, MODE_EMA, i);
       sDev = iStdDevOnArray(bbMacd, 0, Length, MODE_EMA, 0, i);  
       Upperband[i] = avg[i] + (StDv * sDev);
       Lowerband[i] = avg[i] - (StDv * sDev);
       ExtMapBuffer1[i]=bbMacd[i];     // Uptrend bbMacd
       ExtMapBuffer2[i]=bbMacd[i];     // downtrend bbMacd
       ExtMapBuffer3[i]=Upperband[i];  // Upperband
       ExtMapBuffer4[i]=Lowerband[i];  // Lowerband
       //----
       if(bbMacd[i] > bbMacd[i+1])
           ExtMapBuffer2[i] = EMPTY_VALUE;
       //----
       if(bbMacd[i] < bbMacd[i+1])
           ExtMapBuffer1[i] = EMPTY_VALUE;
     }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+


//================


//+------------------------------------------------------------------+
//|                                               Custom BB_MACD.mq4 |
//|                                     Copyright © 2005, adoleh2000 |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+

/*
Осторожно!!!
В том коде мной изменено направление расчёта главного цикла. Осторожно!!! Этот индикатор очень медленно выполняется!!! Его можно бросить только на недельный или месячный таймфрейм где в истории мало баров, если ниже 4х часов то терминал вешается!!! */
#property  copyright "Copyright © 2005, adoleh2000" #property  link      "http://www.metaquotes.net/" //---- indicator settings #property  indicator_separate_window #property  indicator_buffers 4 #property  indicator_color1  Lime    //bbMacd up #property  indicator_color2  Magenta //bbMacd up #property  indicator_color3  Blue    //Upperband #property  indicator_color4  Red     //Lowerband //---- indicator parameters extern int FastLen = 12; extern int SlowLen = 26; extern int Length = 10; extern double StDv = 2.5; //---- int loopbegin; int shift; double zeroline; //---- indicator buffers double ExtMapBuffer1[];  // bbMacd double ExtMapBuffer2[];  // bbMacd double ExtMapBuffer3[];  // Upperband Line double ExtMapBuffer4[];  // Lowerband Line //---- buffers double bbMacd[]; double Upperband[]; double Lowerband[]; double avg[]; double bbMacdline; double sDev; double mean; double sumSqr; //+------------------------------------------------------------------+ //| Custom indicator initialization function                         | //+------------------------------------------------------------------+ int init()   { //---- 6 additional buffers are used for counting.    IndicatorBuffers(8);   //---- drawing settings        SetIndexBuffer(0, ExtMapBuffer1); // bbMacd line    SetIndexStyle(0, DRAW_ARROW);    SetIndexArrow(0, 108);    IndicatorDigits(Digits + 1); //----    SetIndexBuffer(1, ExtMapBuffer2); // bbMacd line    SetIndexStyle(1, DRAW_ARROW);    SetIndexArrow(1, 108);    IndicatorDigits(Digits + 1); //----      SetIndexBuffer(2, ExtMapBuffer3); // Upperband line    SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 1);    IndicatorDigits(Digits + 1); //----      SetIndexBuffer(3, ExtMapBuffer4); // Lowerband line    SetIndexStyle(3, DRAW_LINE, STYLE_SOLID, 1);    IndicatorDigits(Digits + 1); //----    SetIndexBuffer(4, bbMacd);    SetIndexBuffer(5, Upperband);            SetIndexBuffer(6, Lowerband);    SetIndexBuffer(7, avg);     //---- name for DataWindow and indicator subwindow label    IndicatorShortName("BB MACD-2(" + FastLen + "," + SlowLen + "," + Length+")");    SetIndexLabel(0, "bbMacd");    SetIndexLabel(1, "Upperband");    SetIndexLabel(2, "Lowerband");            //---- initialization done    return(0);   } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function                       | //+------------------------------------------------------------------+ int deinit()   { //----    return(0);   } //+------------------------------------------------------------------+ //| Custom BB_MACD                                                   | //+------------------------------------------------------------------+ int start()   {    int limit, i,MaxPeriod;    int counted_bars = IndicatorCounted(); //---- check for possible errors    if(counted_bars < 0)        return(-1); //---- last counted bar will be recounted    if(counted_bars > 0)        counted_bars--;    limit = Bars - counted_bars;             if(counted_bars==0){              for(i=Bars-1; i>=1; i--) bbMacd[i]=0.0;//обнулим первый рассчитываемый массив              MaxPeriod= MathMax(MathMax(FastLen,SlowLen), Length);//это самые старые бары в истории которые не будем рассчитывать       limit=limit-MaxPeriod;    }    //      //---- основной цикл   for(i=limit; i>=1; i--){//ЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦ //В этом месте изменено направление пересчёта в основном цикле. //И все расчёты зависимых друг от друга буферов производятся последовательно  в одном цикле. //Дополнительный цикл расчета удалён.        bbMacd[i] = iMA(NULL, 0, FastLen, 0, MODE_EMA, PRICE_CLOSE, i) -                    iMA(NULL, 0, SlowLen, 0, MODE_EMA, PRICE_CLOSE, i);                           avg[i] = iMAOnArray(bbMacd, 0, Length, 0, MODE_EMA, i);        sDev = iStdDevOnArray(bbMacd, 0, Length, MODE_EMA, 0, i);          Upperband[i] = avg[i] + (StDv * sDev);        Lowerband[i] = avg[i] - (StDv * sDev);        ExtMapBuffer1[i]=bbMacd[i];     // Uptrend bbMacd        ExtMapBuffer2[i]=bbMacd[i];     // downtrend bbMacd        ExtMapBuffer3[i]=Upperband[i];  // Upperband        ExtMapBuffer4[i]=Lowerband[i];  // Lowerband        //----        if(bbMacd[i] > bbMacd[i+1])            ExtMapBuffer2[i] = EMPTY_VALUE;        //----        if(bbMacd[i] < bbMacd[i+1])            ExtMapBuffer1[i] = EMPTY_VALUE;      }//ЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦЦ //---- done    return(0);   } //+------------------------------------------------------------------+
BB MACD
BB MACD
  • www.mql5.com
BB_MACD Indicator.
 
Northwest:
祝大家今天愉快
请帮助我们!
这个用于MetaTrader 4的BB MACD指标是我从这里下载的https://www.mql5.com/en/code/9325
该指标分两个周期计算。
使用前一个MACD缓冲区的数据来计算布林线。

试图改变主周期的计数方向,在一个周期内一次性计算所有内容,同时摆脱
同时为了摆脱计算布林线时的额外周期,以惨败告终。
该指标产生的结果与未触及的同类指标相同,但在计算历史时疯狂地制动终端。
如果你把它放在一个月的时间范围内,你不会注意到它,但如果你把它放在15分钟内

我必须重新启动它。

我不能确定该如何处理它。

我可以问问谁能建议如何计算程序中最慢的位置?

提前感谢您的提示!


这是原文,下面是经过我修改的原文。


//================


全部交还,不要折磨电脑

为存储在数组中的数据计算的iBandsOnArray, iStdDevOnArray

另一方面,数组在1个循环中被填充

 
Alekseu Fedotov:

把所有东西放回去,不要折磨电脑

为存储在数组中的数据计算的iBandsOnArray, iStdDevOnArray

另一方面,一个数组在1个周期内被填充。

1.把所有东西放回去,不要折磨你的电脑

对不起,但你不会拿回来的。 你必须让指标从左到右数。

我不是在打扰他,我是在利用他达到他的目的。

2.使用存储在阵列中的数据计算的iBandsOnArray、iStdDevOnArray

是的,它们是用bbMacd[]数组的数据计算出来的,那么接下来呢?

3.数组在一个循环中被填充

在一个还是在第一个?

你是说,为了填充一个数组,你需要一个个人循环,在这个循环中填充这个数组

阵列被填满,不能进行其他操作?


对我来说,重要的是找出指标变慢的原因,以及如何计算那些发生这种情况的地方。

我有更多的问题,但没有答案。

不幸的是,你没有提供任何线索。

 

当EA时间框架改变时,我如何禁止重新初始化?


这里有一些信息。

EA运行OnDeinit和OnInit,全局类对象没有 变化。

https://www.mql5.com/ru/forum/170952/page61#comment_6132824


对于mql4来说,这也是正确的吗?

原因: