Serving Traders Since 2005
|
|
|
|||||||
| MetaTrader Expert Advisors Post and discuss the MetaTrader expert advisors here. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
||||
|
Good Evening,
I have been trying to develop a trail stop using percentage but not having much luck. This trail stop seems to stop out at the initial trailing stop pips and I can't figure out why. This EA is a modified version of the one on the forex blog with help from admin. However it seems to stop out after 7 pips. My goal is to get this EA working and then modify it again for different trail stop levels such as 10 pips - 20% 20 pips - 40 % etc up to 60 pips at 70%. Help appreciated. MQL4 Code:
|
|
||||
|
It's quite difficult to understand how you want your trailing stop to function from your description.
For example, we are in 19 pips profit. 20% is 3.8 (rounded to 4) pips, so if Bid = 1.3420, the SL is set to 1.3416. Then profit moves up to 20 pips, now we use 40% and that's 8 pips, so if Bid = 1.3421, the SL is set to 1.3413 - below the previous level. In the end it isn't trailing anything if it can go back.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account. |
|
||||
|
Hi thanks for replying - thinking about it I probably didn't define the goal very well. Ideally - this trailing stop would have an initial start at 10 pips.
Once 10 pips were hit it would have a stop loss (not a trailing stop?!) at + 2 pips -20%. Once price hit 20 pips the stop loss would move to 40% or +8 pips. etc up to 60 pips whereupon the stop is 70% of profit which is 42 pips. The problem here is when price continues upwards how do you keep the trailing stop running at 70% of profit so you can keep with a trend and not have a stop loss sit at 42 pips? I think another function would have to take over. At the moment I have around 4 months coding experience with bools and strategies (and success!) but not the order functions. I tried to code a percentage trailing stop (with admin's help) above but this stop moves back (if you are long) when price moves back. I have also commenced coding the levels above and the trailing stop would move backwards as well. At the moment the EA above will put the stop loss on at around 8 pips and if price is at 8 pips it will get taken out very quickly. So there is something wrong there. Below is the code I did for doing different stop levels depending on profit: MQL4 Code:
|
|
||||
|
So before the last level (42 pips), the stop-loss is set only to fixed levels (2, 8, 15, 24), right? But after hitting 60 pips of profit and the SL is set to 42, it should trail every pip of profit increase as 1 to 0.7, right?
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account. |
|
||||
|
Some guidelines:
1. You'll have to check what's your current "stage" of stop-loss for a given position by comparing the current stop-loss (OrderStopLoss()) to 2 pips, 8 pips, etc. Of course, it should be done using the input parameters rather than absolute values. 2. Don't forget about MarketInfo(Symbol(), MODE_STOPLEVEL);
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account. |
|
||||
|
I couldn't get this out. I have no errors but the programming is clearly wrong as no stop loss is appearing in mt4 on the trades. I couldn't really find any clear programming examples to use either. Most of the trailing stop EAs on the net don't work. I have to research that mode stop level indication you gave.
MQL4 Code:
Last edited by Enivid; 12th December 2011 at 09:58. Reason: Syntax Highlighting |
|
||||
|
Some problems in your code:
1. You've messed up with the curly brackets big time. 2. When you set a stop-loss with OrderModify(), you have to set the price level of the stop-loss, not it's pips value. So you sl should be = Bid - (trailing_stop_level1 * PointValue). 3. Monitor your Journal tab in MT4 to see what's your EA is trying to do and why MetaTrader server rejects that.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account. |
|
||||
|
You probably have to switch the order - check the highest SL first; if it's not applicable then check lesser; if it's not applicable then the next one and so on.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account. |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 2 bar trailing stop | Easy Trader | MetaTrader Expert Advisors | 1 | 15th November 2011 15:24 |
| Whats your Risk percentage per trade? | asiaforexmentor1 | Forex Education | 9 | 1st November 2011 01:14 |
| Stop-Out Level | Enivid | Forex Brokers | 0 | 15th September 2011 08:55 |
| Hidden Stop Loss Tool - Hide your Stop Loss from Brokers | MechXTrader | General Forex Discussion | 15 | 29th April 2010 06:58 |
| How to Use Trailing Stop | forexduke | MetaTrader Indicators | 0 | 3rd April 2010 07:51 |