You can not generate the names of variables.
Instead of 40 variables, you can use just 1 array.
In the global area define your Array
int Magic_Array[40];
then fill the array with your magic numbers
then use this loop where you need it
for(int i=39; i>0; i--) { if(OrderMagicNumber()== Magic_Array[i]) { //Do something } }
// The Order must be selected before you use this loop
//Example:
for(int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==_Symbol) { for(int i=39; i>0; i--) { if(OrderMagicNumber()== Magic_Array[i]) { //Do something } } } } }I have just edited the code and changed the loop to start from 39
You can not generate the names of variables.
Instead of 40 variables, you can use just 1 array.
In the global area define your Array
then fill the array with your magic numbers
then use this loop where you need it
// The Order must be selected before you use this loop
//Example:
I have just edited the code and changed the loop to start from 39MagicNumaraxx is an external variable. 40 operations are required to transfer to array
extern int MagicNumber1=333;
int Magic_Array[40];Magic_Array[0]=MagicNumara1;Magic_Array[1]=MagicNumara2;.....Magic_Array[39]=MagicNumara40;
MagicNumaraxx is an external variable. 40 operations are required to transfer to array
extern int MagicNumber1=333;
Are you sure you need to take all does magic numbers from user?
If not, and you are just trying to have 40 magic numbers you can
generate them inside of your codes, But you can not generate the variable names (as far as I know).
You can do it by getting just one magic number externally and generate the other ones based on the external one, or you can make all of them in your
code.
It will be the best if you can tell us about what you exactly trying to do.
I want to compare 40 external input Magicnumbers with the OrderMagicnumbers. I want to do this with a for loop, not 40 lines.
You already said that.
I want to compare 40 external input Magicnumbers with the OrderMagicnumbers. I want to do this with a for loop, not 40 lines.
Then do as Reza has told you, store the magic numbers in an array.
Then do as Reza has told you, store the magic numbers in an array.
how do store ?
Magic_Array[0]=MagicNumara1;
Magic_Array[1]=MagicNumara2;
Magic_Array[2]=MagicNumara3;
Magic_Array[3]=MagicNumara4;
Magic_Array[4]=MagicNumara5;
Magic_Array[5]=MagicNumara6;
....
Magic_Array[39]=MagicNumara40;
i want to this style
int limit=39
for(i=0; i>=limit; i++)
{
Magic_Array[0]=MagicNumara+string(i+1);
- Mehmet Bastem: I want to compare 40 external input Magicnumbers with the OrderMagicnumbers. I want to do this with a for loop, not 40 lines.You've already been told that that is impossible and was given the only solution. #2:
Mehmet Bastem: i want to this style…Mehmet Bastem: MagicNumaraxx is an external variable. 40 operations are required to transfer to array - Why do you think you need more than one magic number? You only need one/strategy/TF.
Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number filtering on your OrderSelect/Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
MagicNumber: "Magic" Identifier of the Order - MQL4 Articles
- You've already been told that that is impossible and was given the only solution. #2:
- Why do you think you need more than one magic number? You only need one/strategy/T
I did not understand my question. variable with constant. how can we assign constants to a variable? and do it with the for loop. writing 40 lines is not the solution.
example,
for (int i = 0; i < 40; i++)
{
((string)this.Controls["MagicNumara" + (i + 1)]).Text;
-
You've already been told that that is impossible and was given the only solution
- Here's a different solution, less efficient:
int MagicNumara(int i){ switch(i){ case 1: return MagicNumara1; ⋮ case 40: return MagicNumara40; } } ⋮ int limit=39 for(i=0; i>=limit; i++) Magic_Array[i]=MagicNumara(i+1);
- Now answer my question #8.2
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use