How can I write the following code in practice

 
nt MagicNumara01=20;
int MagicNumara02=330;
int MagicNumara03=3044;
//...
              // i wanr to this  way
             for(int ig=40;ig>=1;ig--)
               {
               if(OrderMagicNumber() =="MagicNumara"+DoubleToStr(ig);
               }
            
            
            // orjinal codes
            if(
            (OrderMagicNumber() ==MagicNumara1  ||  OrderMagicNumber()==MagicNumara2
            || OrderMagicNumber()==MagicNumara7  ||  OrderMagicNumber()==MagicNumara3
            || OrderMagicNumber()==MagicNumara8  ||  OrderMagicNumber()==MagicNumara4
            || OrderMagicNumber()==MagicNumara9  ||  OrderMagicNumber()==MagicNumara5
            || OrderMagicNumber()==MagicNumara10  ||  OrderMagicNumber()==MagicNumara6
            ||
              OrderMagicNumber() ==MagicNumara11  ||  OrderMagicNumber()==MagicNumara12
            || OrderMagicNumber()==MagicNumara17  ||  OrderMagicNumber()==MagicNumara13
            || OrderMagicNumber()==MagicNumara18  ||  OrderMagicNumber()==MagicNumara14
            || OrderMagicNumber()==MagicNumara19  ||  OrderMagicNumber()==MagicNumara15
            || OrderMagicNumber()==MagicNumara20  ||  OrderMagicNumber()==MagicNumara16
            ||
              OrderMagicNumber() ==MagicNumara21  ||  OrderMagicNumber()==MagicNumara22
            || OrderMagicNumber()==MagicNumara27  ||  OrderMagicNumber()==MagicNumara23
            || OrderMagicNumber()==MagicNumara28  ||  OrderMagicNumber()==MagicNumara24
            || OrderMagicNumber()==MagicNumara29  ||  OrderMagicNumber()==MagicNumara25
            || OrderMagicNumber()==MagicNumara30  ||  OrderMagicNumber()==MagicNumara26
            ||
              OrderMagicNumber() ==MagicNumara31  ||  OrderMagicNumber()==MagicNumara32
            || OrderMagicNumber()==MagicNumara37  ||  OrderMagicNumber()==MagicNumara33
            || OrderMagicNumber()==MagicNumara38  ||  OrderMagicNumber()==MagicNumara34
            || OrderMagicNumber()==MagicNumara39  ||  OrderMagicNumber()==MagicNumara35
            || OrderMagicNumber()==MagicNumara40  ||  OrderMagicNumber()==MagicNumara36
            ) 
 
Mehmet Bastem:

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
 
Reza nasimi:

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 39

MagicNumaraxx 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;
 
Mehmet Bastem:

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.
 
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 already said that.

 
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.

Then do as Reza has told you, store the magic numbers in an array.

 
Keith Watford:

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);


 
  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.
    Mehmet Bastem: i want to this style…
    You've already been told that that is impossible and was given the only solution. #2:
    Mehmet Bastem: MagicNumaraxx is an external variable. 40 operations are required to transfer to array

  2. 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
 
William Roeder:
  1. You've already been told that that is impossible and was given the only solution. #2:

  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;

 
  1. You've already been told that that is impossible and was given the only solution

  2. 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);

  3. Now answer my question #8.2

Reason: