View Single Post
  #16 (permalink)  
Old 05-13-2007, 01:45 AM
COTtrader COTtrader is offline
Member
 
Join Date: Apr 2006
Posts: 62
COTtrader is on a distinguished road
Here is one suggested my ND that is niffty!!!

The following was written by Stockwet ---


Manage Take Profit

The expert works by taking profit out of a trade at various take profit 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: This will move your stoploss when a target, in pips, is reached.

Stop_Differential: This is the number of pips away from the original order entry price to set the new stop. By default, it's set to 0 but can be positive 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: 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"), the original stop loss will be moved to -5 pips ("Stop_Differential") 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.

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.
I must warn everyone that I am not a sophisticated MQ4 programmer. Use this at your own risk. If one of you crack programmers can improve it, please feel free to do so.

Also, 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.

Regards,

stockwet

(COTtrader)
Attached Files
File Type: mq4 ManageTPv2-1.mq4 (5.3 KB, 1006 views)
Reply With Quote