Download MetaTrader 5

Newbie needs help with PositionModify please

To add comments, please log in or register
Cristo
54
Cristo  

Hi all,

I am using CTrade class to do a trailling stop. It works perfectly but the problem is that  my EA after doesn't open more positions.


If i leave my trailing stop, my EA is working without problems but if i put the trailing stop, at the moment that one position is using the trailing, the EA doesnt work more.

I have used this "trade.SetExpertMagicNumber(magicNumber);" because i was reading the CTrade class and the method "PositionModify" needs the magic number, i am not sure. 

Please, i dont know what to do to work it. 

 


With trailing Stop 

 

 Without trailingStop

 

testing only buy_positions 

 

 if(vendido==true){
        if(PositionSelect(_Symbol)){
            if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY){
        
            pr=NormalizeDouble((SymbolInfoDouble(_Symbol,SYMBOL_BID)-PositionGetDouble(POSITION_PRICE_OPEN)),_Digits)/_Point;
            profit=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID)-PositionGetDouble(POSITION_PRICE_OPEN),_Digits)/_Point;
            new_TP=NormalizeDouble(PositionGetDouble(POSITION_PRICE_OPEN)+(TP*_Point),_Digits);
            new_sl=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID)-(StopLoss*_Point),_Digits);
            
          
           if(profit>=StopLoss){ //int StopLoss=400 int TP=800
               
              
               if(trade.PositionModify(_Symbol,new_sl,TP))
                  Print("Todo bien: ",trade.ResultRetcode()," , ",trade.ResultRetcodeDescription());
               else
                  Print("Todo mal: ",trade.ResultRetcode()," , ",trade.ResultRetcodeDescription());
            } 
            
            if(pr>=TP){   
                  trade.PositionClose(_Symbol);
                  vendido=false; //to check the EA doesn't open 2 positions at same time
               }
               if(pr<=-StopLoss){ //StopLoss int 400
                  trade.PositionClose(_Symbol);
                  vendido=false;
               }
                }

 

 Greetings and thx

 

     

Joao Felipe Gomes de Araujo
40
Joao Felipe Gomes de Araujo  
GetLastError()
To add comments, please log in or register