Can the element of OrderSelect() be kept effective also after the new OrderSelect() if it is difined by the variable ?

 

Please watch the following .

  if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderType()== OP_SELL)
  double  a=OrderOpenPrice();
  if (OrderSelect(j,SELECT_BY_POS,MODE_TRADES) && OrderType()== OP_BUY)
  double  b=OrderOpenPrice();
 
        c=a+b;

In this case , is the last "a" (c=a+b) OrderOpenPrice() of the defined SELL position or of the difined BUY position ?

Please answer.

 
a had been recorded it , so a is OrderOpenPrice() of the defined SELL position
 
DxdCn:
a had been recorded it , so a is OrderOpenPrice() of the defined SELL position
Thank you DxdCn. Please participate when I ask again.
 
maymay:

Please watch the following .

  if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderType()== OP_SELL)
  double  a=OrderOpenPrice();
  if (OrderSelect(j,SELECT_BY_POS,MODE_TRADES) && OrderType()== OP_BUY)
  double  b=OrderOpenPrice();
 
        c=a+b;

In this case , is the last "a" (c=a+b) OrderOpenPrice() of the defined SELL position or of the difined BUY position ?

Please answer.

In what case?

a is undefined if position #i is not present or not a short one.
Similarly b is undefined if position #j is not present or not a long one.
In any case c is undefined.
 
Irtron:
maymay:

Please watch the following .

  if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderType()== OP_SELL)
  double  a=OrderOpenPrice();
  if (OrderSelect(j,SELECT_BY_POS,MODE_TRADES) && OrderType()== OP_BUY)
  double  b=OrderOpenPrice();
 
        c=a+b;

In this case , is the last "a" (c=a+b) OrderOpenPrice() of the defined SELL position or of the difined BUY position ?

Please answer.

In what case?

a is undefined if position #i is not present or not a short one.
Similarly b is undefined if position #j is not present or not a long one.
In any case c is undefined.

If you suppose there are some positions , how do you express ?

 if
  (
  for(int a=0;a<OrdersTotal();a++)
  {OrderSelect(a,SELECT_BY_POS,MODE_TRADES) ;
    OrderType()= OP_SELLSTOP ;}
  &&
  for(int b=0;b<OrdersTotal();b++)
  {OrderSelect(b,SELECT_BY_POS,MODE_TRADES;) 
  OrderType()= OP_BUY;}
 )

Do you think An above example is right according to the rule of MQL4?

 
First example is right from MQL4 perspective.
Second example is likely to fail compilation as for statement isn't an expression hence it doesn't produce any result for further calculation in logical expression.
There is a lack of sense in both of them though...
What are you trying to achieve with this?
 
Irtron:
First example is right from MQL4 perspective.
Second example is likely to fail compilation as for statement isn't an expression hence it doesn't produce any result for further calculation in logical expression.
There is a lack of sense in both of them though...
What are you trying to achieve with this?

I want to confirm if there are both of SELLSTOP and BUY.
 
maymay:

I want to confirm if there are both of SELLSTOP and BUY.

bool isBuySellStop() 
{
    bool buyPos = false, sellStopPos = false;
    
    int i = OrdersTotal();
    int type;
    
    while (i > 0)
    {
        i--;
        OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
        
        switch (OrderType())
        {        
            case OP_BUY:
                if (sellStopPos)
                    return (true);
                buyPos = true;
                break;
 
            case OP_SELLSTOP:
                if (buyPos)
                    return (true);
                sellStopPos = true;
        }        
    }
    return (false);
}
Reason: