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

 
PolarSeaman:

まだ蹴り出し中です。

i+1] がある場合、さらに+2チェックする必要があります。

一般的には、次のようにします。

limit=(rates_total<cb || cb<=0) ? rates_total-1 : cb;
if (limit<=0) return(0);
 
Ihor Herasko:

チェックが根本的に間違っているからです。Barsが1000を返し、cbも1000を返すとします。そして、最初の反復のループで、私は値1000を取得します。ループ本体の最初の条件では

インデックス1000のバーとインデックス1001のバーにアクセスし、一度に2つの配列の外に 出る。例えば、チャートに1000本のバーがある場合、最初のバーのインデックスは0、最後のバーのインデックスは999となります。

さらにループ体を進むと、歴史の中でさらに遠い小節への言及がある。

これらすべてを考慮した上で、初期チェックを行う必要があります。

適切な確認方法は、MQL4リファレンスのIndicatorCounted()関数の例をご覧ください。今だけ、IndicatorCounted()は、共有rates_total(これはBars)とprev_calculated(これはIndicatorCounted())に置き換えられるべきである。

ありがとう、見つけました。

 int counted_bars=IndicatorCounted(); 
     if(counted_bars>0) counted_bars--;

例ではlimitで始まって いますが、何と比較すればいいのでしょうか?

 limit=Bars-counted_bars;

この "cb "は何と比較すればいいのでしょうか?

 
PolarSeaman:

ありがとうございます、見つけました。

何と比較すればいいのか? 例では、limitから始まって います。

この "CB "を何と比較すればいいのか?

インジケーターのデータを表示するバーの数を 制限したい場合は、このようにするのが良いでしょう。

int GetRecalcIndex(int& total, const int ratesTotal, const int prevCalculated)
{
   total = ratesTotal - 2 - barsig;                                                                         
                                                   
   if (cb > 0 && cb < total)
      total = MathMin(cb, total);                      
                                                   
   if (prevCalculated < ratesTotal - 1)                     
   {       
      InitializeBuffers();    // Это функция, которая должна заново инициализировать все индикаторные буфера, т. к. имеем дело с первой загрузкой индикатора или подкачкой истории
      return (total);
   }
   
   return (MathMin(ratesTotal - prevCalculated, total));                            
}

以下のようにお使いください。

int total;   
int limit = GetRecalcIndex(total, rates_total, prev_calculated);                                

for (int i = limit; i >= 0; --i)
{
  ...
}
合計値は、ヒストリーの中で最も深いバーのインデックスであり、インジケーターの設定値に基づいてアクセスすることが可能です。
 
Taras Slobodyanik:

i+1] がある場合、さらに+2チェックする必要があります。

一般的には、次のようにします。

そのようにしたのですが、...HiLo.mq4'(122,15)の配列が範囲外です、と表示されます。

さらに+2して確認すべきことは何ですか?


 
Ihor Herasko:

インジケーターデータを表示するバーの 数を制限したい場合は、そのようにするとよいでしょう。

以下のようにお使いください。

totalの値は、ヒストリーの中で最も深いバーのインデックスであり、インジケーターの設定の値に基づいて呼び出すことができます。

コンパイラは悪態をつく。

'InitializeBuffers' - function not defined HiLo.mq4 161 7.

で、この関数については、ヘルプには何も書かれていません。
 
PolarSeaman:

についてコンパイラが文句を言う。

'InitializeBuffers' - function not defined HiLo.mq4 161 7.

また、この機能についてはヘルプには何も書かれていません

コメントで、これはすべてのインジケータバッファを初期化する関数であると書きました。カスタム機能である。こんな感じで持っています。

void InitializeBuffers()
{
   ArrayInitialize(g_indValues, EMPTY_VALUE);
   ArrayInitialize(g_tempBuffer, EMPTY_VALUE);
}

バッファが違うので、違うものが出てきます。グラフィカルなオブジェクトで動作する インジケーターの場合、読み取りの初期描画を行うため、ここですべてのオブジェクトを削除する必要があります。

 
Ihor Herasko:

コメントで、これはすべてのインジケータバッファを初期化する関数であると書きました。カスタム機能である。こんな感じで持っています。

バッファーが違うので、違うものが出てきます。グラフィカルなオブジェクトで 動作するインジケーターの場合、読み取りの初期描画を行うため、ここですべてのオブジェクトを削除する必要があります。

HiLo.mq4 "の配列が範囲外(130,15)になっています。

.どうしたんですか?

#property copyright "Copyright ©  november 2015"
#property strict 

#property indicator_chart_window
#property indicator_buffers 6

#property indicator_color1 RoyalBlue       //DodgerBlue
#property indicator_color2 Crimson         //OrangeRed
#property indicator_color3 Black  //White
#property indicator_color4 Black  //White
#property indicator_color5 Black            //White
#property indicator_color6 Black         //Red

#property indicator_width1 2
#property indicator_width2 2

#property indicator_style3 STYLE_DOT
#property indicator_style4 STYLE_DOT

input int    p        = 10;    // Период
input int    s        = 5;     // Угол наклона
input double distance = 2.0;   // Ширина канала
input bool   showBb   = false;  // Границы канала
input bool   showCl   = true;  // Центральная линия
input int    barsig   = 1;     // Сигнальная свеча (номер)
input int    arrots   = 0;    // Стрелка (отступ)
input int    arrsz    = 0;     // Стрелка (размер)
input int    ATR      = 1000;  // Период ATR
input int    cb       = 1000;  // Сколько свечей в истории

double fx1[],fx2[],hp[];
double z1,z2,ki;
int fs;

double upper[],lower[];
double upar[],dnar[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
//--- indicator buffers mapping
IndicatorBuffers(7);
SetIndexBuffer(0,fx1);
SetIndexBuffer(1,fx2);
SetIndexBuffer(2,lower);
SetIndexBuffer(3,upper);
SetIndexBuffer(4,upar);
SetIndexBuffer(5,dnar);
SetIndexBuffer(6,hp);


SetIndexStyle (4,DRAW_ARROW,0,arrsz);
SetIndexArrow (4,233);
SetIndexStyle (5,DRAW_ARROW,0,arrsz);
SetIndexArrow (5,234);

   if(showBb)
   {SetIndexStyle(2,DRAW_LINE);
    SetIndexStyle(3,DRAW_LINE);
   }
   else
   {SetIndexStyle(2,DRAW_NONE);
    SetIndexStyle(3,DRAW_NONE);
   }
   
    if(showCl)
   {SetIndexStyle(0,DRAW_LINE);
    SetIndexStyle(1,DRAW_LINE);
   }
   else
   {SetIndexStyle(0,DRAW_NONE);
    SetIndexStyle(1,DRAW_NONE);
   }

SetIndexEmptyValue(0,0.0);
SetIndexEmptyValue(1,0.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[])
  {
//---
   int i,limit;
//   limit=(rates_total<cb || cb<=0) ? rates_total-2 : cb;
//if (limit<=0) return(0);
 int total;   
 limit = GetRecalcIndex(total, rates_total, prev_calculated);                                

for (int i = limit; i >= 0; --i)
{ 
  
  
   SetIndexDrawBegin(0,Bars-cb);
   SetIndexDrawBegin(1,Bars-cb);

double avg;

ki=2.0/(p+1);

for (i=cb; i>=0; i--) {fx1[i]=Close[i];}

for (int m=0; m<=s; m++)
{
z1=fx1[0];
for (i=0; i<=cb; i++) {z1=z1+(fx1[i]-z1)*ki; hp[i]=z1;}

z2=fx1[cb];
for (i=cb; i>=0; i--) {z2=z2+(fx1[i]-z2)*ki; fx1[i]=(hp[i]+z2)/2;}
}

fs=0;
for (i=cb; i>=0; i--)
{
if (fx1[i]>fx1[i+1]) fs=1;
if (fx1[i]<fx1[i+1]) {if (fs==1) fx2[i+1]=fx1[i+1]; fs=2;}
if (fs==2) fx2[i]=fx1[i]; else fx2[i]=0.0;

avg = iATR(NULL,0,ATR, i+10);
upper[i] = hp[i] + distance*avg;
lower[i] = hp[i] - distance*avg;

if(Close[i+1+barsig]<upper[i+1+barsig] && Close[i+barsig]>upper[i+barsig])
 dnar[i] = High[i]+arrots*Point; else dnar[i] = EMPTY_VALUE;
 
if(Close[i+1+barsig]>lower[i+1+barsig] && Close[i+barsig]<lower[i+barsig])
 upar[i] = Low[i]-arrots*Point; else upar[i] = EMPTY_VALUE; 
}
}
//--- return value of prev_calculated for next call
   return(rates_total);
  }
  

int GetRecalcIndex(int& total, const int ratesTotal, const int prevCalculated)
{
   total = ratesTotal - 2 - barsig;                                                                         
                                                   
   if (cb > 0 && cb < total)
      total = MathMin(cb, total);                      
                                                   
   if (prevCalculated < ratesTotal - 1)                     
   {       
      InitializeBuffers();    // Это функция, которая должна заново инициализировать все индикаторные буфера, т. к. имеем дело с первой загрузкой индикатора или подкачкой истории
      return (total);
   }
   
   return (MathMin(ratesTotal - prevCalculated, total));                            
}

void InitializeBuffers()
{
   ArrayInitialize(fx1, EMPTY_VALUE);
   ArrayInitialize(fx2, EMPTY_VALUE);
   ArrayInitialize(lower, EMPTY_VALUE);
   ArrayInitialize(upper, EMPTY_VALUE);
   ArrayInitialize(upar, EMPTY_VALUE);
   ArrayInitialize(dnar, EMPTY_VALUE);
   ArrayInitialize(hp, EMPTY_VALUE);
}
 
PolarSeaman:

ありがとうございます。でも、何も変わっていないんです。どうしたんですか?

もちろん、結果は変わりません。結局、主な理由(CBループ)を削除していないんですね。このループの構成は間違っています。

for (i=cb; i>=0; i--)

取り外して、リミットループに交換する必要があります。 どちらの場所でも。

 
Ihor Herasko:

もちろん、結果は変わりません。結局、主な理由(CBループ)を削除していないんですね。このループの構成は間違っています。

取り外して、リミットループに交換する必要があります。 どちらの場所でも。

このようなループが3つあります。交換したら、端末がハングアップした。

 

やってみたところ、フリーズもクラッシュもしないのですが、最初のバッファ(fx2)にprice, 0.0, 164874239.218492の3つの値が存在します。

sell_1_B=NormalizeDouble(iCustom(Symbol(),0,"HiLo",1,1),Digits);

値 sell_1_B!=EMPTY_VALUE と sell_1_B!=0 の場合、価格があることを意味しない。

どうすれば電波が届くのか?