Download MetaTrader 5

suggestions with close orders with profit and trailing stop

To add comments, please log in or register
sergio daniel mazza
175
sergio daniel mazza  

hello I need the suggestions of you, I have this portion of code where I close orders if I gain, besides that let profits run with a difference of 10 percent. I do this because my broker has long takeprofit and I want to close faster.
this

extern double MinProfit=1.30;
extern double TrailingStop=10;
double NewProfit;
double BottomProfit;

void closeOrders(){
   for( int i = OrdersTotal() -1; i >= 0 ; i -- ) {
   if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == false ) break;
      if( OrderSymbol() == Symbol() ){ 
         RefreshRates();
            if(( OrderProfit() >= MinProfit)){
               if(( OrderProfit() >= NewProfit)){
               NewProfit=OrderProfit();
               BottomProfit=OrderProfit()-(OrderProfit()*TrailingStop/100);
               break;
               }else{                              
               if(( OrderProfit() <= BottomProfit) && (OrderProfit() >= MinProfit)){
               if( OrderType() == OP_BUY ){
                  Alert("OP: "+ OrderProfit()+" BP: "+BottomProfit+" MP: "+ MinProfit+" NP: "+NewProfit);
                  PlaySound(SoundFileClosed);
                  if (!OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), 0,White ))
                  {
                     logError("closeOrders()", "Error closing BUY order TicketNumber: "+OrderTicket());
                  }
                                          }
               if( OrderType() == OP_SELL ){
                  Alert("OP: "+ OrderProfit()+" BP: "+BottomProfit+" MP: "+ MinProfit+" NP: "+NewProfit);
                  PlaySound(SoundFileClosed);
                  if (!OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), 0,Blue ))
                  {
                     logError("closeOrders()", "Error closing SELL orderTicketNumber: "+OrderTicket());
                  }
               }                            }
               }
               }
         }
      }
   }

module seems good as done?

To add comments, please log in or register