初心者の方からの質問 MQL5 MT5 MetaTrader 5 - ページ 1065

 
yiduwi:

ありがとうございます。 なぜ、矢印が最初のバーではなく、2番目のバーに配置されているのか、教えてください。

つまり、2本目のバーに矢印を置き、1本目のバーには置かないということですが、勝手に描画されるわけではありませんよね?)))

ここで余分に追加したのでしょう BufferDN[i+1]=high[i+1];

 
Igor Makanu:

ということは、矢印を2本目のバーに置いて、1本目のバーには置かないということですね、勝手に描画されませんよね?)))

ここで余計なものを入れてしまったのでしょう BufferDN[i+1]=high[i+1];

ええと、1がないと、一般的に矢印は3番目のバー、コードスモールに配置されます、私はどこで失敗したのでしょうか?

#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:

うっ、単位がない、一般的に矢印は3番目のバーに置かれる、コード小さい、どこで失敗したんだろう?

最初のバーに貼られているのですが、もしそうなら意味がわかりません。

おそらくそうだと思いますが、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で書いていないので、間違っているかもしれません。

また、2本目のバーでは、私を置く)

 
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:

また、2本目のバーでは、私を置く)

そういえば、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");

例えば、すべての「Print()」を「if(L)Print()」に置き換えるとか、他のオプションがあるかもしれません。

 
pivomoe:
Printコールが 多用されるコードがあります。このような場合、Printを削除することなく、すぐに無効化する方法はありますか? 今のところ、このオプションしかありません。

例えば、すべての「Print()」を「if(L)Print()」に置き換えてください。

入力パラメータで、"Print "フラグを出力する。あなたのコードと同じように動作しますが、フラグ自体(bool変数)は入力パラメータになります。

 

こんにちは。

MT5テスターで全てのシンボルによる最適化が機能しない...。

どうすればうまくいくのか、教えてください。

ありがとうございました。

理由: