新人对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的柱子。如果图表有1000个柱子,第一个柱子的索引是0,最后一个柱子的索引是999。

再往前走,通过环形体,在历史中提到了更遥远的酒吧。

所有这些都需要在初步检查中加以考虑。

要进行适当的检查,请参阅MQL4参考中的IndicatorCounted()函数的例子。只是现在,IndicatorCounted()应该被分享rate_total(这是Bars)和prev_calculated(这是IndicatorCounted())取代。

谢谢,找到了。

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

我应该把它与什么相比较? 在例子中,它以极限 开始

 limit=Bars-counted_bars;

我应该把这个 "Cb "与什么相比较?

 
PolarSeaman:

谢谢你,找到了。

在这个例子中,它以极限 开始。

我应该把这个 "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:

如果你想限制显示指标数据的条数,最好是这样做。

使用方法如下。

总数的值是历史上最深的柱子的指数,可以根据指标设置的值来调用。

编译者发誓。

'InitializeBuffers' - 函数未定义 HiLo.mq4 161 7

而在帮助中没有关于这个函数的任何信息。
 
PolarSeaman:

编译器抱怨说

'InitializeBuffers' - 函数未定义 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)有3个值:价格、0.0和164874239.218492。

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

如果值sell_1_B!=EMPTY_VALUE和sell_1_B!=0,这并不意味着有价格。

我怎样才能获得信号?