Experts: TradeProtector-1.1 - Automatic Stop Loss and proprotional Trailing Stop (updated version) - page 2

 
pipman:

Marcool, So when testing this on a demo account with 4 digits, it worked perfectly. But when I implemented this on a live account using 5 digits, the trailing SL is improperly calculated. It is about 1/5 of what it should be. I see in the mql4 code you were trying to normalize the doubles to 4 digits. Any suggestions?



Pipman,

1. I have submitted updated version - 1.2 - with some corrections, for proofreading. It should be available soon (it is already available on my blog - http://fx-perience.blogspot.com/2009/10/tradeprotector-12.html).

2. I am adding/subtracting spread to the proportional SL, for the small values of the current profit it can heavily affect resulting SL. I meant the whole thing to assist with a swing trading with profits reaching 50+. So my main concern is not to close the trade, which 'has potential yet'. If you want tight trailing, you can remove -/+ dSpread in the code:

for Buy orders, instead of dSl = NormalizeDouble( OrderOpenPrice() + dPropSLRatio*(Bid - OrderOpenPrice()) - dSpread,4 );
dSl = NormalizeDouble( OrderOpenPrice() + dPropSLRatio*(Bid - OrderOpenPrice()),5 ); - and for Sell - similarly.

Rounding to 4 digits shouldn't be a problem, of course you can change it to 5...

3. Please make sure first which SL is in use: normal or proportional.

4. I will try to test it on Alpari, I think they have 5 digits on demo as well...

 

Thank you for your hard work. You have developed very useful EA. I'm using this in my live account now. A lot of trading instructions and experts are repeating the simple mantra that is quite hard to follow: "cut your losses short and let your profits run". The second important thing is related to the money management - the famous "profit /loss ratio". Your profit must be larger than your losses to be profitable in the long run. You EA does exactly that.

I have a suggestion. Please extend the SL choises by implementing also the hedge feature - a reverse order as a SL.

 
To:

Thanks for appreciation, it's always a good thing to encourage for more effort. To implement hedging I just need to figure out what to do with a reverse position? I see following choices:

1. Treat it as any order, so if it hitting some threshold hedge it either - this will lead to a chain reaction - I know ;-),
2. Treat it with my original algorithm (no double-hedging, just kill it at some level),
3. ... any suggestions ?

Once I will know how to handle hedging orders AFTER they are open, I will have no problem to implement this. I am just not a 'hedging rat', so it's difficult for me to program something I don't even have clear idea about...

Kind regards,

Marek

 
marcool:
To:

Thanks for appreciation, it's always a good thing to encourage for more effort. To implement hedging I just need to figure out what to do with a reverse position? I see following choices:

1. Treat it as any order, so if it hitting some threshold hedge it either - this will lead to a chain reaction - I know ;-),
2. Treat it with my original algorithm (no double-hedging, just kill it at some level),
3. ... any suggestions ?

Once I will know how to handle hedging orders AFTER they are open, I will have no problem to implement this. I am just not a 'hedging rat', so it's difficult for me to program something I don't even have clear idea about...

Kind regards,

Marek


Hello, pleas read this post from the forum https://www.mql5.com/en/forum/115684 There are described a bit more advanced hedging strategy. You might be interested in it.

 
marcool:
steve321:

please advice you have a very good ea, but the when I attach to a chart it says "EA requires trade allowed"

Could you advice please.

Hi Steve,

There are two ways:
1. Tools/Options/ Expert Advisors tab

Set to "on" (mark):
Enable Expert Advisors...
Enable Live Trading
Allow DLL Imports
Allow External Experts Imports

and Disable:

Ask Manual Confirmation
Confirm DLL Function Calls

(actually my EA doesn't use DLL, but some others do, so with these settings you will be able to use any EA).

2. When you attach EA on it's options General tab you can set the same options as above (not globally though - only for this one EA).

Hi marcool, thanks for your reply.

I have never been able to use the ea as it always says the same thing. I have never been able to use any eas in my acccount apart from fap whcih I have not put on a live account yet.

I suspect my MT4 broker has messed with the platform.

I have tried to uninstal and reinstal but all in vein. Could please advice so we can know if the broker can plant a but to make ea behave in that manner.

many thanks.

 
marcool:
zenoni:

marcool wrote:

Someone also requested an option, to reverse position at certain point, instead of using S/L - I am going to implement this.

Please implement this hedging feature. Hedging is a very powerful feature if it is used properly. I have used it a lot.

I have also a simple question about Escape feature:

nUseEscape [ 1 or 0 ] - escape misplaced trades as soon as they reach some minimal profit
nEscapeLevel [pips] - lose size after which we want our trade to terminate as soon as it will reach next high
nEscapeTP [pips] - take profit level in pips (you can set to negative value - then it will be a lose that you would be happy to get, in the case your trade reached some impressive negative pips value)

Please explain how this Escape feature works, is this same as take profit ?

When your position will reach nEscapeLevel (pips) lose, the EA will set TP to a nEscapeTP (pips) value, relative to the OrderOpenPrice. It can be negative.


For instance you have opened position and the market went opposite way by 52 pips (you had no or loose SL like 100pips). You would like to minimize the lose by using 50% retracement. So set nEscapeLevel to let's say 50 and nEscapeTP to -27 or -30. It was idea I had before, I am not attached to it any more and I rather trust in tight SLs.

Regarding hedging - if you could provide me a hedging strategy - I could implement it. Of course I can put something simple like, instead of SL set pending order in opposite direction, then when it will be fired and will reach a threshold gain, set SL of the hedging order to it's OpenPrice +/- 5 pips or so. Would that make sense?

I personally don't like the idea of hedging so I need to be convinced by someone that it's better than waiting for the right point and setting tight SL :-)

Hi,

I have successfully deployed V1.2 of this very cool EA. On the original EA (v1.0) I believe that you advised using it on the M1/5 chart. Can I confirm that it will work on the H1 chart that I use? Also, I'm not sure I fully understand the settings, so at present, I haven't touched any of these. Has someone on the forum changed any of the parameters for more optimised trading? Thanks for any help and again for a very handy EA, kind regards

 

MACH26 wrote:

Hi,

I have successfully deployed V1.2 of this very cool EA. On the original EA (v1.0) I believe that you advised using it on the M1/5 chart. Can I confirm that it will work on the H1 chart that I use? Also, I'm not sure I fully understand the settings, so at present, I haven't touched any of these. Has someone on the forum changed any of the parameters for more optimised trading? Thanks for any help and again for a very handy EA, kind regards

Mach26, Thanks for a good words! I think using this EA on H1 has sense only for a very long term trading (days scale) because it's purpose is to adjust SL (stoploss) so for intra-day it might not be effective. It's also about sudden situations you don't foresee, like unexpected announcement after which price is sky-rocketing or diving 100 pips in 1 hour.

I use it on M1 and M5 - for each pair. On M1 I set

nInitialSL=15;
nTrailingStop=0; //I don't use trailing stop at all
nPropSLThreshold=12;
dPropSLRatio=0.25;

nInitialSL (pips) is set that will be applied if you forget to set yours. After profit will reach nPropSLThreshold, the "proportional SL" will be applied according to formula:

SL = OrderOpenPrice() +/- dPropSLRatio(Bid/Ask - OrderOpenPrice()) -/+ spread

For example with nPropSLRatio=0.25, for a BUY order, when it reaches 100 pips profit, it will be set to SL= OrderOpenPrice + (100* 0.25) - spread

But on M5 I set the following:

nInitialSL=0;
nTrailingStop=0; //I don't use trailing stop at all
nPropSLThreshold=50;
dPropSLRatio=0.9;

So initially, if my profit is between 12 and 50 pips, the EA is setting 'relaxed' SL of ~20% of the current profit - in order not to stop prematurely. After my trade reaches 50pips a tight SL (90% of profit) is applied, thus booking a profit ~40 pips or more.

I hope this will explain the meaning of the parameters and intention of the whole machinery :-)

Marek.

 
marcool:

MACH26 wrote:

Hi,

I have successfully deployed V1.2 of this very cool EA. On the original EA (v1.0) I believe that you advised using it on the M1/5 chart. Can I confirm that it will work on the H1 chart that I use? Also, I'm not sure I fully understand the settings, so at present, I haven't touched any of these. Has someone on the forum changed any of the parameters for more optimised trading? Thanks for any help and again for a very handy EA, kind regards

Mach26, Thanks for a good words! I think using this EA on H1 has sense only for a very long term trading (days scale) because it's purpose is to adjust SL (stoploss) so for intra-day it might not be effective. It's also about sudden situations you don't foresee, like unexpected announcement after which price is sky-rocketing or diving 100 pips in 1 hour.

I use it on M1 and M5 - for each pair. On M1 I set

nInitialSL=15;
nTrailingStop=0; //I don't use trailing stop at all
nPropSLThreshold=12;
dPropSLRatio=0.25;

nInitialSL (pips) is set that will be applied if you forget to set yours. After profit will reach nPropSLThreshold, the "proportional SL" will be applied according to formula:

SL = OrderOpenPrice() +/- dPropSLRatio(Bid/Ask - OrderOpenPrice()) -/+ spread

For example with nPropSLRatio=0.25, for a BUY order, when it reaches 100 pips profit, it will be set to SL= OrderOpenPrice + (100* 0.25) - spread

But on M5 I set the following:

nInitialSL=0;
nTrailingStop=0; //I don't use trailing stop at all
nPropSLThreshold=50;
dPropSLRatio=0.9;

So initially, if my profit is between 12 and 50 pips, the EA is setting 'relaxed' SL of ~20% of the current profit - in order not to stop prematurely. After my trade reaches 50pips a tight SL (90% of profit) is applied, thus booking a profit ~40 pips or more.

I hope this will explain the meaning of the parameters and intention of the whole machinery :-)

Marek.

Hello Marek, and thank you for replying so quickly. I will try these settings. If this was intended for the 5m chart then I assume that I can simply open a new M5 chart and place the EA on this timeframe. However, I usually order on the 1 hour chart, so the question is: Does the EA need to be on the same chart from which the order is placed? Does the EA need to be on each individual chart for every pair being traded? For example, today, I placed 6 trades on 6 seperate pairs. All orders placed on the H1 chart. So does the EA need to be placed on 6 seperate charts and if it is attached to the M5 chart, would it work with those 6 pairs? If some of these orders were placed with a stop loss and take profit, would the EA still try to close against its parameters? Finally, if the EA is on a chart where an order has been placed, will it then prevent manual placement of TP/SL's? Sorry for so many questions! Kind regards, Stephen ps where are you based?

 
MACH26:

Hello Marek, and thank you for replying so quickly. I will try these settings. If this was intended for the 5m chart then I assume that I can simply open a new M5 chart and place the EA on this timeframe. However, I usually order on the 1 hour chart, so the question is: Does the EA need to be on the same chart from which the order is placed? Does the EA need to be on each individual chart for every pair being traded? For example, today, I placed 6 trades on 6 seperate pairs. All orders placed on the H1 chart. So does the EA need to be placed on 6 seperate charts and if it is attached to the M5 chart, would it work with those 6 pairs? If some of these orders were placed with a stop loss and take profit, would the EA still try to close against its parameters? Finally, if the EA is on a chart where an order has been placed, will it then prevent manual placement of TP/SL's? Sorry for so many questions! Kind regards, Stephen ps where are you based?


Mach26,

This EA is only checking if the order is on the same currency pair (as the chart EA is attached to). I personally even use it from different location. I keep one running at home, with somehow relaxed settings. So if I would open a position at the office and lost patience and leave, the one at home would take care to move my stop. So if you trade 6 pairs, EA has to be attached to each pair's chart.
Regarding time frame - it really is up to you. If moving SL every hour is enough for you - why not to keep this EA on hourly chart?
Just have this in mind if you open a position, the initial SL will not be applied until bar on the EA's chart will arrive.

For the manually setting SL: this EA lets you keep your SL as tight as you like, but it will not let you loosen it, beyond EA's parameters.

The algorithm is to move SL only one way, so EA will apply new SL ONLY if it will be in the trade direction.

The initial SL will only be applied if there is no SL set yet.
Afther that - if you tighten SL - it will be respected, if you make bigger gap then it would be calculated by EA, than "TradeProtector" will apply it's SL.

As for TP my EA is ignoring them.

Maybe this will explain it the best (example for the BUY operation):

Start
Is order of the same currency pair?
no: break
yes: continue
Is any SL set yet
yes: calculate initial SL
no: continue
Is nPropSLThreshold exceeded?
no:
Is nTrailingStop <>0 ?
Calculate traling stop
yes:
Calculate proportional stop
calculate maximum of (current SL, initial SL, trailing stop, proportional stop) = SLmax
if SLmax > current SL
apply SL max as a new SL ;

Regarding my location, I currently live in Saudi Arabia and I am Polish.

Kind regards,

Marek.



 
marcool:
MACH26:

Hello Marek, and thank you for replying so quickly. I will try these settings. If this was intended for the 5m chart then I assume that I can simply open a new M5 chart and place the EA on this timeframe. However, I usually order on the 1 hour chart, so the question is: Does the EA need to be on the same chart from which the order is placed? Does the EA need to be on each individual chart for every pair being traded? For example, today, I placed 6 trades on 6 seperate pairs. All orders placed on the H1 chart. So does the EA need to be placed on 6 seperate charts and if it is attached to the M5 chart, would it work with those 6 pairs? If some of these orders were placed with a stop loss and take profit, would the EA still try to close against its parameters? Finally, if the EA is on a chart where an order has been placed, will it then prevent manual placement of TP/SL's? Sorry for so many questions! Kind regards, Stephen ps where are you based?

Mach26,

This EA is only checking if the order is on the same currency pair (as the chart EA is attached to). I personally even use it from different location. I keep one running at home, with somehow relaxed settings. So if I would open a position at the office and lost patience and leave, the one at home would take care to move my stop. So if you trade 6 pairs, EA has to be attached to each pair's chart.
Regarding time frame - it really is up to you. If moving SL every hour is enough for you - why not to keep this EA on hourly chart?
Just have this in mind if you open a position, the initial SL will not be applied until bar on the EA's chart will arrive.

For the manually setting SL: this EA lets you keep your SL as tight as you like, but it will not let you loosen it, beyond EA's parameters.

The algorithm is to move SL only one way, so EA will apply new SL ONLY if it will be in the trade direction.

The initial SL will only be applied if there is no SL set yet.
Afther that - if you tighten SL - it will be respected, if you make bigger gap then it would be calculated by EA, than "TradeProtector" will apply it's SL.

As for TP my EA is ignoring them.

Maybe this will explain it the best (example for the BUY operation):

Start
Is order of the same currency pair?
no: break
yes: continue
Is any SL set yet
yes: calculate initial SL
no: continue
Is nPropSLThreshold exceeded?
no:
Is nTrailingStop <>0 ?
Calculate traling stop
yes:
Calculate proportional stop
calculate maximum of (current SL, initial SL, trailing stop, proportional stop) = SLmax
if SLmax > current SL
apply SL max as a new SL ;

Regarding my location, I currently live in Saudi Arabia and I am Polish.

Kind regards,

Marek.

Marek, I'm not sure if the message I posted yesterday actually got through, however, these are the settings I have put into TP: Initial SL =40 so I expect it to close all trades at 40pips. Trailing stop at 20; I expect the SL to trail behind the price action by 20 points. nProp SL Threshold=30; at 30 points positive the trailing stop loss kicks in. nPropSLratio = 0.9; dont know what this means.


n Escape level = 40; no matter what happens at 40 pips down, the trade closes. nEscape TP =35 TP is at 35pips, however what I really need it to do is close if there is a trend change but carry on if there's a retracement (which the trailing stop loss can do) but can a TP be set where it carries on and stops out only in a retracement? Sorry if I still cant understand this but I'm getting there, kind regards, Stephen

Reason: