Questions from a "dummy" - page 62

 
x100intraday:
An example would be...

Like this (not the structure, but the class, of course):

class TBuffer
{
public:
  double  MABuffer[ ];
};

//---------------------------------------------------------------------
TBuffer*  Buffer_Array[ ];
//---------------------------------------------------------------------

//---------------------------------------------------------------------
  ArrayResize( Buffer_Array, NUMBER );
  for( int i = 0; i < NUMBER; i++ )
  {
    Buffer_Array[ i ] = new TBuffer;
    SetIndexBuffer( i, Buffer_Array[ i ].MABuffer, INDICATOR_DATA );
  }

What to put where, I think, is clear.

Don't forget at the end:

  for( int i = 0; i < NUMBER; i++ )
  {
    delete( Buffer_Array[ i ] );
  }
 
Yedelkin:

Let me rephrase. You're wondering if it's possible, when defining a function

specify only a variable of the structure type as its formal parameter, ignoring the name of the structure itself? I.e. specify, for example, not void funcName(MqlTradeRequest & req), but just void funcName(& req)?

Yes. You need a universal function for any simple structure --- No methods, din. arrays. etc. --- purely a sequence of specific data types.

Since the composition of the script is predetermined by me, I can explicitly specify the number of structures to deal with.

struct Data1
  {
   double param[1000000];
  };
struct Data2
  {
   int    temp;
   double k;
  };
struct Data3
  {
   int    temp;
   double k;
  };

But to pass any of these structures intofunction with one name, I have to use overloading.

void funWrite(Data1 &dd[])
  {
    .....
    Один тип обработки для всех структур
    .....
    FileWriteArray(1, dd);
  }
void funWrite(Data2 &dd[])
  {
    .....
    Один тип обработки для всех структур
    .....
    FileWriteArray(1, dd);
  }
void funWrite(Data3 &dd[])
  {
    .....
    Один тип обработки для всех структур
    .....
    FileWriteArray(1, dd);
  }

There are some difficulties here.

1. The number of structures is limited, because overloading will slow down if you have more elements.

2. I myself may make a mistake when copying the overloading functions.

PS// ThefunWrite() function performs certain calculations and executesFileWriteArray() with a certain sequence and calculated parameters (which index to write from, how many to read).

 
rlx:

Yes. You need a universal function for any simple structure --- No methods, din. arrays. etc. --- purely a sequence of specific data types.

Since the composition of the script is pre-defined by me, I can explicitly specify the number of structures to deal with.

But to pass any of these structures to a function with one name, I have to use overloading.

I see. Some time ago I asked a similar question about whether it was possible not to specify the type of arrays when defining a function. Just below there, Roche advised overloading.

So I came to the conclusion that "built-in" functions likeFileWriteArray(), whichhave some parameters specified with void type, are themselves overloaded functions. We just do not see their implementation.

 
Yedelkin:

I see. I asked a similar question once before about whether it was possible not to specify the type of arrays when defining a function. Just below there, Roche advised overloading.

So I came to the conclusion that "built-in" functions likeFileWriteArray(), whichhave some parameters specified with void type, are themselves overloaded functions. We just cannot see their implementation.

Built-in functions are written in a full programming language.

In C, for example, you can pass any number of variables, and already in the function get a list of passed parameters and examine them.

void fun(...)
  {
}

In MQL5, there is no such a possibility. In particular, links and pointers to simple data types and structures are missing...

 

It must have something to do with security. Access to data. Going outside the sandbox.

But I still wish these features were implemented in MQL5

 
rlx:

It must have something to do with security. Access to data. Going outside the sandbox.

But I still want these features to be implemented in MQL5

It would be better to write your request to Service Desk. Otherwise, it will be quickly lost in the forum.
 
Dima_S:

Like this (not the structure, but the class, of course):

I think it's clear what to put in where.

At the end, don't forget:

Now that's what I call help: real and quite concrete. Thank you. Where's the plus sign?

By the way... I've been figuring that's good enough for me. But I don't want to be a formalist... ... so out of curiosity I decided that it wouldn't hurt to try organizing a two-dimensional array. MQL reminds me something of C/C++, which I have forgotten over the past dozen or so years. Now I've tried to do it this way (without loop - I intentionally simplified it):

class TBuffer
{
public:
  double MABuffer[][1];
};

//---------------------------------------------------------------------
TBuffer* Buffer_Array[][1];
//---------------------------------------------------------------------
int OnInit()
  {
   ArrayResize(Buffer_Array,1);
   Buffer_Array[0][0] = new TBuffer;
   SetIndexBuffer(0,Buffer_Array[0][0].MABuffer,INDICATOR_DATA);
// --- [...]
   delete(Buffer_Array[0][0]);
   return(0);
  }

The compiler generates the error: "'MABuffer' - parameter conversion is not allowed".

I wonder what I'm doing wrong. If I'm not mistaken, when declaring a class with multidimensional array it's necessary to specify numerically one of measurements, making it static?ArrayResize, meanwhile, setsnew size for the first dimension.

 

x100intraday:

I wonder what I'm doing wrong?

1) SetIndexBuffer works with an array of doubles of the same dimension.

2) It's not clear why you're using TBuffer*, i.e. using dynamics where it's not needed?

3) (TIP) In the example, you could have done with a structure rather than a class, to save a little memory and a couple of hundred clock cycles.

 

mql5:

3) (TIP) In the example, you could have done with a structure rather than a class, to save a little memory and a couple of hundred clock cycles.

Has this been checked?
 

The expert advisor uses the indicator on a different timeframe. On tests in the Expert Advisor appears wrong data from the indicator.

The EA itself works on M5, and the indicator on H4. Indicators which are called on the same timeframe (M5) return the correct values.

Returned values are similar to the indicator values, but are different from the real values which are visible when the indicator is applied to the price chart window.

What is the problem?

Example code of indicator call:

int W_handle;
int OnInit()
  {
   W_handle=iCustom(NULL, PERIOD_H4, "WW");
  }

void OnNewBar() // моя функция
{
 double wave[10];
 ArraySetAsSeries(wave, true);

 CopyBuffer(W_handle,0,0,2,wave);
 if (wave[1] > 0) Buy(); 
// по замыслу в wave[1] должно лежать значение индикатора на предыдущем баре H4
// но так получается только на нескольких первых обращениях, потом результат начинает расходиться с реальностью
}
Способы вызова индикаторов в MQL5
Способы вызова индикаторов в MQL5
  • 2010.03.09
  • KlimMalgin
  • www.mql5.com
C появлением новой версии языка MQL, не только изменился подход к работе с индикаторами, но и появились новые способы создания индикаторов. Кроме того, появилась дополнительная гибкость при работе с индикаторными буферами - теперь вы можете самостоятельно указать нужное направление индексации и получать ровно столько значений индикатора, сколько вам требуется. В этой статье рассмотрены базовые методы вызова индикаторов и получения данных из индикаторных буферов.
Reason: