EA_based Trailing Stop - page 3

 

from Mexico

Kathy and/or Admin.

I am looking for the same, but so far have not found anything, unless the Igorad EA mentioned on page 1 is the solution, but the still missing the sound and the box.

MA Period

MA shift

Sound Alert

Box Alert

close order if candle close over/under MA

Your help very much appreciated.

 

Any instructions for this EMA T/S?

igorad:
Hi, I've developed EMATrailing Stop EA.

This seems to work fine, but does anyone have any tips or detailed instructions for inputs: EMATimeFrame, Price, EMAPeriod, EMAShift, InitialStop... The EMA Shift and Period is obvious, but can anyone provide some additional information on how to properly populate the other fields and use/customize it efficiently?

Thanks!

 

I'd suppose that the EMATimeFrame means the timeframe you want the EMA'll be calculated from (or the chart the EMA's virtually attached to)

Then - Price means the EMA's applied to price constants: Close - 0, Open - 1, High -2, Low -3, and so on

InitialStop - the Stop placed when the trade gets open

 

And I have to add - this EMA will trail only trend following trades, because when on reversals the price one's trade is open is always behind any EMAs (and this EA will change the stoploss to the current price)

 

Thanks a lot.

I am already using it with channel trading system for M5 timeframe here https://www.mql5.com/en/forum/173261/page17 and it works fine.

It is my settings for M5 timeframe:

You can use EMAPeriod as 15 or 20 for example.

This EA should be attached to 1 chart only and it will trail all opened trades for the account for all the pairs/charts (in case you are using my settings).

CloseWhenProfit is in dollars. It is closing all the trades when profit in dollars.

EA is moving stop loss strictly according to Moving Averages indicator's line. To see this line - you can attach standard Moving Averages indicator to the chart. In case you are using my settings if this EA - thr settings of the indicator may be the following:

Please note: this EA is working on closed bar.

It means the stop loss will be moved based on value of MA indicator on the previous/closed bar.

You do not need to attach any indicator especially. You need it just for visuality because it is always interesting to see this stop loss line.

Files:
 

EA That Modifies SL and TP on Other EAs?

Does anyone know of an EA that can change the stop loss and take profit set by other EAs?

I'm aware of Multi Purpose Trade Manager and Swiss Army Knife, but these allow you to jump stops and set trailing stops, but not modify existing ones.

I find that some EAs look good, but they use 'floating' stops and sometimes lose control, giving away more than necessary. Also, they sometimes miss taking profit early because they're waiting for something better - lower set take profits could allow trades to close earlier.

All the EA would need to be able to do is modify the stop loss and take profit of other EAs. Other features like jumping stops and trailing stops would be nice bonuses, but aren't essential.

 

I moved your post on this thread.

Sometimes I am using this EA (see post by Mladen on this thread). This EA can place stop loss and can modify stop loss for already existing orders.

 

Ok, thanks very much newdigital, i'll give it a try and let you know how i go...

 

mladen and newdigital:

i think this is fine, general trailing routine. Now replacing EMA with another indicator, and integrating it with some other stuff in an EA.

Got puzzled by the following lines of code:

if (CloseWhenProfit>0)

{

if ((TimeCurrent()-startTime)>15) totalProfit = colectProfit();

Can you please explain why you hardcode the value 15?

Also, newdigital says that this routine "is working on closed bar. It means the stop loss will be moved based on value of MA indicator on the previous/closed bar."

I see nothing in the code that makes this work only on closed bars, except that the MA is shifted 2 bars back. If i set EMAShift = 0 , i suppose it will operate on each tic?

 

...

Actually, it is simple :

That is a timer that measures execution time before that step is reached (the timer is started in line 82 : datetime startTime = TimeCurrent();)

____________________________

EA does the job in two steps :

  1. The EA is first modifying trailing stops according to settings (it is it's primary task) and when going through the list of trades it calculates the overall profit "on the fly"
  2. If it is required, EA closes all opened orders when certain profit is reached (so if specified with CloseWhenProfit). But, if the time that the first step was executed is longer than 15 seconds (I simply took that as an arbitrary value) then the currently overall reached profit is recalculated again (the colectProfit() function)

It is done to save execution time (for cases when a lot of trades are trailed simultaneously) but also, when a lot of them need to modify their stop losses sometimes order execution when changing stop loss can take some time, and that execution time would almost sure mean false overall profit figures. If stop losses are not changed, than it takes almost the same time as the colectProfit() function (so a call to colectProfit() would be unnecessary in that case).

You can "deactivate" that "safety" by simply removing that condition, but, at the time I wrote it it seemed as a logical step to save EA execution time and to ensure EA execution with reasonable error margin. There is no 100% error proof method (it always can occur that in the meantime data is changed) so this is just one way to make it work as close to ideal as it can

____________________________

As of closed bars : setting for the bar that is looked for EMA value that is going to be used for trailing stop is that EMAShift parameter (as you can see, I kept original parameter names from version 1), and as you see the default value is not even the first closed bar but the second one. That is not MA shifted, but the bar of EMA that is used (there is no shift in EMA calculation, moving average shift is set to 0(line 299), that shift is the last "shift" parameter used in EMA calculation (iMA(....)) I decided to leave that option so that the user can decide what EMA bar values is he going to use as trailing stops. So yes, if you decide to set it to 0, it will, do it on every tick (if the conditions are fulfilled)

____________________________

Hope this clarifies what and why is done

regards

mladen

kiasom:
mladen and newdigital:

i think this is fine, general trailing routine. Now replacing EMA with another indicator, and integrating it with some other stuff in an EA.

Got puzzled by the following lines of code:

if (CloseWhenProfit>0)

{

if ((TimeCurrent()-startTime)>15) totalProfit = colectProfit();

Can you please explain why you hardcode the value 15?

Also, newdigital says that this routine "is working on closed bar. It means the stop loss will be moved based on value of MA indicator on the previous/closed bar."

I see nothing in the code that makes this work only on closed bars, except that the MA is shifted 2 bars back. If i set EMAShift = 0 , i suppose it will operate on each tic?