MQL4、MQL5に関する初心者からの質問、アルゴリズムやコードに関するヘルプ、ディスカッションなど。 - ページ 305

 
mila.com:

ありがとうございます、でも私にはゼロを返します。その理由は何でしょうか?

それ以外の理由ではありえない。1970年以下の年を知っているコンピュータはない。ブローカーの見積書に表示されている年号から始めます。

 
Alexey Viktorov:

他の年ではありえない。1970年以下の年を知っているコンピュータはない。ブローカーの見積書に表示されている年号から始めます。

いい仕事してますね、私たちの時代の元年です(笑)。

 
Vitaly Muzichenko:

どうした、いいじゃないか、我々の時代の元年)

そして、-1が1年目のBCとなる。
 
Artyom Trishkin:
CopyXXX()を使用する

ありがとうございます。


MT5では、このようにチャートを移動さ せることができます。

PlotIndexSetInteger(0,PLOT_SHIFT,InpChannelPeriod);

MT4でコンパイルするとエラーは出ないのですが、何も動作しないのですが、MT4の対応機種はありますか?
 
Aleksey Vyazmikin:

ありがとうございます。


MT5では、このようにチャートを移動さ せることが可能です。

PlotIndexSetInteger(0,PLOT_SHIFT,InpChannelPeriod);

MT4でコンパイルするとエラーは出ないのですが、何も動作しないのですが、MT4の対応機種はありますか?
Пользовательские индикаторы - Справочник MQL4
Пользовательские индикаторы - Справочник MQL4
  • docs.mql4.com
Пользовательские индикаторы - Справочник MQL4
 
Alexey Viktorov:

そこを選びました。

SetIndexShift(0,InpChannelPeriod); 

しかし、その効果は全く異なるものです。つまり、コードが動作しない、ロジックが異なる、などなど...わかりません。
 

誰か助けてくれるかもしれません。 このインジケータの本質は、通常通りドネシアンチャネルを 描き、最後のチャネル値のラインをマイナスバーの後ろにずらすことです。

MT5ではすべてうまくいっているようですが、MT4では何が問題なのかわかりません。あちこち描き直しましたが、やはり無意味に描画されます。別途、ずれる値の計算をしていますが、チャンネルそのものがずれてしまいます。

//+------------------------------------------------------------------+
//|                                             Donchian_Channel.mq5 |
//+------------------------------------------------------------------+
#property copyright "Vyazmikin Aleksey Vyacheslavovich"
#property link      "https://www.mql5.com/ru/users/-aleks-"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2

//--- plot Label1
#property  indicator_label1  "High_Prognoz";
#property  indicator_type1   DRAW_LINE;
#property  indicator_color1  clrAquamarine;
#property  indicator_style1  STYLE_DOT;
#property  indicator_width1  1;
//--- plot Label2
#property  indicator_label2  "Low_Prognoz";
#property  indicator_type2   DRAW_LINE;
#property  indicator_color2  clrAquamarine;
#property  indicator_style2  STYLE_DOT;
#property  indicator_width2  1;


//--- input parameters
input int InpChannelPeriod=48; // Period

//--- indicator buffers
double ExtHighBufferPrognoz[];
double ExtLowBufferPrognoz[];
//---
int i,limit,start;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtHighBufferPrognoz,INDICATOR_DATA);
   SetIndexBuffer(1,ExtLowBufferPrognoz,INDICATOR_DATA);
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- set first bar from what index will be drawn
   SetIndexDrawBegin(0,InpChannelPeriod);
   SetIndexDrawBegin(1,InpChannelPeriod);

   SetIndexShift(0,InpChannelPeriod);
   SetIndexShift(1,InpChannelPeriod);

//---
   return(0);
  }
//+------------------------------------------------------------------+
//| 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[])
  {

//--- check for rates
   if(rates_total<InpChannelPeriod*2) return(0);
//--- preliminary calculations
   if(prev_calculated==0) limit=InpChannelPeriod;
   else limit=prev_calculated;
//--- the main loop of calculations

   for(i=limit;i<rates_total && !IsStopped();i++)
     {
      start=i-InpChannelPeriod;
      ExtHighBufferPrognoz[i-InpChannelPeriod]=high[ArrayMaximum(high,InpChannelPeriod,start)];
      ExtLowBufferPrognoz[i-InpChannelPeriod] =low[ArrayMinimum(low,InpChannelPeriod,start)];

     }

   for(int x=rates_total-InpChannelPeriod;x<rates_total && !IsStopped();x++)
     {
      ExtHighBufferPrognoz[x]=ExtHighBufferPrognoz[rates_total-InpChannelPeriod];
      ExtLowBufferPrognoz[x]=ExtLowBufferPrognoz[rates_total-InpChannelPeriod];
     }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
Aleksey Vyazmikin:

誰か助けてくれるかもしれません。 このインジケータの本質は、通常通りドネシアンチャネルを描き、最後のチャネル値のラインをマイナスバーの後ろにずらすことです。

MT5ではすべてうまくいっているようですが、MT4では何が問題なのかわかりません。あちこち描き直しましたが、やはり無意味に描画されます。別途、ずれる値の計算をしていますが、チャンネル自体がずれてしまうのです・・・。

ワニのコードを見てください、そこにシフトが効いているんです。とはいえ、もしかしたら理屈は違うかもしれませんが。

 
Alexey Viktorov:

まあ、ワニのコードを見てくださいよ、あそこはシフトが効くんですよ。理屈は違うかもしれませんが。


はい、シフトは私にも有効です。

配列にシフトをかけると、シフトがないかのように充填されますが、シフト自体は視覚的に起こります。

コードの最初の部分は、最後のバーからInpChannelPeriodの 深さまでバッファを満たさないままにしておきます。

   for(i=limit;i<rates_total && !IsStopped();i++)
     {
      start=i-InpChannelPeriod;
      ExtHighBufferPrognoz[i-InpChannelPeriod]=high[ArrayMaximum(high,InpChannelPeriod,start)];
      ExtLowBufferPrognoz[i-InpChannelPeriod] =low[ArrayMinimum(low,InpChannelPeriod,start)];

     }

第2部では、この部分を埋める必要があります。

   for(int x=rates_total-InpChannelPeriod;x<rates_total && !IsStopped();x++)
     {
      ExtHighBufferPrognoz[x]=ExtHighBufferPrognoz[rates_total-InpChannelPeriod];
      ExtLowBufferPrognoz[x]=ExtLowBufferPrognoz[rates_total-InpChannelPeriod];
     }

しかし、実際はこのような結果になるのです。


 

MT5でのコード

#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2

//--- plot Label1
#property indicator_label1  "Predicted_high_price";
#property indicator_type1   DRAW_LINE;
#property indicator_color1  clrAquamarine;
#property indicator_style1  STYLE_DOT;
#property indicator_width1  1;
//--- plot Label2
#property indicator_label2  "Predicted_low_price";
#property indicator_type2   DRAW_LINE;
#property indicator_color2  clrAquamarine;
#property indicator_style2  STYLE_DOT;
#property indicator_width2  1;


//--- input parameters
input int InpChannelPeriod=48; // Period

//--- indicator buffers
double ExtHighBufferPrognoz[];
double ExtLowBufferPrognoz[];
//---
int i,limit,start;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtHighBufferPrognoz,INDICATOR_DATA);
   SetIndexBuffer(1,ExtLowBufferPrognoz,INDICATOR_DATA);   
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- set first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpChannelPeriod);
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpChannelPeriod);   

   PlotIndexSetInteger(0,PLOT_SHIFT,InpChannelPeriod);
   PlotIndexSetInteger(1,PLOT_SHIFT,InpChannelPeriod);   


//---
   return(0);
  }
//+------------------------------------------------------------------+
//| 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[])
  {

//--- check for rates
   if(rates_total<InpChannelPeriod) return(0);
//--- preliminary calculations
   if(prev_calculated==0) limit=InpChannelPeriod;
   else limit=prev_calculated;
//--- the main loop of calculations
   for(i=limit;i<rates_total && !IsStopped();i++)
     {
      start=i-InpChannelPeriod;          
      ExtHighBufferPrognoz[i-InpChannelPeriod]=high[ArrayMaximum(high,start,InpChannelPeriod)];
      ExtLowBufferPrognoz[i-InpChannelPeriod]=low[ArrayMinimum(low,start,InpChannelPeriod)];

     }

   for(int x=rates_total-InpChannelPeriod;x<rates_total && !IsStopped();x++)
     {
      //int calc=x--;
      ExtHighBufferPrognoz[x]=ExtHighBufferPrognoz[rates_total-InpChannelPeriod-1];
      ExtLowBufferPrognoz[x]=ExtLowBufferPrognoz[rates_total-InpChannelPeriod-1];             
     }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

結果


ZS: コードを変更しました。間違ったMEは