1

How would I group a list of (x) variables to be true, OR and group of (y) variables to be true to activate a command.

The following I have here, which includes the || Boolean.

if(OrderSelect(PosSel,SELECT_BY_POS,MODE_TRADES))
                 if(OrderTicket() > 0)
                 if((OrderMagicNumber() == Period()))
                 if(OrderSymbol() == Symbol())
                 if(TimeCurrent() >=(OrderOpenTime() + 60 * Period()))
                 /*Either the above variables can be met OR the one below can be met. */
                 || if((MarketInfo(Symbol(),MODE_BID)==(iOpen(Symbol(),0,1))))

Many thanks.

  • You might be interested in a syntax fact, that variables are not the same as a function call. All the elements in the proposed code are in fact groups of function calls, not a list of variables. One more thing you will have to take into account is the fact, all the functions used in your syntax require an explicit call to OrderSelect() to precede any of the following and some compiler-magics do not guarrantee the order of evaluation of the boolean-construct ( a.k.a. shortcuting ), so **some other steps are needed, ref. below** for details. – user3666197 Mar 22 '17 at 14:33

2 Answers2

0
   if(OrderSelect(PosSel,SELECT_BY_POS,MODE_TRADES)){
      if(OrderMagicNumber() == Period() && OrderSymbol()==Symbol()){
            RefreshRates(); //must call it before accessing Bid & Ask
            if(TimeCurrent()>=OrderOpenTime()+60*Period() || 
                fabs(Bid-iOpen(Symbol(),0,1))<Point/2){///here 1 OR 2 is true:
            //what to do ?
         }
      }
   }
Daniel Kniaz
  • 4,603
  • 2
  • 14
  • 20
  • Thank you for your help, so what is "fabs" then? I've never come across that term before. Thanks :) –  Mar 22 '17 at 14:39
  • you were going to compare two double/float values, in order to compare them correctly - need to check that their difference is small enough, like below half a pip in absolute value in this case. fabs() equals MathAbs() – Daniel Kniaz Mar 22 '17 at 15:59
0

Houston, we have a problem:

The solution is not a pure boolean logical construct, but involves a ( hidden ) transaction - a sequentially conditioned process.

In MetaTrader Terminal 4, there all the Order*(...) calls depend & must be preceded with an explicit OrderSelect() otherwise the dbPool-engine serves alike russian-lottery ( percussion revolver loaded with a single bullet in an unknown chamber position in the revolver's cylinder storage ). That's why an OrderSelect() goes & must go first. RefreshRates() is self-explanatory.


Need more than just a slight syntax honing - solution may be:

try to perform the dbPool.SELECT first and handle the explicit result in the boolean construct:

bool OrderSELECT_RESULT = OrderSelect( PosSel, SELECT_BY_POS, MODE_TRADES );
                          RefreshRates();
// a MUST-DO part, indeed _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

if (  (     OrderSELECT_RESULT
      &&    OrderTicket()           >  0
      &&    OrderMagicNumber()      == Period()
      &&    OrderSymbol()           == Symbol()
         )
      && (  OrderOpenTime()         <= TimeCurrent() - ( 60 * Period() )
         || iOpen( Symbol(), 0, 1 ) == MarketInfo( Symbol(), MODE_BID )
            )
      )
      { ... }
user3666197
  • 1
  • 6
  • 50
  • 92