Download MetaTrader 5
To add comments, please log in or register
Interested in the Market activity? Come and track!
sohail
7
sohail 2016.01.07 20:24 

Here is the code:

if(OrderSelect(ticket,SELECT_BY_TICKET) == true)
      {      
         if(position == IN_SELL){
            double avg = get_average();
            if(value <= avg){
               RefreshRates();
               if(OrderClose(OrderTicket(),OrderLots(),Bid,3,Red) == true)
                  position = NULL;
               else
                  Alert("ERR for selllllll: " , GetLastError());   
            }   
         }
         if(position ==IN_BUY){
            double avg = get_average();
            if(value >= avg){
               RefreshRates();
               if(OrderClose(OrderTicket(),OrderLots(),Ask,3,Red) == true)
                  position = NULL;
               else
               Alert("ERR for buyyyyy: " , GetLastError());      
            }   
         }
      }

Here is the result in testing:

Result


Keith Watford
Moderator
7887
Keith Watford 2016.01.07 23:18  

Close a Buy at Bid and a Sell at Ask

or use

  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,Red)

 for either

sohail
7
sohail 2016.01.08 07:41  

Opss .. ! Fixed.

Thanks. 

/
To add comments, please log in or register