OrderProfit - page 2

 

I don't understand why it is written in the way it is.

void OnTick()
{  
 if(!OrderSelect(OpenedTradePos(), SELECT_BY_POS))
  {  
   if(OrderProfit()<= -25)
    {
     bool res = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), slipage);
    } 
  }
}

It's simple.

 
paulselvan:

Hello,

A trade must be closed if its losses reache -25$ 

The probable codes  are :


is it correct ?Thanks

 for ( int pos = 0 ; pos < OrdersTotal (); pos++){

       if (( OrderSelect (pos, SELECT_BY_POS ) == TRUE ) && ( OrderMagicNumber () == magicNumber)) {

                 if ( OrderProfit()+OrderSwap()+OrderCommission() <= - 25 )
                           if( OrderClose( OrderTicket (), OrderLots(), Ask , slipage, 0 ) ) continue;

       }

}
 
Konstantin Nikitin:

Yes it is more correct to have Swap and Commission included as well.
But the order close price must not be Ask always(Ask for sell closes only), it is more appropriate to have it as OrderClosePrice().

for ( int pos = 0 ; pos < OrdersTotal (); pos++){

       if (( OrderSelect (pos, SELECT_BY_POS ) == TRUE ) && ( OrderMagicNumber () == magicNumber)) {

                 if ( OrderProfit()+OrderSwap()+OrderCommission() <= - 25 )
                           if( OrderClose( OrderTicket (), OrderLots(), OrderClosePrice(), slipage, 0 ) ) continue;

       }

}
 
It's more convenient.
for ( int pos = 0; pos < OrdersTotal(); pos++)
{
     if ( !OrderSelect(pos, SELECT_BY_POS,MODE_TRADES) ) continue;
     if ( OrderMagicNumber() != magicNumber ) continue;
     if ( OrderProfit()+ OrderSwap()+ OrderCommission() > -25 )   continue;

     if ( OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), slipage, 0 ) ) continue;
}
 

Yes It is true (this is the way I use it too), I think it is better to include Symbol check also, as the EA might work on different currency pairs as well..

for ( int pos = 0 ; pos < OrdersTotal(); pos++)
{
     if ( !OrderSelect (pos, SELECT_BY_POS,MODE_TRADES) ) continue;
     if ( OrderMagicNumber() != magicNumber ) continue;
     if ( OrderSymbol() != Symbol() ) continue; 
     if ( OrderProfit()+ OrderSwap()+ OrderCommission() > -25 )   continue;

     if ( OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), slipage, 0 ) ) continue;
}
 
Marco vd Heijden:

I don't understand why it is written in the way it is.

It's simple.

Because there are 2 ways to get out of the trade : one if takeprofit()<=-25$ ,the second if price target stoploss .

But anyway I have to change the code because the moving SL dont respect the minmum loss condition (-25$)

 
Konstantin Nikitin:

thanks for this remark

 

i thanks all for your ideas

I remarked my moving stoploss dont respect the maximum losses condition = -25$

So i must rewrite the pg to correct this by sizing the lot  ,maybe it's more simple:


lotsize
Reason: