I've used this kind of thing before.....
if(Bid <= trailingStop){
// stop triggered
OrderClose( ticketId, OrderLots(), Bid, slip)
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;
}
// 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.
t1m0thy:
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.
I've used this kind of thing before.....
if(Bid <= trailingStop){
// stop triggered
OrderClose( ticketId, OrderLots(), Bid, slip)
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;
}
// 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:
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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.