wemersonrv

OrderModify MQL4

Dec 24th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. for(int i=OrdersTotal()-1;i>=0;i--){
  2.      
  3.     if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES) ){
  4.  
  5.         // Pula ordens que não sejam desse gráfico
  6.         if( OrderSymbol() != Symbol() && OrderMagicNumber != MagicNumber){ continue; }
  7.          
  8.         trailling = false;        
  9.  
  10.         if(OrderType()==OP_BUY ){
  11.             if(Bid - OrderStopLoss() >= TraillingStop*pointer){
  12.                 SL=NormalizeDouble(Bid-StopLoss*pointer, Digits);
  13.                 if( SL > OrderStopLoss() ){ trailling = true; }
  14.             }
  15.         }        
  16.  
  17.         if(OrderType()==OP_SELL  ){
  18.             if(OrderStopLoss() - Ask >= TraillingStop*pointer){
  19.                 SL=NormalizeDouble(Ask+StopLoss*pointer, Digits);
  20.                 if( SL < OrderStopLoss() ){ trailling = true; }
  21.             }
  22.          }
  23.          
  24.         if(trailling){
  25.             if( !OrderModify(OrderTicket(), OrderOpenPrice(), SL, OrderTakeProfit(), 0) ){
  26.                 int Error = GetLastError();
  27.                 string ErrorText = ErrorDescription(Error);
  28.                 StringToUpper( ErrorText );
  29.                 Print("Ordem #", OrderTicket(), " não foi modificada. Código Erro: ", Error, " \"", ErrorText, "\"" );
  30.             }
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment