Help me to Find the Most Efficient/Best Code in Variables Declaration [100+ Variables]

 

Help me to Find the Most Efficient/Best code in Variables Declaration [100+ Variables]

I have more than 100 variables declaration inside start(). Here's my example:

int start()
{

  double a = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
  double b = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
  double c = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
  /*

   1
   . 
   . 
   .

   100
  */

  

return 0;
}

 Should I put all variables in one declaration? Like this:

int start()
{
  double a, b, c; // variables 1 to 100+

  a = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
  b = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
  c = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);


return 0;
}

 Should I declare it global? To avoid excessive declaration in start()

double a, b, c; // global variables 1 to 100+

int start()
{
  a = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
  b = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
  c = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
  /*

   1
   .
   .
   .

   100
  */

 

return 0;
}


 

 

What about an array?

double arr[100];
..
int start() {
    arr[0] = iRSI(..);
    arr[1] = iRSI(..);
    ...
}
 
Musngi:

Help me to Find the Most Efficient/Best code in Variables Declaration [100+ Variables]

I have more than 100 variables declaration inside start(). Here's my example:

...
Carl Schreiber:

What about an array?

double arr[100];
..
int start() {
    arr[0] = iRSI(..);
    arr[1] = iRSI(..);
    ...
}

That will change nothing if we are talking about execution speed.

 
Musngi:

Help me to Find the Most Efficient/Best code in Variables Declaration [100+ Variables]

I have more than 100 variables declaration inside start(). Here's my example:

... 

 Should I put all variables in one declaration? Like this:

... 

 Should I declare it global? To avoid excessive declaration in start()

... 


 

 Local declaration will use resources of your processor.

Global declaration will use resources of your Random Access Memory.

 
Musngi:

Help me to Find the Most Efficient/Best code in Variables Declaration [100+ Variables]

 Should I put all variables in one declaration? Like this:

int start()
{
  double a, b, c; // variables 1 to 100+

  a = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
  b = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
  c = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);


return 0;
}

 Should I declare it global? To avoid excessive declaration in start()

double a, b, c; // global variables 1 to 100+

int start()
{
  a = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
  b = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
  c = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
  /*

   1
   .
   .
   .

   100
  */

 

return 0;
}
  1. Globally declared if they have to be shared between routines.
  2. Statically declared if they have to be remembered between calls.
  3. Don't declare them and then initialize them - that's bad style. Do both at once
    double  a = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
    double  b = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
    double  c = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
  4. How are you going to access them?
    if(i == 1) do_something(a);
    if(i == 2) do_something(b);
    Then you might as well as use arrays.
  5. For efficiency, don't do per tick what you can do per bar. If you're waiting for price to reach a level, remember the level and ignore ticks until you reach it (or you reach a invalid condition or new bar.)
 
Carl Schreiber:

What about an array?

double arr[100];
..
int start() {
    arr[0] = iRSI(..);
    arr[1] = iRSI(..);
    ...
}

No.

I want to declared different variable names for each currency pairs to make it easy to read/maintain. 

 
whroeder1:
  1. Globally declared if they have to be shared between routines.
  2. Statically declared if they have to be remembered between calls.
  3. Don't declare them and then initialize them - that's bad style. Do both at once
    double  a = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
    double  b = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
    double  c = iRSI("AUDNZD", Period(), 14, PRICE_CLOSE, i);
  4. How are you going to access them?
    if(i == 1) do_something(a);
    if(i == 2) do_something(b);
    Then you might as well as use arrays.
  5. For efficiency, don't do per tick what you can do per bar. If you're waiting for price to reach a level, remember the level and ignore ticks until you reach it (or you reach a invalid condition or new bar.)

Could you please elaborate more on this? 1-5.

I use the variables for counters to use in some calculation then use it to buffers. I don't use this variables to hold the values for longer time. 

 
My question still not solve. 
 
Musngi: My question still not solve. 
Because there is no "Best" to such a vague question.
Every post of yours is vague. Most replies are to read the documentation. In response to the rest, you just want more of the same.
https://www.mql5.com/en/forum/161118
https://www.mql5.com/en/forum/160344
https://www.mql5.com/en/forum/160332
https://www.mql5.com/en/forum/160381
<removed by moderator>
 
whroeder1:
Because there is no "Best" to such a vague question.
Every post of yours is vague. Most replies are to read the documentation. In response to the rest, you just want more of the same.
https://www.mql5.com/en/forum/161118
https://www.mql5.com/en/forum/160344
https://www.mql5.com/en/forum/160332
https://www.mql5.com/en/forum/160381
I think you a troll. Please do not feed the troll. When you respond, you give the troll power. When you ignore the troll, he starves for attention and eventually dies.
My question is very clear. Do you see I give 3 example code to choose? 
Reason: