Breakeven falha na execução Mql5 ? [RESOLVIDO]

 

Estou tentando fazer com que quando o preço caminhar 100 pontos, o Stop Loss va para a posição de abertura da ordem, mas tem horas que falha, simplesmente o SL não vai para a posição.

Como resolver esse problema ?


void startBreakeven(ulong mn, double points = 100){ 

   CTrade _trade;
   CSymbolInfo _simbolo;
   _simbolo.Name(_Symbol);   
   _simbolo.RefreshRates();
   
   double _PontosBreakeven = NormalizeDouble(points,0);   
   
   if(PositionsTotal() > 0 && points > 0){
    
      for(int x = 0 ; x <= PositionsTotal(); x++){
         string _symbol = PositionGetSymbol(x);
         ulong _magicNumber = PositionGetInteger(POSITION_MAGIC);
         if(_symbol == _Symbol && _magicNumber == mn){
            ulong _positionTicket = PositionGetInteger(POSITION_TICKET);
            double _currentSL = PositionGetDouble(POSITION_SL);
            double _currentTP = PositionGetDouble(POSITION_TP);
            double _positionOpened = PositionGetDouble(POSITION_PRICE_OPEN);
            
            if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY && _PontosBreakeven > 0){
               //comprado
               double Bid = _simbolo.Bid();
               if(Bid >= (_PontosBreakeven + _positionOpened * _Point)){                     
                     _trade.PositionModify(_positionTicket, _positionOpened * _Point, _currentTP);
               }
            }
            
            if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY && _PontosBreakeven > _currentTP){
               //vendido
               double Ask = _simbolo.Ask();
               if(Ask <= (_PontosBreakeven - _positionOpened * _Point)){                     
                     _trade.PositionModify(_positionTicket, _positionOpened * _Point, _currentTP);
               }
            }
            
         }         
      }
   }
   
   
}//startBreakeven



void OnTick()  {
     startBreakeven(MagicNumber);      
}
 

Resolvido. Não me atentei que era apenas na venda que não estava funcionando. Agora esta 100%


void startBreakeven(ulong mn, double points = 100){ 

   CTrade _trade;
   CSymbolInfo _simbolo;
   _simbolo.Name(_Symbol);   
   _simbolo.RefreshRates();   
   
   double _PontosBreakeven = 0;
   _PontosBreakeven = NormalizeDouble(points,0);   
   
   if(PositionsTotal() > 0 && points > 0){
    
      for(int x = 0 ; x <= PositionsTotal(); x++){
         string _symbol = PositionGetSymbol(x);
         ulong _magicNumber = PositionGetInteger(POSITION_MAGIC);
         if(_symbol == _Symbol && _magicNumber == mn){
            ulong _positionTicket = PositionGetInteger(POSITION_TICKET);
            double _currentSL = PositionGetDouble(POSITION_SL);
            double _currentTP = PositionGetDouble(POSITION_TP);
            double _positionOpened = PositionGetDouble(POSITION_PRICE_OPEN);
            
            if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY && _PontosBreakeven > 0){
               //comprado
               double Bid = _simbolo.Bid();
               if(Bid >= (_PontosBreakeven + _positionOpened * _Point)){                     
                     _trade.PositionModify(_positionTicket, _positionOpened * _Point, _currentTP);
               }
            }
            
            if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL && _PontosBreakeven > 0){
               //vendido
               double Ask = _simbolo.Ask();               
               if(Ask <= (_positionOpened - _PontosBreakeven  * _Point)){                     
                     _trade.PositionModify(_positionTicket, _positionOpened * _Point, _currentTP);
               }
            }
            
         }         
      }
   }
   
   
}//startBreakeven