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

 
yiduwi:

谢谢你,你能告诉我为什么箭头放在第二个柱子上而不是第一个柱子上吗?

所以你把箭头放在第二条上,而不是放在第一条上--它不会自己画出来,对吗?)))

你肯定在这里多加了一个 BufferDN[i+1]=high[i+1]。

 
Igor Makanu:

所以你把箭头放在第二条上,而不是放在第一条上--它不会自己画出来,对吗?)))

我猜你一定在这里多加了一个 BufferDN[i+1]=high[i+1]。

呃,没有那个,一般情况下,箭头放在第三条上,代码小,我哪里搞砸了?

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot UP
#property indicator_label1  "UP"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrLawnGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot DN
#property indicator_label2  "DN"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrDeepPink
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1

//--- indicator buffers
double         BufferUP[];
double         BufferDN[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,BufferUP);
   SetIndexBuffer(1,BufferDN);
   PlotIndexSetInteger(0,PLOT_ARROW,233);
   PlotIndexSetInteger(1,PLOT_ARROW,234);

//---

   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[])
  {
//---
   if(rates_total<3) return(0);
   int limit=rates_total-prev_calculated;
   if(limit>1)
     {
      limit=rates_total-3;
      ArrayInitialize(BufferUP,EMPTY_VALUE);
      ArrayInitialize(BufferDN,EMPTY_VALUE);
     }
   for(int i=limit; i>=0; i--)
     {
      if (fabs(high[i+1]-high[i+2]) <= 0.0*_Point)
        {
         BufferDN[i]=high[i];
        }
     }
//--- return value of prev_calculated for next call

   return(rates_total);
  }
如果是这样的话,它就会进入第一条。
BufferDN[i+2]=high[i+2];
我不明白。
 
Igor Makanu:

这是解决方案,但我认为没有任何东西是我考虑过的。

逻辑上说这是正确的。

 
yiduwi:

唉,没有单位,一般来说,箭头放在第三条上,代码小,我哪里弄错了?

它被放在第一条上,如果是这样的话,我就不明白了。

可能是这样,但我没有在MT5下写,我可能是错的。

//+------------------------------------------------------------------+
//|                                                          tst.mq5 |
//|                                                            IgorM |
//|                              https://www.mql5.com/ru/users/igorm |
//+------------------------------------------------------------------+
#property copyright "IgorM"
#property link      "https://www.mql5.com/ru/users/igorm"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot UP
#property indicator_label1  "UP"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrLawnGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot DN
#property indicator_label2  "DN"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrDeepPink
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1

input int Pips=5;
//--- indicator buffers
double         BufferUP[];
double         BufferDN[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,BufferUP);
   SetIndexBuffer(1,BufferDN);
   PlotIndexSetInteger(0,PLOT_ARROW,233);
   PlotIndexSetInteger(1,PLOT_ARROW,234);
//---
   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[])
  {
//---
   int limit=rates_total-prev_calculated;
   if(limit>1 || prev_calculated==0)
     {
      limit=rates_total-2;
      ArrayInitialize(BufferUP,EMPTY_VALUE);
      ArrayInitialize(BufferDN,EMPTY_VALUE);
     }
   for(int i=limit; i>=0; i--)
     {
      if(fabs(high[i+1]-high[i])<=_Point*(double)Pips) BufferDN[i]=high[i];
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Igor Makanu:

可能是这样,但我不在MT5下写作,我可能是错的。

另外,在第二条把我)

 
Igor Makanu:

谢谢,这就是其中的一个错误,但还是搞不清楚如何从159,002秒到44小时10分2秒(在线计算器 )。)


这是解决方案,但我认为我错过了一些东西

2019.06.18 11:46:22.691 tstss EURUSD,H1: h = 44 , m = 10 , s = 2

在我看来,似乎更简单

 int timeinsec = 159002;
 int sec = timeinsec%60;
 int min = ((timeinsec-sec)%3600)/60;
 int hou = (timeinsec-sec-min)/3600;
 
yiduwi:

另外,在第二条把我)

箭头应该只放在条件满足的地方,对了,我记得MT5最好有一个完整的松弛条件。

if(fabs(high[i+1]-high[i])<=_Point*(double)Pips) BufferDN[i]=high[i]; else BufferDN[i]=EMPTY_VALUE;
阿列克谢-维克多罗夫

我认为这比较容易。

找到了!谢谢你!这正是我想要的。

 
有一些代码有大量的Print调用。有没有什么方法可以在不删除代码的情况下快速关闭它们? 这是我目前看到的唯一选择。
bool L=true;
if(L)Print("123");

即用 "if(L)Print("替换所有的 "Print(",也许还有一些其他的选项?

 
pivomoe:
有一些代码,其中有大量的Print调用。有没有什么方法可以在不从代码中删除打印的情况下快速禁用它们? 到目前为止,我只看到这个选项。

即用 "if(L)Print("取代所有的 "Print(",也许还有一些其他的选项?

在输入参数中输出 "打印 "标志。它将像你的代码一样工作,但标志本身(bool变量)将在输入参数中。

 

你好!

在MT5测试器中通过所有符号进行优化,拒绝工作...

能否请您指点我如何使其发挥作用?

谢谢你。

原因: