Close the position after 10 pips

 

Hi

I want the position to close when the position reaches 10 pips

What am I doing wrong?

//---------------------------------------------------------------------
void Trail2()
{
{
 if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES))
 
 if(OrderMagicNumber()==Magic7)
 {
  if((Bid-OrderOpenPrice())>MathPow(10,-Digits)*10)
 
   {
   OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Green);
    }
  
 if(OrderMagicNumber()==Magic8)
 {
  if((OrderOpenPrice()+Ask)<(MathPow(10,-Digits)*10))
  
   {
   OrderClose(OrderTicket(),OrderLots(),Ask,slippage,Yellow);
    }
 
  }
 }
}
//--------------------------------------------------------------


 
ghobar:

Hi

I want the position to close when the position reaches 10 pips

What am I doing wrong?


int start()
  {
  Trail2();
   return(0);
  }

void Trail2()
  {
  bool rest;
   int total = OrdersTotal();
   for(int i=total-1; i>=0; i--)
     {
      rest=OrderSelect(i, SELECT_BY_POS);
      int type   = OrderType();

      bool result = false;
// Buy
      if(
         OrderMagicNumber()==Magic7
         &&
         (((Bid-OrderOpenPrice())/Point)>10)
         &&
         OrderType()==OP_BUY
      )
         result = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, CLR_NONE);
// Sell
      if(
         OrderMagicNumber()==Magic8
         &&
         (((OrderOpenPrice()-Ask)/Point)>10)
         &&
         OrderType()==OP_SELL
         )
        
   result = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, CLR_NONE);
}
  
  }
 
Mehmet Bastem:

Global thanks

The code you wrote works very well

Reason: