Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 899

 
lufer:
Thanks, but it doesn't work with Mas[N]; in OnInit(), I've already tried it.
Well, I'm sorry, I was not very sober yesterday. Or not very sober.
 
AlexeyVik:
Well I'm sorry, I wasn't very sober last night. Or not very sober.
)), it happens.
 

Suppose I want the array to be filled with data taken from an indicator (for example ATR) from each bar starting from the first formed bar (#1)? That is, the array is declared and the start function already initializes it. How to do it correctly?

like this?

for(int i=0; i<N; i=i++)

{

Mas[i]=iATR(NULL,0,1,i+1);

}

Or it can be done via:

for(int i=0; i<N; i=i++)

{

ArrayFill(Mas,i,1,iATR(NULL,0,1,i+1))

}

or something else entirely?, so far I have not succeeded in any way(, something wrong, please advise, thank you in advance.

 
lufer:

Suppose I want the array to be filled with data taken from an indicator (for example ATR) from each bar starting from the first formed bar (#1)? That is, the array is declared and the start function already initializes it. How to do it correctly?

like this?

for(int i=0; i<N; i=i++)

{

Mas[i]=iATR(NULL,0,1,i+1);

}


The first case is sufficient. But if you need values starting from the first bar, it would be wise to count the loop from 1 as well.
 
evillive:
The first option is sufficient. But if we need values starting from the first bar, it would be more reasonable to count the cycle from 1.
I tried both with 1 and 0, still something is wrong, values are not written, when I ask to output some - it gives out only zeros
 
lufer:
I tried it with both 1 and 0, it still doesn't work, no values are written, when I ask to output some - it just outputs zeros.
Please show me the output code.
 
evillive:
Show the code to ask for the output.

I'll show you all the code just in case:

//+------------------------------------------------------------------+

extern int    N        =100;                       // Количество баров

       int    Mas[];                             // Объявление массива

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

int OnInit()
  { 
     ArrayResize(Mas,N,0);                // Установка размера массива      
  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+

void OnDeinit(const int reason)
  {

  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

void OnTick()
  {                                       
   for(int i=0; i<N; i=i++)                     // Цикл записи данных
     {                      

          Mas[i]=iATR(NULL,0,1,i+1);           // Вычисление значений          
     }
       Alert(Mas[0],"," ,Mas[50],"," ,Mas[99]);      // Вывод на экран
   return;                                           // Выход из start
  }
//+------------------------------------------------------------------+

 

Use SRC to insert code

 
lufer:

I'll show you all the code just in case:


make an array of type double
 
evillive:
make an array of type double
This does not solve the problem, now it seems that something is wrong inOnTick() - when I load the EA in the terminal window nothing happens, and when I try to delete it, the terminal stalls for a very long time and then deletes it after a while. I tried to manually assign values to some elements, everything is OK. Something about the array initialization cycle seems to be wrong.
 
lufer:
This does not solve the problem, now it seems that something is wrong inOnTick() - when I load the EA in the terminal window nothing happens, and when I try to delete it, the terminal stalls for a very long time and then deletes it after some time. I tried to manually assign values to some elements, everything is OK. Something about the array initialization loop seems to be wrong.

What do you mean it "doesn't solve"? You're shoving data of double precision below 1 into the Int array, the output will naturally contain zeros. Well, the loop was crippled as well.

This code should work:

#property strict

extern int N=100;                       // Количество баров

double Mas[];                             // Объявление массива
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

int OnInit()
  { 
    ArrayResize(Mas,N);
     return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+

void OnDeinit(const int reason)
  {

  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

void OnTick()
  {                                       
       for(int i=0; i<N; i++)                     // Цикл записи данных
         {                      
    
              Mas[i]=iATR(NULL,0,5,i+1);           // Вычисление значений          
         }
           Print(DoubleToStr(Mas[0],_Digits),"," ,DoubleToStr(Mas[50],_Digits),"," ,DoubleToStr(Mas[99],_Digits));      // Вывод значений
  }
Reason: