Hi,
give away simple trailing stop loss code for plugging in any EA. (if you are lazy to make one)
I want to give this back to ff community and much as I take the knowledge from here.
Below is the code snippet that I use for trailing stop loss. It does not have much flexible setting and a bunch or usage application but if your newly create system does work on just a few order at a time then this thing work very well ( for me at least).
How to use?
very simple. place below code in any part of your Expert Advisor program and call the function trail2(#ticket) in the Start() function.
give away simple trailing stop loss code for plugging in any EA. (if you are lazy to make one)
I want to give this back to ff community and much as I take the knowledge from here.
Below is the code snippet that I use for trailing stop loss. It does not have much flexible setting and a bunch or usage application but if your newly create system does work on just a few order at a time then this thing work very well ( for me at least).
How to use?
very simple. place below code in any part of your Expert Advisor program and call the function trail2(#ticket) in the Start() function.
ticket = is your order ticket, it could be either buy or sell order. But it has to be live order not pending order.
e.g.
{...(yourcode)
ticket=ordersend(...)
...
}
..
trail2(ticket)
or trail2(ticket, 300, 40, 250, 100)
..
- all of them (t1-t4) are integer
- they are all points (10 points = 1 pip), so 150 means 15 pips, 30 means 3 pips
- t1 = distance from market price to opened price when that order is profit while stop loss is set under or over the open price (buy or sell relatively)
- if buy order, market price must be higher than opened price by t1 points
- if sell order, market price must be lower than opened price by t1 points
- t2 = distance which the code will move the stop loss to over or under the open price (according to buy or sell position) after the market price is satisfied by t1 points
- t3 = distance from market price to current stop loss when that order is profit while stop loss is set over or under the open price (buy or sell relatively), means that order already in profit and already locked in some profit.
- if buy order, market price must be higher than current stop loss price by t3 points
- if sell order, market price must be lower than current stop loss price by t3 points
- t4 = distance which the code will move the stop loss away from current stop loss (according to buy or sell position) after the market price is satisfied by t3 points. If buy, it move stop loss up, if sell it move stop loss down by t4 points
You can diverse the input for this function by either input price instead of distance from opened price or stop loss price but need to edit the code a little bit.
if the order already closed, and you give it the ticket number it will do nothing and show nothing.
Attached Image
Attached File(s)
trail2.mqh
3 KB
|
581 downloads
Holy grail, pls pm