Learning and writing together in MQL5 - page 11

 
m_a_sim:

it turns out it is all about the indicators?

2010.09.01 19:44:36 Core 1 2010.06.01 00:00:01 Array out of range in 'trend_v3.mq5' (71,9)
2010.09.01 19:44:36 Core 1 2010.06.01 00:00:01 Array out of range in 'trend_v3_5.mq5' (83,9)

Array is out of range.

See code of 'trend_v3.mq5'. Even specific lines are given.

 
m_a_sim:

So it's all about the indicators? The tester is giving me an error

2010.09.01 19:44:36 Core 1 2010.06.01 00:00:01 Array out of range in 'trend_v3.mq5' (71,9)
2010.09.01 19:44:36 Core 1 2010.06.01 00:00:01 Array out of range in 'trend_v3_5.mq5' (83,9)


alexvd:

Array overrun.

See code 'trend_v3.mq5'. Even specific lines are specified.

I wonder if the indulgers themselves work?
 
alexvd:

Out of range of an array.

See code 'trend_v3.mq5'. Even specific lines are indicated.

Most likely it is the indicator, I redid it with mql4, it works, but there is an error, new bar is not considered yet, I can't figure out how to do it correctly so there will be no conflict with mql5

here is trend_v3. Do you mean line 9?

//+------------------------------------------------------------------+
//|                                                     trend_v3.mq5 |
//|                        Copyright 2010, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window


#property  indicator_buffers 1
#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property  indicator_color1  Blue


input int period =20;

double A[];
//+--------------
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

 SetIndexBuffer(0,A, INDICATOR_DATA);
   ArraySetAsSeries(A,true);

//---
   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[])
  {
  //int    counted_bars=IndicatorCounted();
   int   i, j, k, q, limit;
   double X[4][4], Y[4], B[4], x[4][2000], y[2000], a;
   
   // int Bar=Bars("EURUSD",_Period);
    ArraySetAsSeries(close,true);
 // limit=BarsCalculated-counted_bars;
 for(q=prev_calculated;q<rates_total;q++)
     {
  //for(q=0; q<Bar; q++)
  // {
     
   ArrayInitialize(X,0);
   ArrayInitialize(Y,0);   
   ArrayInitialize(B,0);   
   ArrayInitialize(x,0);
   ArrayInitialize(y,0);  
//===========================================
for (i=0; i<=period; i++) {

x[0][i]=1;
x[1][i]=i+q;
y[i]=   close[i+q];
}
//===========================================
  for (k=1; k<=period; k++) {
  for (j=0; j<=1; j++) {
  for (i=0; i<=1; i++) { 
   X[i][j]=x[j][k]*x[i][k]+X[i][j];   
   }
   Y[j]=y[k]*x[j][k]+Y[j];
   }}  
//===========================================  
k=0; 
 j=1; 
  a=X[k][j]/X[k][k];
  for (i=0; i<=3; i++){
  X[i][j]=X[i][j]-X[i][k]*a; 
  }
  Y[j]=Y[j]-Y[k]*a;

//==========================================  
for (k=2; k>=1; k--){
a=0;
for (i=1; i>=k; i--){
a=X[i][k-1]*B[i]+a;
}
B[k-1]=(Y[k-1]-a)/X[k-1][k-1];
}
//=========================================


   A[q]=B[0]+B[1]*q;
   }

//---
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Ограничения и проверки в экспертах
Ограничения и проверки в экспертах
  • 2010.08.02
  • MetaQuotes Software Corp.
  • www.mql5.com
Можно ли торговать этим инструментом в понедельник? Хватит ли денег на открытие позиции? Какой размер убытка мы получим, если сработает Stop Loss? Как ограничить количество отложенных ордеров? Была ли выполнена торговая операция на этом баре или это было на предыдущем? Если торговый робот не может сделать подобные проверки, то любая прибыльная торговая система может превратиться в проигрышную. В этой статье показаны примеры проверок, которые пригодятся в любом эксперте.
 
m_a_sim:

Most likely it is the indicator, I have redesigned it with mql4, it is drawn, but there is an error, new bar is not considered yet, I can not understand how to do it correctly, so that there would be no conflicts with mql5

here is trend_v3. Do you mean line 9?


71 stocks, 9 characters...

As I see it, this is the place where it's getting annoyed.

y[i]=   close[i+q];
 
Interesting:

71 stoka, 9 character...

As I understand it, this is where it fouls up

Is there a programmatic way to look for the line number and the character instead of manually counting?
 
m_a_sim:
Is there a software way to look for the line number and character, rather than manually counting?

Of course there is. Edit menu, go to line(Ctrl+G)...

PS

The line number and positions are written at the bottom. There is also a way to quickly jump to functions (by their name)...

 
Interesting:

Of course there is. Edit menu, go to line item...

PS

The line number and position are written at the bottom. There is also a way to quickly jump to functions (by their name)...


and what's wrong with it?
 
m_a_sim:
and what's wrong with it?
Check the dimensionality of the array. But first, I would add a disability and data availability check to the EA itself...
Документация по MQL5: Операции с массивами / ArrayRange
Документация по MQL5: Операции с массивами / ArrayRange
  • www.mql5.com
Операции с массивами / ArrayRange - Документация по MQL5
 
Interesting:
Check the dimensionality of the array. But first, I would add a disability and data availability check to the EA itself...
Can you be more specific, what do you mean by disability and data availability?
 
m_a_sim:
can you be more specific, what do you mean by disability and data availability?

Something like this

void OnTick()
{
//----------------------------------------------------------------------------//
//Work variables
MqlTradeRequest mrequest;  
MqlTradeResult mresult;
MqlTick latest_price;   

int i, j,jj, k, g, q, ticket,l;
double stop;
//----------------------------------------------------------------------------//

ArraySetAsSeries(ind1,true);
ArraySetAsSeries(ind2,true);

  if(hind1==INVALID_HANDLE||hind2==INVALID_HANDLE)
  {
  Print("Ошибка!!!");
  }
  else
  {
  MAX = CopyBuffer(hind1,2,0,3,ind1);
  MIN = CopyBuffer(hind2,0,0,3,ind2);
  }
//----------------------------------------------------------------------------//  
}

PS

I would also formalise all the work with the turkeys as a class...