oldest order's profits - page 2

 
hadher ramadhan:

thanks konstantin but i guess this code 

 if ( OrderType()!= OP_SELL && OrderType()!= OP_BUY )continue;

must be written in this way

 if ( OrderType()!= OP_SELL || OrderType()!= OP_BUY )continue;

 thanks for your help 

If there is no BUY and SELL then continue . So everything is correct.
 if ( OrderType()!= OP_SELL && OrderType()!= OP_BUY )continue;

Equivalent

 if ( OrderType()== OP_SELL || OrderType()== OP_BUY )
 {
 }
 
Konstantin Nikitin:
If there is no BUY and SELL then continue . So everything is correct.

Equivalent

ok you are right, thanks pro

 
Konstantin Nikitin:
If there is no BUY and SELL then continue . So everything is correct.

Equivalent

hi Konstantin

i dont clearly understand why this test :

if ( OrderType()!= OP_SELL && OrderType()!= OP_BUY )continue;


there are only two situations when we open a trade : buy or sell, arent they ?

why we must test if an open trade has a  type  different of buy or sell   ?

 
paulselvan:

hi Konstantin

i dont clearly understand why this test :


there are only two situations when we open a trade : buy or sell, arent they ?

why we must test if an open trade has a  type  different of buy or sell   ?

OrderType

OP_BUY - buy order,
OP_SELL - sell order,
OP_BUYLIMIT - buy limit pending order,
OP_BUYSTOP - buy stop pending order,
OP_SELLLIMIT - sell limit pending order,
OP_SELLSTOP - sell stop pending order.

 
hadher ramadhan :

I try it but 

it collect's the profits of all the opened orders which was  opened before the current time ,,i just want the oldest order only sir   

Check by tickets. The smallest, is the oldest.

 
Konstantin Nikitin:

OrderType

Konstantin Nikitin:

OrderType

OP_BUY - buy order,
OP_SELL - sell order,
OP_BUYLIMIT - buy limit pending order,
OP_BUYSTOP - buy stop pending order,
OP_SELLLIMIT - sell limit pending order,
OP_SELLSTOP - sell stop pending order.

tnx

 OrderSelect(i, SELECT_BY_POS, MODE_TRADES ) gives open and pending orders

 
Konstantin Nikitin:

Check by tickets. The smallest, is the oldest.

great idea thanks

 
Marco vd Heijden:
Marco vd Heijden:
//+------------------------------------------------------------------+
double OLDESTPROFIT()
  {
   double result=0;
   datetime timeOpenOrder=TimeCurrent();

   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderMagicNumber()==MagicNumber)
           {
            if(OrderType()==OP_SELL || OrderType()==OP_BUY)
              {
               if(OrderOpenTime()<timeOpenOrder)
                 {
                  timeOpenOrder=OrderOpenTime();
                  result=OrderProfit()+OrderSwap()+OrderCommission();
                 }
              }
           }
        }
     }
   return(result);
  }
//+------------------------------------------------------------------+

it works perfectly thanks boss