Download MetaTrader 5

Can i define/change trailling stop using mql4

To add comments, please log in or register
All Code Base apps are available from MetaTrader 5. You can publish your own one!
Wemerson Guimaraes
560
Wemerson Guimaraes 2015.09.01 18:55 

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 2015.09.01 20:52  
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
560
Wemerson Guimaraes 2015.09.01 23:35  
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