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

 

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

Updated version of the http://codebase.mql4.com/6043

Author: Marek

 

10+

 
SRbg:

10+

how can i change the parameters of the running trade?

 
sliffy:

how can i change the parameters of the running trade?

I am not sure if I understand your question. If you attach this EA to the chart with the same currency pair as the running trade (open position), EA will - at each bar arrival - check prices and compare them to the EA parameters, and if needed, it will adjust S/L of the open position.
So if you have opened position, and then you will attach "TradeProtector" to the chart, it will start processing your position (as long as it has the same currency symbol, as the chart to which EA is attached).

Does it answer your question?

Btw. - After using it for a while I decided to change it a bit: It will apply initial S/L and don't use Trailing Stop until position will reach certain profit. Then it will start to use proportional S/L:


S/L = OpenPrice +/- (CurrentPrice - OpenPrice) * dPropSLRatio

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

 
marcool:
sliffy:

how can i change the parameters of the running trade?

I am not sure if I understand your question. If you attach this EA to the chart with the same currency pair as the running trade (open position), EA will - at each bar arrival - check prices and compare them to the EA parameters, and if needed, it will adjust S/L of the open position.
So if you have opened position, and then you will attach "TradeProtector" to the chart, it will start processing your position (as long as it has the same currency symbol, as the chart to which EA is attached).

Does it answer your question?

Btw. - After using it for a while I decided to change it a bit: It will apply initial S/L and don't use Trailing Stop until position will reach certain profit. Then it will start to use proportional S/L:


S/L = OpenPrice +/- (CurrentPrice - OpenPrice) * dPropSLRatio

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


thanks for the answer.... i try to be more specific

let's say i put trade_protector on the chart and it began to work but after a while i change my mind and i would like to change the parameters... how can i do it?

the changed parameters will be appear in the next trade only

btw. yes, it will be better when the initial sl won't move with the current rate... pls code it :o)

 

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 ?

 
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 :-)

 

marcool wrote:

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 :-)

Here is the basic hedging strategy, please consider to implement this.

  Instead of using SL we are using reverse orders to hedge position (if market turns againts the trade we are become to be flat on the singel position). Hedging assumes multiple pair of orders management. The simulatneous sell and buy positions need to be treated together as a pair. There may be logic to handgle pairs and orphan orders (orders that are at loss without hedging order)

Hedging senario for the uptrend.

Lets assume we are trading long EUR/GBP. We buy first position at 0.9300 and set TP for 9340, our hedging SL (HSL) is set at 0.9270 (set by the trade_protector). Market turns immediatley against us and reverse sell order (second order) initiated at 0.9270. The downtrend continues to 0.9100.

The biggest problem in hedging is to avoid trading ranges. So there must be a parameter like
hedgingratio[pips] - the distance of the market price and hedging order SL when the "breakeven" SL of the hedging order will be initiated.

Lets assume that this hedgingratio[pips] = 100

So the EA put SL at the breakeven of the second order (0.9270) only when current market price is 100 pips away at (0.9170) from the hedging order open price (0.9270). With this way we avoid trading ranges.

There need to be also a second parameter hedgingBreakevenTP[pips] - the SL/TP distance between hedging order SL and open price. Lets assume that hedgingBreakevenTP[pips]= 10. The SL of the hedging order is set to 0.9260 instead of the breakeven at 0.9270 to get 10 pip profit if the market turns. 

The biggest problem with hedging is that the market may never turn back. This is only the basic Senario. Sell logic is reversed and it is similar to the sell senario. Plese implement this into the ea.

UPDATED: The next thing to think -  what to do when the market turns up again and the hedging order SL is executed at 0.9270 and the market turns back down such a way that the first order at 0.9300 is still at loss. There are two ways to handle this situation 1)close first order at the loss 2)make new hedging sell order. For the senario 2 there need to be a parameter like secondLevelHedgingRatio[pips] (=25) - new HSL is set 25 pips away from ordinary HSL at 0.9270. The option to choose between second HSL or standard SL.

What to do when the both first order and second HSL order is initiated and the trade is going to the right way so that the TP at 0.9340 will be targeted. If the HSL is triggered at 0.9270 the the TP at 0.9340 need to be canceled. The situation is reverse now.

 
marcool:
sliffy:

how can i change the parameters of the running trade?

I am not sure if I understand your question. If you attach this EA to the chart with the same currency pair as the running trade (open position), EA will - at each bar arrival - check prices and compare them to the EA parameters, and if needed, it will adjust S/L of the open position.
So if you have opened position, and then you will attach "TradeProtector" to the chart, it will start processing your position (as long as it has the same currency symbol, as the chart to which EA is attached).

Does it answer your question?

Btw. - After using it for a while I decided to change it a bit: It will apply initial S/L and don't use Trailing Stop until position will reach certain profit. Then it will start to use proportional S/L:


S/L = OpenPrice +/- (CurrentPrice - OpenPrice) * dPropSLRatio

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

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.

 
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).

 

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?

Reason: