Questions from a "dummy" - page 86

 

Renat, the question was theoretical rather than practical.

So as not to get lost in the fog, I will refer you to an example from the iFractals help. It is true that there is an indicator there, but let's simplify the task to a single calculation of the graphic layout by a script.

Suppose, I intended to find out the times of all the topside fractal bars on the entire history (or on its substantial part on some medium timeframe where there will be plenty of fractals). Did I understand correctly, that it's better to repeatedly disturbCopyTime in loop at FrUpBuffer[shift]!=EMPTY_VALUE to a depth of 1 element:

handle=iFractals(_Symbol,PERIOD_H4);
// вызов FillArraysFromBuffers(...)
// ...
// прочёс буфера
for(int shift=0; shift<BarsCalculated(handle); shift++)
{
   if(FrUpBuffer[shift]!=EMPTY_VALUE)
   {
     CopyTime(_Symbol,PERIOD_H4, shift, 1, Arr);
     Print(Arr[0]);
   }
}

bool FillArraysFromBuffers(double &up_arrows[],
                           int ind_handle,
                           int amount
                          )
  {
   if(CopyBuffer(ind_handle,0,0,amount,up_arrows)<0) return(false);

   return(true);
  }

and get a faster result than to eat the history at once with CopyTime by depth of FrUpBuffer:

handle=iFractals(_Symbol,PERIOD_H4);
// вызов FillArraysFromBuffers(...)
// ...
// прочёс буфера
for(int shift=0; shift<BarsCalculated(handle); shift++)
{
   if(FrUpBuffer[shift]!=EMPTY_VALUE)
     Print(TimeUpBuffer[shift]);
}

bool FillArraysFromBuffers(double &up_arrows[],
                           int ind_handle,
                           int amount
                          )
  {
   if(CopyBuffer(ind_handle,0,0,amount,up_arrows)<0) return(false);
   else CopyTime(_Symbol,PERIOD_H4,0,amount,TimeUpBuffer);

   return(true);
  }
and then in the same loop at the same if's just print the fractal bar time values?

Both tasks are identical, just implementations are slightly different.

Intuitively I understand that it is longer and more expensive to copy an enormous string of bar times (both fractal and empty) into an array; on the other hand, it's doubtful to pull up CopyTime repeatedly to a depth of 1 element.

If the first variant is faster, is it an absolute gain or it all depends on the total number of fractals encountered (for example, there are much more of them on small TF)?

 

Herehttps://www.mql5.com/ru/forum/3775/page59#comment_94865 I asked a question about putting declaration, linking, initialization and other actions on multiple buffers of the same type into a loop in order to reduce code and improve readability and manageability. I got an answer with an example (class, structure) and understood it.

Now according to the same principle I tried to tamp down multiple assignments of #property type:

#property indicator_label1  "FractalUp1"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrGreen

#property indicator_label2  "FractalDown1"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrGreen
// ---
#property indicator_label3  "FractalUp2"
#property indicator_type3   DRAW_ARROW
#property indicator_color3  clrBlue

#property indicator_label4  "FractalDown2"
#property indicator_type4   DRAW_ARROW
#property indicator_color4  clrBlue
[...]

and encountered at least two problems:

1. For on the global level is prohibited, that is, the earliest use of it is not earlier than in OnInit(), but #property is known to be declared on the global level before all the other functions;

2. When trying to assign properties to indicators in the loop in OnInit():

// понимаю, что сочинил бред
for (int i=0; i<NUMBER; i++)
{
  #property Property_Array[i].indicator_label (string)("Fractal"+i)
  #property Property_Array[i].indicator_type  DRAW_ARROW
  #property Property_Array[i].indicator_color clrArr[i]
}
Compiler swears at '#' (as expected): '#property' - unexpected token.
Could you tell me if and how the idea is feasible in principle?
 

Can you tell me how to declare a two-dimensional array of arrays?

Something like this:

double Buffers[6][3]={ [],[],[] },{ [],[],[] },{ [],[],[] },{ [],[],[] },{ [],[],[] },{ [],[],[] };
 
tol64:

Can you tell me if it is possible to declare a two-dimensional array of arrays?

An array of structures with fields as arrays can be declared, the compiler even skips dynamic arrays in the structure:

struct arr{double arr_str[];};
arr buffers[6][3];
Документация по MQL5: Основы языка / Типы данных / Объект динамического массива
Документация по MQL5: Основы языка / Типы данных / Объект динамического массива
  • www.mql5.com
Основы языка / Типы данных / Объект динамического массива - Документация по MQL5
 
tol64:

Can you tell me how to declare a two-dimensional array of arrays?

Something like this:

#define DIM1_NUMBER 6
#define DIM2_NUMBER 3

struct TBuffer
{
  string Buffer[3]; // для нагляднсти поменяем double на string
};

TBuffer Buffer_Array[DIM1_NUMBER];

string prefixArr[6]={"a","b","c","d","e","f"};

int OnInit()
  {
   for (int j=0; j<DIM1_NUMBER; j++)
   {
      for (int i=0; i<DIM2_NUMBER; i++)
      {
        string t;
   
        StringConcatenate(t,prefixArr[j],i);
        Buffer_Array[j].Buffer[i]=t;
      }
   }

   Print(Buffer_Array[0].Buffer[0],", ",
         Buffer_Array[0].Buffer[1],", ",
         Buffer_Array[0].Buffer[2],"; ",

         Buffer_Array[1].Buffer[0],", ",
         Buffer_Array[1].Buffer[1],", ",
         Buffer_Array[1].Buffer[2],"; ",

         Buffer_Array[2].Buffer[0],", ",
         Buffer_Array[2].Buffer[1],", ",
         Buffer_Array[2].Buffer[2],"; ",

         Buffer_Array[3].Buffer[0],", ",
         Buffer_Array[3].Buffer[1],", ",
         Buffer_Array[3].Buffer[2],"; ",

         Buffer_Array[4].Buffer[0],", ",
         Buffer_Array[4].Buffer[1],", ",
         Buffer_Array[4].Buffer[2],"; ",

         Buffer_Array[5].Buffer[0],", ",
         Buffer_Array[5].Buffer[1],", ",
         Buffer_Array[5].Buffer[2]
   );

   return(0);
  }
[Fixed.]
 

IgorM, x100intraday

Thanks for the options. I think this should do the trick, I'll give it a try.

 
tol64:

IgorM, x100intraday

Thanks for the options. I think this should work, I'll give it a try.

By the way, the name "Buffer" can be changed to "_" or some other riddles, then the call will be completely clear:

Buffer_Array[0]._[0]

Buffer_Array[0].¦[0]

 
Urain:

By the way, the name "Buffer" can be changed to "_" or something else, so that the call is completely clear:

ThanksUrain. Also an interesting addition. It's more familiar.))
 

But how do you do all this with #property? - I wonder...

No idea?

 
x100intraday:

But how do you do all this with #property? - I wonder...

No idea?

decrypt
Reason: