Hello all. This expert was created 4 years ago. Since then, MetaTrader has introduced many, many new features. This expert is no longer guaranteed to work with these newer versions of MetaTrader and I am not in a position where I can or want to create a new expert. So, read this thread at your own "risk", so to speak. Happy Trading!
I've developed an expert that is designed to help me stick to my system a bit better than what I do by myself. Use it at your own risk, though.
The expert works by taking profit out of a trade at various take profit levels. It also moves stop losses at designated levels. You have the ability to customize the following parameters:
- First_Target: This is the first take profit target, in pips, that you specify.
- Target_Increment: Once the first profit target is reached, the next target will increment by the amount specified by the target increment variable.
- Close_Lots: This is how many lots you want to take out at each target. For example, if you have 10 lots, you can take 1 lot out at each of 10 profit targets, or 5 lots out at each of two targets. It's up to you.
- Move_Stops: Set to true if you want the expert to move stops based on the First_Stop and Stop_Differential parameters. Otherwise, set to false if you don't want stops moved automatically.
- First_Stop_Target: This is the amount in pips the trade moves before your stop loss is moved to the First_Stop level.
- First_Stop: This will move your stop loss when a target, in pips, is reached. The number represents the number of pips from entry and can be postive or negative.
- Second_Stop_Target: This is the amount in pips the trade moves before your stop loss is moved to the Second_Stop level.
- Second_Stop: This will move your stop loss when a target, in pips, is reached. The number represents the number of pips from entry and can be postive or negative.
- Use_Max_Loss: Set to true if you want to input your own stoploss and hide your stop value from your broker. This is the maximum loss you'll risk on the trade. It's irrelevant if Move_Stops is set to true AND Move_Stops was triggered.
- Max_Loss: This is the maximum pip loss you'll accept on the trade. If set to 0, this function is disabled.
- Magic_Number: You can use this to ensure the expert only manages trades with a particular magic number. This will allow you to trade the same pair using different systems without this expert interfering with the take profit points of the other trade(s).
The image below represents example parameters that can be set for the expert. I'll explain each one with a scenario. Assume you place a 1 lot sell order for EURUSD at 1.2100 (1.2103/1.2100 - ask/bid). (Assume a 3 pip spread.)
- The expert will take .1 lots ("Close_Lots"), or 1/10th of this scenario's order, out at +10 pips ("First_Target"), or 1.2090/1.2087.
- After that, the next profit target will increment 8 pips ("Target_Increment") to 1.2082/1.2079. and another .1 lots will be taken out at that level. The expert continues to increment the preceding profit target by 8 pips until the original order is closed. In this example, the maximum pips gained would be 10 + (8*9), or 82 pips. (First target pips + increment pips * number of times to increment, which would vary depending on the original order size and the "Close_Lots" parameter.)
- When the trade reaches +15 pips ("First_Stop_Target"), the stop loss will be moved to -5 pips ("First_Stop") from the order entry price. In this case, the order entry price was 1.2100, so the new price would be 1.2105. This means that you would lose 5 pips if the trade turned. Set the "Stop_Differential" parameter to "0" in order to move stops to breakeven (1.2100). If this parameter were, for example, set to 5, then the stop loss would be moved to 1.2095, and you would have a 5 pip increase if the move turned against you and stopped you out.
- When the trade reaches +30 pips (Second_Stop_Target), the SL is moved to Entry Price + 10 pips.
- If you don't want the expert to move the order's stop loss, then set the "Move_Stops" parameter to "false". I think this works, but haven't fully tested it.
In case you're wondering, the reason I wrote this is so that I didn't have to place 5 different stop loss orders in order to manage different take profit levels. Since I don't want to sit in front of the computer all the time, waiting for these levels to hit and I take out a portion of the order, I figured an expert would do just the thing.
** Important **
I've found that if I'm in the middle of trade and make a change to the expert parameters, it resets everything. So, here's an example. Let's say that I want to take 1 lot out at 20 pips and another out at 40 pips. The price moves to 25 pips and takes out my first lot. I decide that I want to change my stop rules to move stops from breakeven to +10 pips if the price goes to +30 pips. The problem is, my take profit had incremented to watch for +40 pips but my initial target is still set to 20. If I close the expert, it resets the incremented value to the initial target. Since the price is now +25 pips and my initial target is set to 20, even though the expert incremented to 40 as the next target, the reset causes my second lot to be taken out.
So, if you're targets have incremented and you want to change your move stops or any other value, make sure you make your initial target to be the new next target you want to take profit out at.
11/2/2006 (v2.3) :: Fixed bug that caused the sl var to be set to 1 when a pending order was > than the First_Stop_Target value. In other words, if a pending order was in, not an actual order, and the price was greater than First_Stop_Target pips from the pending order entry, then the expert would honor the second move stops stop target, and skip the first.
1/23/2007 (v2.4) :: Fixed pip calculation. The old way of calculating pips could be off by 1 pip, resulting in missed TP or move stops. The new calculation is more accurate.