What about an array?
..
int start() {
arr[0] = iRSI(..);
arr[1] = iRSI(..);
...
}
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:
...What about an array?
..
int start() {
arr[0] = iRSI(..);
arr[1] = iRSI(..);
...
}
That will change nothing if we are talking about execution speed.
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.
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
.
.
.
*/
return 0;
}
- Globally declared if they have to be shared between routines.
- Statically declared if they have to be remembered between calls.
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);
Then you might as well as use arrays.How are you going to access them? if(i == 1) do_something(a);
if(i == 2) do_something(b);- 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.)
What about an array?
..
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.
- Globally declared if they have to be shared between routines.
- Statically declared if they have to be remembered between calls.
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);
Then you might as well as use arrays.How are you going to access them? if(i == 1) do_something(a);
if(i == 2) do_something(b);- 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.
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<removed by moderator> |
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/161118I 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. |

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.
.
.
*/
}
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.
.
.
*/
}