stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

MPTM_Global
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=1633
Page 1 of 14
Author:  global [ Tue Jan 08, 2013 6:11 pm ]
Post subject:  MPTM_Global

Here is my changed version of MPTM renamed as "MPTM_Global" with my Additions & Modifications (ADMod). I added some stuff to the tighten stoploss feature to tighten it at four different percentages of either the take profit or the ATR and to do that automatically depending on whether or not a TP is set. If you set your SL based on the ATR volatility of the pair, and set no TP, the EA will automatically let your profits run by trailing the price movement as far as it will go based on percentages of the ATR. The main purpose of this modification is to help with one of the Golden Rules of Trading, to minimize your losses and allow your profits to run (do not close your position before it is required by your system).

You can now also set the breakevenpips based on a percentage of either the ATR or the TP. The mode the EA used to set the Tightening Stops (Ts) and BreakEvenPips will be displayed in the EA comments on your chart along with the value of the take profit (TP) or ATR if they were used.

Example: (Mode: TS %ATR) ATR: 159 pips or (Mode: BE %TP) TP: 80 pips
Or (Mode: BE STD) and (Mode: TS StdTP) for the standard MPTM original feature settings.

I also added the feature to close all orders if you lose a chosen percentage of your account balance. So if for example you want to close all orders when your trading loss reaches 5% of your account balance, then set PercentProfitLoss to -5. I'm experimenting with various percentages to see what works best for the trading strategy I'm using. I use the ManageThisPairOnly option and attach the EA to each chart I open a trade on. All the default settings in my modified version are what I'm currently testing.

My broker uses 5 digits and 3 digits for JPY pairs and since I encountered some weird behavior in relation to the points and pips stuff, I made some changes that work for me. At first I wasn't sure if I had to enter 200 for 20pips in this EA but now I'm sure that it is working so that a 20 pip input is equal to 20pips.

I use the attached EA for my D1 trades and I saved H4 and H1 versions with 240 and 60 TimeFrame values instead of 1440.

I did not test the Global order closure with my added PercentProfitLoss feature but it should work. I also never tested the hidden stop loss features that came with MPTM since so far I didn't need it. Anyway, I made these changes for my own use but then I thought that I should share my modified version with everyone just as Steve shared all his hard work with us all. So I hope that the changes are useful to you and maybe someone might modify it to make it even better.

UPDATED VERSION: I replaced the attached file with the updated version that uses the same name so if you downloaded the previous version then please redownload the updated one. I only made additions and modifications to the BreakEven, Tightening stop and Global order closure features of MPTM so I did not change anything else, therefore, all the other features should work as before. In this update I plugged a few loopholes that generated crazy values if users put in the wrong combination of inputs and I also added short descriptions of each new feature to the EA input dialog window.

If the descriptions are cut off because Empty4 doesn't allow resizing of their EA input dialog box, then I suggest that you use the very small portable ResizeEnable program for PCs to turn Non-Resizeable Windows into Resizeable Windows so that you can easily see the full descriptions. The full descriptions are self-explanatory so no manual is required. You can also use the InputResizer EA/Indicator from http://www.forexfactory.com/showthread.php?t=299017 but I prefer the easier to use ResizeEnable that sits in your system tray.

To find all the changes I made with some additional descriptions of each change, just search for all the sections within the code beginning with the comment "Added by ADMod".

You can read about ResizeEnable here:

http://www.howtogeek.com/howto/11799/tu ... e-windows/

And you can download it here:

http://www.digitallis.co.uk/pc/ResizeEnable/index.html

UPDATE Jan 22nd, 2013: For all pips values in the code that were declared as integers, I re-declared them as decimal "double" data types because Steve discovered an Empty4 program anomaly with how it calculates a mixture of int and double data type variables in certain circumstances. I tested it and everything seems fine so I replaced the attached file with the updated one.


UPDATE Feb 4th, 2013: In this update I just cleaned up the formatting of the input code a bit and changed the default setting of the "PartCloseEnabled" setting to false. Therefore, except for the change of the default "PartCloseEnabled" setting, this update does not change the functionality of my MPTM_Global version in any way.

UPDATE March 13th, 2013: In this update I added a few new features that may make it a little more difficult for you to set up MPTM correctly. Nevertheless, once you read the descriptions of the new features in the EA input dialog box, understand how they all work together and set up MPTM just as you like it, then managing your trades will be as easy as just clicking your mouse.

In this update I added the following options:

1) A Tightening stop option to replace the 4 target levels: TrailAt25%, 50%, 75% & 85% of the Take Profit (TP), with 4 PIP targets. When these PIP targets are hit, your JumpingStopPips or TrailingStopPips will move to the x number of pips you specify.

2) An option to set your TrailingStopPips & JumpingStopPips as percentages of the TP. This overrides the TrailingStopPips & JumpingStopPips values from the Jumpingstoploss & Trailingstoploss settings.

3) An option to set the TrailingStopPips & JumpingStopPips as percentages of the ATR. This overrides the TrailingStopPips & JumpingStopPips values from the Trailingstoploss & Jumpingstoploss settings.

I also changed some of the EA input descriptions a bit to make things a little clearer. The default settings are for setting the Break Even, Trailing/Jumping and Tightening Stops based on percentages of the Take Profit (TP). I'm currently experimenting with those default values but of course you can change the settings as you like and set the Break Even, Trailing/Jumping and Tightening Stops as fixed pips or set them based on percentages of the ATR.

Once your settings are all based on your Take Profit, as in this updated version, you can use the EA with any timeframe since no ATRs are used in the calculations. If you like you can modify the code to hard code your settings and save the EA with a different name such as "MPTM_Global.mq4" or any name you like without the _D1, _H4, etc suffixes to remind yourself that it can be used with any timeframe without the need to change any settings.

UPDATE March 15th, 2013: Fixed the MPTM_Global EA screen comment error where the "Trailing stop on and set to xx% ATR: xx pips" was displaying the TrailJumpStopPercentageTP value instead of the TrailJumpStopPercentageATR value.

Note: If you use the Tightening Stop Feature and select UseTrailJumpStopPercentageATR or UseTrailJumpStopPercentageTP as true, then the xx number of pips in the EA screen comment message "Trailing/Jumping stop on and set to xx% ATR: xx pips" or "Trailing/Jumping stop on and set to xx% TP: xx pips" will change as your Trailing or Jumping stops tighten BUT the initial xx% ATR or xx% TP value will remain the same to show the initial Trailing Stop or Jumping Stop % ATR or % TP value you selected.

March 16th, 2013 Update: Changed EA name to "MPTM_Global" from the old name "Multi purpose trade managerADMod_D1." I only changed the name so the code is exactly the same as before. Since essential truth spoken concisely is true eloquence I prefer the shorter name to the old one.

Go to this post and the replies that follow it for some suggestions on how to modify the code yourself and how to use my MPTM_Global ATR settings on different timeframes: http://www.stevehopwoodforex.com/phpBB3 ... 134#p36134

Here is the link to the post by milanese with MPTM_Global_6xx.mq4 updated for the updated Empty4 build 600:
http://www.stevehopwoodforex.com/phpBB3 ... 173#p86035

The attachment below is for previous builds. I will replace it with the milanese's update once it has been tested.
Author:  KevinT [ Wed Jan 09, 2013 6:22 am ]
Post subject:  Re: MPTM Added to & Modified (AdMod)

global wrote:Here is my changed version of MPTM with my Additions & Modifications (ADMod). (...) I made these changes for my own use but then I thought that I should share my modified version with everyone just as Steve shared all his hard work with us all. So I hope that the changes are useful to you and maybe someone might modify it to make it even better.
:o :) :D Thank you very much global that´s the spirit :!:
Author:  global [ Wed Jan 09, 2013 1:43 pm ]
Post subject:  Re: MPTM Added to & Modified (AdMod)

KevinT wrote: :o :) :D Thank you very much global that´s the spirit :!:
You are welcome KevinT. I wanted to modify it further so that with ManageAllTrades set to true I could just attach the EA to one chart and have it manage all my open trades without having to open charts for each open trade and attach the EA to each chart. I especially wanted to do that because I do my charting with one broker on a demo account and my one click trades are copied instantly with MT4i Personal Trade Copier to another Empty4 installation connected to my real broker with lot sizes automatically adjusted. That way it's much faster than opening up the charts with my template in the second installation and manually entering SL & TP, etc., plus faster means more profits. I do my trade analysis based on the New York Daily candle open/close time on my demo broker since time shift indicators like P4L Period Con to change the daily open time on my real broker to NY time don't work with all the indicators on my template so I have to use the demo broker for charting. Unfortunately, I don't have the time for such a ManageAllTrades modification so I'll just have to continue doing it the long way for now.

I think that for such a modification to work, the EA will have to set global variables for each open trade when it cycles through the open trades as the ticks come in. Plus if you want to manage trades made on different timeframes that use the ATR stuff then you will have set a different magic number for trades on different timeframes so that MPTM will know what timeframe to use for calculating the ATRs when it cycles through the open trades. MPTM is the best trade manager I've found and with everyone's help it will get even better.
Author:  global [ Sun Jan 13, 2013 3:03 pm ]
Post subject:  Re: MPTM's new home

Tomorrow I will upload an additional modification of my AdMod version. There were a few loopholes that generated crazy values if users put in the wrong combination of inputs so I plugged those and added more descriptions of what the new input sections do. I'm waiting on the market to open tonight so I can test the changes before I upload it tomorrow.
Author:  global [ Thu Jan 17, 2013 9:11 am ]
Post subject:  Re: MPTM's new home

UPDATED VERSION: I updated my changed version of MPTM with my Additions & Modifications (ADMod). I replaced the file attached to my original post with the updated version that uses the same file name "Multi purpose trade managerADMod_D1.mq4" so if you downloaded the previous version then please redownload the updated one.

For some more explanation about my modified version just go here to the original post with the updated attached file: http://www.stevehopwoodforex.com/phpBB3 ... 816#p34816

I only made additions and modifications to the BreakEven, Tightening stop and Global order closure features of MPTM so I did not change anything else, therefore, all the other features should work as before. In this update I plugged a few loopholes that generated crazy values if users put in the wrong combination of inputs and I also added short descriptions of each new feature to the EA input dialog window.

If the descriptions are cut off because Empty4 doesn't allow resizing of their EA input dialog box, then I suggest that you use the very small portable ResizeEnable program for PCs to turn Non-Resizeable Windows into Resizeable Windows so that you can easily see the full descriptions. The full descriptions are self-explanatory so no manual is required. You can also use the InputResizer EA/Indicator from http://www.forexfactory.com/showthread.php?t=299017 but I prefer the easier to use ResizeEnable that sits in your system tray.

To find all the changes I made with some additional descriptions of each change, just search for all the sections within the code beginning with the comment "Added by ADMod".

You can read about ResizeEnable here:

http://www.howtogeek.com/howto/11799/tu ... e-windows/

And you can download it here:

http://www.digitallis.co.uk/pc/ResizeEnable/index.html
Author:  Mike [ Sat Jan 19, 2013 8:57 am ]
Post subject:  Re: MPTM's new home

global wrote:... my changed version of MPTM with my Additions & Modifications (ADMod): http://www.stevehopwoodforex.com/phpBB3 ... 816#p34816
Hi global
Great modifications. Just to be sure: Do all settings based on "percentages of the ATR" have to be set on every single chart or pair and is trading by "Magic Number" or "Comment" or all pairs incompatible? (The bot's info is specific for the chart it is on.)
Mike
Author:  KevinT [ Sat Jan 19, 2013 9:00 am ]
Post subject:  Re: MPTM's new home

Great post... been busy digesting other advances here (no time to reply :oops: ) Nice everything... When we use all this, posts will pour in Global(not Prime :lol: ) AWESOME JOB 8-)
global wrote:UPDATED VERSION: I updated my changed version of MPTM with my Additions & Modifications (ADMod). I replaced the file attached to my original post with the updated version that uses the same file name "Multi purpose trade managerADMod_D1.mq4" so if you downloaded the previous version then please redownload the updated one.

For some more explanation about my modified version just go here to the original post with the updated attached file: http://www.stevehopwoodforex.com/phpBB3 ... 816#p34816

I only made additions and modifications to the BreakEven, Tightening stop and Global order closure features of MPTM so I did not change anything else, therefore, all the other features should work as before. In this update I plugged a few loopholes that generated crazy values if users put in the wrong combination of inputs and I also added short descriptions of each new feature to the EA input dialog window.

If the descriptions are cut off because Empty4 doesn't allow resizing of their EA input dialog box, then I suggest that you use the very small portable ResizeEnable program for PCs to turn Non-Resizeable Windows into Resizeable Windows so that you can easily see the full descriptions. The full descriptions are self-explanatory so no manual is required. You can also use the InputResizer EA/Indicator from http://www.forexfactory.com/showthread.php?t=299017 but I prefer the easier to use ResizeEnable that sits in your system tray.

To find all the changes I made with some additional descriptions of each change, just search for all the sections within the code beginning with the comment "Added by ADMod".

You can read about ResizeEnable here:

http://www.howtogeek.com/howto/11799/tu ... e-windows/

And you can download it here:

http://www.digitallis.co.uk/pc/ResizeEnable/index.html
Author:  global [ Sat Jan 19, 2013 8:00 pm ]
Post subject:  Re: MPTM's new home

Mike wrote:
global wrote:... my changed version of MPTM with my Additions & Modifications (ADMod): http://www.stevehopwoodforex.com/phpBB3 ... 816#p34816
Hi global
Great modifications. Just to be sure: Do all settings based on "percentages of the ATR" have to be set on every single chart or pair and is trading by "Magic Number" or "Comment" or all pairs incompatible? (The bot's info is specific for the chart it is on.)
Mike
For the same timeframe, I use the same ATR settings for all pairs and I attach the EA with the same ATR settings on each chart. For different timeframes, you will have to use different settings and the easiest way to do that is by saving the EA with different names for each timeframe. If you don't already know how to do that then just read below for an explanation.

To use the EA ATR settings on different timeframes, the best thing to do is right click on the EA in the Navigator->Expert Advisors list, then click "Modify" to open up the EA in the MetaEditor, change the settings to what you want, then save the EA with a modified name suffix -- I use the D1, H4 and H1 suffixes since I use different settings for different timeframes. Then click the compile button to convert your changed mq4 file to a compiled ex4 file Empty4 can use. Then restart Empty4 so that your modified renamed EA will show up in theNavigator->Expert Advisors list. So with my settings for different timeframes saved in differently named EAs, if I open an H4 trade I just use the H4 EA, and if I open a D1 trade I just use the D1 EA, etc.

The correct ATR for each chart on the same timeframe will be calculated by the EA with the percentages you chose. I don't like having to change settings every time I attach the EA to a chart so my modifications make it more set and forget. Sometimes I set a takeprofit and sometimes I don't when I want my profits to run as far as possible followed by trailing tightening stops. In that case, without a TP, I prefer to use the 20 period ATR as the TP target level that the trailing/jumping tightening stop percentages are based on. So for every trade I open, I just attach the EA with my settings and I can feel confident that it will efficiently manage the trades to squeeze out the most profits.

I found that the only way for MPTM to manage multiple charts with different pairs correctly was to set it to use the ManageThisPairOnly option and attach the EA to each chart I open a trade on. I tried the ManageAllTrades option but I got crazy values and results so that did not work for me. One reason for ManageAllTrades not working for different pairs simultaneously is because one setting such as ATR will produce one value for the chart the EA is attached to and that value will be wrong for the other pairs. I did not try ManageByMagicNumber or ManageByTradeComment so I can't comment on that.

ManageByTickeNumber did not work as expected with ManageThisPairOnly but only ManageThisPairOnly by itself when attached to each chart worked fine.

By the way, I saw that Steve made a modification to the pipfactor code so I'll have a look at the code and modify my version as well with Steve's update.
Author:  Mike [ Sat Jan 19, 2013 10:20 pm ]
Post subject:  Re: MPTM's new home

global wrote:
Mike wrote:
global wrote:... my changed version of MPTM with my Additions & Modifications (ADMod): http://www.stevehopwoodforex.com/phpBB3 ... 816#p34816
Hi global
Great modifications. Just to be sure: Do all settings based on "percentages of the ATR" have to be set on every single chart or pair and is trading by "Magic Number" or "Comment" or all pairs incompatible? (The bot's info is specific for the chart it is on.)
Mike
For the same timeframe, I use the same ATR settings for all pairs and I attach the EA with the same ATR settings on each chart. For different timeframes, you will have to use different settings and the easiest way to do that is by saving the EA with different names for each timeframe. If you don't already know how to do that then just read below for an explanation.
Thanks ... clear explanation. What I did: save and compile a version each for D1, H4, H1 by opening the meta editor using Find 1440 Replace all by 240 for H4/ Replace all by 60 for H1. I hope I did not mess up anything.
What I also would like to do is to eliminate all options in the Custom Indicator window, which I do not intend to use for this kind of trade management, but I do not know how (Example):
extern bool ManageByMagicNumber=false;
change to
bool ManageByMagicNumber=false;
but I actuall have no idea what I am really doing.
Thanks again for your modifications and explanations
Mike
Author:  global [ Sat Jan 19, 2013 10:47 pm ]
Post subject:  Re: MPTM's new home

SteveHopwood wrote:If, say, StopLoss is declared as an integer as in int StopLoss = 20:
double NewStop = NewStop = OrderOpenPrice() - (StopLoss * Point); is allowed and (StopLoss * Point) creates a 0.xxxxxxxx result.

The command using factor is OrderOpenPrice() - (StopLoss / factor); But, if StopLoss is an integer then the code (StopLoss / factor) returns a zero value.

All the pip values in mptm were declared as integers, so when interacting with factor resulted in 0 being added to whatever the bot was supposed to be doing, and so trades were closing prematurely. All that was needed was to convert them to doubles - something Paul forgot to do and that I did not notice.

So, fix is in post 1; sing out if I am barking at the wrong moon and the fix does not work.
:D
Thanks for the update Steve. I checked your updated code and I'm wondering if the int iPipsAboveVisual variable in line 901 needs to be converted to double iPipsAboveVisual from this line of code...

Code: Select all

bool CheckForHiddenStopLossHit(int type, int iPipsAboveVisual, double stop )
...because a little further down you divide iPipsAboveVisual by Pipfactor as below:

Code: Select all

double sl = NormalizeDouble(stop + (iPipsAboveVisual /Pipfactor), digits);
All times are UTC Page 1 of 14