A question for MQL experts - page 7

 

It's working so far. One more question.

There's another piece of code like this.

 
if (OrderSymbol() == Symbol() && OrderType() == OP_SELL) {
        switch (OrderMagicNumber()) {
            case 212:  MMMMM = 12;   break;
            case 211:  MMMMM = 11;   break;
            case 210:  MMMMM = 10;   break;
            case 209:  MMMMM = 9;    break;
                                    }

Would it be correct to replace it with -

if (OrderSymbol() == Symbol() && OrderType() == OP_SELL) 
     {     
            if ( OrderMagicNumber()==Magic_212)  MMMMM = 12;   
            if ( OrderMagicNumber()==Magic_211)  MMMMM = 11;   
            if ( OrderMagicNumber()==Magic_210)  MMMMM = 10;   
            if ( OrderMagicNumber()==Magic_209)  MMMMM = 9;    
     }
 
I'm looking at your exercises and thinking to myself:
- You start a few wizards
- then you keep track of magician numbers and depending on the number you assign the appropriate numeric value to the MMMMMM variable

Question: isn't it easier to assign this value to a wizard once in the inite and then use it?
 
Rita:

It's working so far. One more question.

There's another piece of code like this.

Would it be correct to replace it with -


if (OrderSymbol() == Symbol() && OrderType() == OP_SELL) 
     {     
            MMMMM = OrderMagicNumber()-200;   
     }
It is of course only for this particular case
 

Thank you. for the answers.

No, granit77, - that's not exactly the case.

I've been asked to fix-refine someone else's EA (- move the magicians to global). It is 1800 lines of code and complex algorithms of interaction of orders with different mages.

I simply cannot physically take the time to study these complicated control circuits. I find it easier to replace digital magics with "global" ones and fix those magics in a few functions in a purely mechanical way (without going deep into them).

 
Rita:

Thank you. for the answers.

No, granit77, - that's not exactly the case.

I've been asked to fix-refine someone else's EA (- move the magicians to global). It is 1800 lines of code and complex algorithms of interaction of orders with different mages.

I simply cannot physically take the time to study these complicated control circuits. I find it easier to replace digital magics with "global" ones and fix those magics in a few functions in a purely mechanical way (without going deep into them).


Where has Leonid gone?
 
He trades. He pretends he has no time. He's making arbitrage "dough" on the gold-silver spread.
 
Rita:
He trades. He pretends he has no time. He's making arbitrage "dough" on the gold-silver spread.
Well, if he puts the money in the drawer, pretend to believe in arbitrage.
 
Yes, - that's what I'm doing...

--------------------------

And probably the last question.

Here is this part of the code:

//double getNextOrderPriceByNum(int TTTT, double DDDD) {

   if (StepSum == FALSE && StepMultiply == FALSE) {

      switch (TTTT) {
      case 101:
         return (DDDD - Step * Point);
      case 102:
         return (DDDD - Step * MathPow(1, 1) * Point);
      case 103:
         return (DDDD - Step * MathPow(1, 2) * Point);
      ... ... ...
         
      }
      return (0);
   }
 

To replace case 101-102-103.... with Magic_101, Magic_102, Magic_103...

Would it be correct to do it like this:

   if (StepSum == FALSE && StepMultiply == FALSE) {

switch (TTTT) {
for (i=0; i<k; i++)                           {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
  if (OrderSymbol() == Symbol())                 {
    double Result ;
    if ( OrderMagicNumber()==Magic_101)  Result = (DDDD - Step * Point);   
    if ( OrderMagicNumber()==Magic_102)  Result = (DDDD - Step * MathPow(1, 1) * Point);   
    if ( OrderMagicNumber()==Magic_103)  Result = (DDDD - Step * MathPow(1, 2) * Point); 
                                                    }}}
      return (Result);
                     }
                                                   }
 
Rita:
Yes - that's what I'm doing...

--------------------------

To replace 101-102-103.... to Magic_101 - Magic_102 - Magic_103 -...

Would it be correct to do the following:

wrong. read about switch statement https://docs.mql4.com/ru/basis/operators/switch
In your example, just replace switch with if

      switch (TTTT) {
      case 101:
         return (DDDD - - Step * Point);
      case 102:
         return (DDDD - Step * MathPow(1, 1) * Point);
      case 103:
         return (DDDD - Step * MathPow(1, 2) * Point);
      }

replace with.

      if(TTT==Magic_101) return (DDDD - - Step * Point);
      else if(TTT==Magic_102) return (DDDD - Step * MathPow(1, 1) * Point);
      else if(TTT==Magic_103) return (DDDD - Step * MathPow(1, 2) * Point);
      ... ... ...
 
Thank you, abolk, for the clarification.
Reason: