Help With Breakeven Code Mql4

 

Hi i wrote this code for breakeven function.

Its work for buy order but not working with sell order. I checked several times the code but i dont found the trouble.

Maybe some one can help me with this. 


Thanks before

void MoveToBreakeven()
{
  
   for(int b=OrdersTotal()-1; b>=0; b--)
   {
   if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
      if(OrderMagicNumber()==MagicNumber)
         if(OrderSymbol()==Symbol())
            if(OrderType()==OP_BUY)
               if(Bid-OrderOpenPrice()>WhenToMoveToBE*SetPoint)
                  if(OrderOpenPrice()>OrderStopLoss())
                     OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+(PipsToLock*SetPoint),OrderTakeProfit(),0,clrNONE);
   }
   for(int s=OrdersTotal()-1; s>=0; s--)
      {
      if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES))
         if(OrderMagicNumber()==MagicNumber)
            if(OrderSymbol()==Symbol())
               if(OrderType()==OP_SELL)
                  if((OrderOpenPrice()-Ask)>(WhenToMoveToBE*SetPoint))
                     if(OrderOpenPrice()<OrderStopLoss())
                        OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-(PipsToLock*SetPoint),OrderTakeProfit(),0,clrNONE);
      }

}
 
  1. Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (strict), it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum 2012.05.20
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles 25 March 2014

 
if(OrderOpenPrice()<OrderStopLoss())

Usually when this is a problem with a sell trade, it can be solved with

if(OrderOpenPrice()<OrderStopLoss() || OrderStopLoss()==0)

I will move your topic to the MQL4 and Metatrader 4 section.


 
Keith Watford:

Usually when this is a problem with a sell trade, it can be solved with

I will move your topic to the MQL4 and Metatrader 4 section.


Wow its work. Thanks for your answer :)

Reason: