collapse

Author Topic: Advanced Trailing Stop EA  (Read 111619 times)

Offline kennyhubbard

  • Full Member
  • ***
  • Posts: 160
    • compu-forex.com
Advanced Trailing Stop EA
« on: February 21, 2011, 11:26:13 AM »
Hi Guys,

NOTE : Latest version of this EA will always be attached to the first post.

Here is a trailing stop EA that I have made. I like to think of it as a pretty advanced EA but that is for you guys to decide 8)

Use of the Compuforex Trailing Stop

Typical User default settings are as follows :-

   
  • MagicNumber    = -1
  • Own_Symbol_Only = false
  • Trail_Start    = 10
  • Trail_Max      = 50
  • Trail_Percent  = 50
  • Trail_Min      = 5
  • Use_Decay      = true
  • Decay_Rate     = 1
  • Wait_Bars      = 4
  • Min_Mod        = 0.5
  • Audio_Alert    = true
The trailing stop has the following feature/functions :-

1.     Trail starts at number of pips defined by the user;
2.     EA will trail your order by a % of the profit as defined by the user e.g. 50% trail>>>>20 pips profit = 10 pips trail;
3.     Trail is limited to a maximum trail by the user e.g. 50% of profit until trail reached 50 pips, thereafter trail at constant 50 pips;
4.     The EA can reduce(or decay) the trail % at a user defined rate per bar;
5.     The user can choose to have the EA accelerate the trail decay;
6.     The user can have the EA wait before the trail decay commences;
7.     User can define the minimum pip change to the trail to reduce trade thread activity;
8.     User can choose whether to have an audio annunciation of trail commencement;
9.     A lot of attention has been given to order persistence. You can close the EA or crash the platform and the EA will pick up where
             it left off, having recorded all trade information to file. When reloading the EA, the file is verified against existing trades
       and old data discarded, new data added and only valid data is used.
10.    There is more screen output that keeps the user informed as to the EA's activity.
11.    The EA will trail multiple currencies simultaneously, automatically correcting for 4/5 digit brokers and 2/4 digit instruments;
12.    The user can choose to use on only a single currency if required.;
13.    The user can elect to trail only a specific MagicNumber if required   

A brief explanation of the settings :-

MagicNumber - Use this to set a specific MagicNumber to be trailed. This is when you are using this EA in conjunction with another EA.
                     Set this to -1 to trail all MagicNumbers(including manual trades).
Own_Symbol_Only - if set to true, will ONLY trail the currency pair of the chart on which the EA is loaded.
Trail_Start    - This is the number of pips in profit a trade must be for the EA to commence trailing a trade.
Trail_Max      - As profit increases, so will the trail....this setting sets the maximum number of pips in trail that the trail will be allowed.
Trail_Percent    - this is the % of profit to trail by. A big % equals a long trail. E.g 100% would be break even. 5% would be a very tight trail.
Trail_Min        - this is used in conjunction with the trail decay. The trail % is reduced over time(per bar) down to this value in this case 5%.
Use_Decay        - Tell the EA if you want to use the trail decay or not.
Decay_Rate       - this is the rate at which the trail decay will occur. In this example, the trail will reduce from 50% at a rate of 1% per bar.
                       There is more than 1 way to use this bcause an additional variable is the timeframe of your chart. You could run this on the M1 chart
                       which would result in a decay rate of 1% per minute. You could also run on the M5 which would result in a decay rate of 12% per hour,
                       etc, etc.....
Exp_Decay        - this is for an exponential decay. In this case, the initial decay rate is by default 1% and you cannot change that. On the first bar, the
                       trail is reduced by 1%, on the next bar it is reduced by 2% and then 4% on the next bar. My thinking is this would be good for catching breakouts.
Wait_Bars        - Oncethe trail is running at the Trail_Percent, this setting will tell the EA to wait before it starts to decay the trail. You may want to trail at 75%
                     for 30 minutes and then only start winding in the trail.
Min_Mod          - This setting tells the EA not to adjust the trail with every single 1/10 pip but will only make changes every 0.5 pips. This reduces thread activity which
                     may be a factor if you are trading several EA's(think of 'Trade Context is Busy').
Audio_Alert       - Enables or diables the trail commencement audio alarm(was more useful for me for testing).
Show_Info      - Enables/Disables on-screen output. Output is for user benefit only. If you do not need it, turn it off to conserve resources.
Text_Color     - You can now select the color of the text for the screen output.

You are welcome to ask questions but please don't ask me what settings work best. You need to experiment and determine those....and feedback will be appreciated.

Updates :

24 Feb 2011.....as is common practice on many forums, the latest update to this EA will always be found on the first post.
21 March 2011 - Update

Ability to add a hard stoploss has been added to this EA.

As always, it is never a simple case of just setting a stoploss. I have allowed for 3 ways to set a stoploss, namely :-

1. Straight-forward manually specified stoploss eg 20 60 pips;
2. A stoploss based on recent highs or lows;
3. A stoploss based on % loss per trade ie you have a $10 000 account and prepared to lose 1%($100) the EA will calculate the stoploss based on the tradesize that it finds.

Settings and defaults are as follows :-

Set_SL         = true;
Set_SL_Delay   = 15;
Manual_SL      = 0;
SL_Buffer      = 15;
SL_Hours       = 6;
SL_Max         = 60;
Use_RiskPercent_SL = false;
Risk           = 1;

Use the settings as follows :-

Set_SL...........This is the master ON/OFF switch for the SL feature. If set to false, no SL will be entered.
Set_SL_Delay.....Make the EA wait before it enteres a SL. The EA you may be combining this with may set its own stoploss and this delay will allow that EA to enter its own stoploss before taking over the trade. If a stoploss exists, this EA will NOT overide that SL.
Manual_SL........This is the stright-forward manual SL. Enter whatever SL you desire and be aware that this overides ALL other stoploss features. Make sure this is 0 if you want to use any of the other stoploss features.
SL_Buffer........Used for the recent high/low calculated SL. This EA will look back x number of hours and for a buy will enter a SL the the low less this buffer and VV for a sell.
SL_Hours.........The number of hours to look back for recent highs/lows.
SL_Max...........When looking back, there may have been some extreme moves in the market. This setting will allow the EA to look for recent high/lows plus buffer, but will also limit the final stoploss to a number that may be more acceptable. Also note that should you be trading a counter trend strategy, you may be presented with a situation where the CURRENT bar is the highest or lowest, this may leave you with an unnessesarily tight stoploss, in which case the SL will revert to this SL_Max value. This only applies when the current bar is the high or low as the case may be.
Use_RiskPercent_SL....This will make the EA calculate the SL based on risk % rather than high/lows. It looks at the trade size and will calculate the SL to be such that you will lose a % of your account if the SL is hit.
Risk..................This is the % of account loss that the EA will calculate the SL for should the Use_RiskPercent_SL be set to true.

Note that the Use_RiskPercent_SL overides the high/low bar SL, as well as the SL_Max setting. Also note that the Risk % SL is a simple calculate SL by trade size and nothing else. If your EA makes multiple trades, this EA will treat each trade as an individual trade and does not consider the impact of the trades as a basket.

I have done some basic testing, but you need to test this with your own broker and your own preferred settings, as I cannot check all permuations of options and brokers.

Please report any bugs here.

Update : 14 April 2011 : Version 1.2......EA will now overide the Target EA SL if SL_Overide is set to true
                                                         Fixed a bug with SL high/low determination
                                                         Removed superfluous comments in the experts tab
UPdate : 10 May 2011 : Version 1.7......Wait_Bars now changed to Wait_Mins. This still does the same thing, except now you can specify minutes    to wait instead of bars to wait. Allow you to run the EA on ony timeframe.

Update 16 May 2011 : Version 1.8 allows the lookback period for high/low stoploss calculation to be entered in minutes for trading shorter timeframes. SL_Hours is changed to SL_Minutes.
« Last Edit: June 27, 2011, 12:00:47 PM by kennyhubbard »
Wealth Creation Through Technology
www.compu-forex.com


Offline jamesfrance

  • Sr. Member
  • ****
  • Posts: 1238
Re: Advanced Trailing Stop EA
« Reply #1 on: February 21, 2011, 12:51:08 PM »
Wow,one of the best trailing stop EA's out there and it's free

Thanks Kenny

Offline rayong

  • Sr. Member
  • ****
  • Posts: 996
Re: Advanced Trailing Stop EA
« Reply #2 on: February 21, 2011, 12:58:28 PM »
Great job Kenny.  Thanks so much.

Offline bcfc1976

  • Full Member
  • ***
  • Posts: 441
  • Oh to be in Pafos, Cyprus. At the Royal Seacrest
Re: Advanced Trailing Stop EA
« Reply #3 on: February 21, 2011, 02:03:23 PM »
Kenny,

Fantstic work with this, many thanks.

Russ.
Walt Disney World - Animal Kingdom Park - December 1999.
Can any one remember the information guy?
"Rex Vananaboid"    Self Guided Tours
Make sure you take plenty of fresh water and a clean pair of socks!

Offline piphunter

  • Sr. Member
  • ****
  • Posts: 601
Re: Advanced Trailing Stop EA
« Reply #4 on: February 21, 2011, 02:40:27 PM »
Thanks a bunch Kenny!  :D One question for now ... I have 5 different EAs trading the EURUSD so how do I get Compuforex_trail to manage one or two of the EAs and leave the other three alone?  8)
FXCM - SWVPS - http://asirikuy.com/ GodsGiftATR, Atinalla F3.5

Offline kennyhubbard

  • Full Member
  • ***
  • Posts: 160
    • compu-forex.com
Re: Advanced Trailing Stop EA
« Reply #5 on: February 21, 2011, 03:06:49 PM »
Hi piphunter,

You would have to run multiple instances of the trailing EA. For example, you could run it on 2 EURUSD charts with Own_Symbol_Only set to true and then you would give each instance of the trailing EA the MagicNumber of the respective EA whose trades you want it to control.
Wealth Creation Through Technology
www.compu-forex.com


Offline ronny

  • Full Member
  • ***
  • Posts: 122
Re: Advanced Trailing Stop EA
« Reply #6 on: February 22, 2011, 01:47:38 AM »
Kenny this is very good. Usual trail managers get stopped out far too quickly.
 I would like to use this as a total trade manager.  Is is possible to add a hard SL and TP?
  Also a nice touch would be to make the SL and TP movable by mouse.
 Hope I'm not requesting too much.
« Last Edit: February 22, 2011, 01:53:06 AM by ronny »

Offline kennyhubbard

  • Full Member
  • ***
  • Posts: 160
    • compu-forex.com
Re: Advanced Trailing Stop EA
« Reply #7 on: February 22, 2011, 05:57:05 AM »
Hi ronny,

One can always only ask.......

I will incorporate a SL & TP in the next version as it seems to be a popular request.

I will ponder the visual order modification.........
Wealth Creation Through Technology
www.compu-forex.com


Offline ronny

  • Full Member
  • ***
  • Posts: 122
Re: Advanced Trailing Stop EA
« Reply #8 on: February 22, 2011, 09:55:17 PM »
Thanks Kenny....


        I had a good 60 pip trade last night with Compuforex trail showing stats as trade came into profit.
 
Possible small bug though. The Safe pips display (green) didn't change, even though I had 50 pips locked in.




Offline kennyhubbard

  • Full Member
  • ***
  • Posts: 160
    • compu-forex.com
Re: Advanced Trailing Stop EA
« Reply #9 on: February 22, 2011, 11:17:08 PM »
Hi ronny,

Thanks for the feedback......I think you are correct. I did notice the same on my account. The individual trades' locked pips is correct but the total seems to have a mind of its own.... :'(

I am sure, I find the error before the end of the week......watch for the next update.
Wealth Creation Through Technology
www.compu-forex.com


Offline mjfunk

  • Jr. Member
  • **
  • Posts: 88
Re: Advanced Trailing Stop EA
« Reply #10 on: February 22, 2011, 11:53:40 PM »
Kenny,

If I put up a trade and then turn the EA on, will it take control of the trade that is already there?
I think I can... I think I can...

Offline kennyhubbard

  • Full Member
  • ***
  • Posts: 160
    • compu-forex.com
Re: Advanced Trailing Stop EA
« Reply #11 on: February 23, 2011, 12:02:04 AM »
mjfunk,

Yes it will, providing the MagicNumbers match, or MagicNumber is set to -1(ie controls ALL trades irrespective of MagicNumber).

I have tried to pay a lot of attention to order persistence, so you can do what you like to the EA and it will always update itself with the current situation. It has to keep a record of the trades, so that it can execute the Trail Decay correctly when the platform/ EA is interrupted.

Wealth Creation Through Technology
www.compu-forex.com


Offline kennyhubbard

  • Full Member
  • ***
  • Posts: 160
    • compu-forex.com
Minor Update
« Reply #12 on: February 23, 2011, 12:13:23 AM »
Hi guys,

Herewith a minor update......

1. Better control of removal of the screen text on removing the EA from a chart(thanks to Robert at FF);
2. You can now have more precise control over the 'accelerated' rate of decay;
3. Safe Pips display bug corrected;
4. New setting to control whether to show screen output or not.

As mentioned, you can now excercise better control over the accelerated decay function. Previously it was based on x^2 exponential function ie the value of the trail reduction increase by the square of the number of bars, every bar. By adjusting the Decay_Rate, you can either speed this up or slow it down. So a Decay_Rate of 0.5 will now give you a reduction sequence of 0.5% first bar.........2% second bar........4.5%..........8% next bar.........12.5%.........18%.......etc.

The new setting Show_Info will determine whether to output the information to the screen. The screen output is only for the user's benefit and if you are running on a VPS, it is an unnecessary waste of resources to have so much screen output.

Please note that the default settings are not necessarily the best settings. I have adjusted the defaults to be more in line with what I use and M1 is the recommended timeframe, but my settings are, at best, an educated guess. Please provide feedback here on what settings have worked for you.........
« Last Edit: February 23, 2011, 12:18:27 AM by kennyhubbard »
Wealth Creation Through Technology
www.compu-forex.com


Offline CAJUN

  • Sr. Member
  • ****
  • Posts: 980
Re: Advanced Trailing Stop EA
« Reply #13 on: February 23, 2011, 10:12:21 AM »
Hey Kenny, thanks for the ea and great job. It would help if the status info color was changeable because when you are using a white chart you cannot see the status info.

CAJUN
"The return (OF) you money is more important than the return (ON) your money!"

Offline kennyhubbard

  • Full Member
  • ***
  • Posts: 160
    • compu-forex.com
Another minor update
« Reply #14 on: February 23, 2011, 10:11:15 PM »
Hi Guys,

CAJUN, I have included a setting now to change the color of the text.

Guys, please download this version rather than the previous, as there was a small bug in the calculation of the accelerated trail decay.

Regards

Kenny
Wealth Creation Through Technology
www.compu-forex.com


 

browse forum

* Recent Posts