Download MetaTrader 5

Can i define/change trailling stop using mql4

To add comments, please log in or register
Wemerson Guimaraes
627
Wemerson Guimaraes  

Hi guys,

 

There are a way to define and change trailling stop manually via mql4 code ? 

 

I need to put the trailling stop on orders created on my EA.

t1m0thy
19
t1m0thy  
I've used this kind of thing before.....

      
      if(Bid <= trailingStop){ 
           // stop triggered      
          OrderClose( ticketId, OrderLots(), Bid, slip)
            
      }else if (Bid > high) { 
            // new high set, move stop up
            high = Bid;
           trailingStop = high - stopDist;
       }

and that would run on every tick. There is a bit more you'll add in  to confirm orders for example and you obviously also have to set the stop levels initially when you open a position but that's it in a nutshell.

Wemerson Guimaraes
627
Wemerson Guimaraes  
t1m0thy:
I've used this kind of thing before.....

      
      if(Bid <= trailingStop){ 
           // stop triggered      
          OrderClose( ticketId, OrderLots(), Bid, slip)
            
      }else if (Bid > high) { 
            // new high set, move stop up
            high = Bid;
           trailingStop = high - stopDist;
       }

and that would run on every tick. There is a bit more you'll add in  to confirm orders for example and you obviously also have to set the stop levels initially when you open a position but that's it in a nutshell.

Thanks T1m0thy, but this is a hard-coded implementation and works... but i am seeking for a way to use mql4 to activate the trailing stop resource mt4 native just lik we do manually on the image below:

Trailling 

To add comments, please log in or register