• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 8:41pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 8:41pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Looking for Trailing Stop EA like default MT4 trailing stop 7 replies

Trailing stop after up some pips and question trailing step 3 replies

Trailing step and trailing stop optimization 0 replies

Buy Stop and Sell Stop orders with OCO and Trailing Stop 0 replies

To Trailing Stop or Not To Trailing Stop.... 36 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 19
Attachments: I'm seeking a trailing stop EA that surely must exist, any ideas?
Exit Attachments
Tags: I'm seeking a trailing stop EA that surely must exist, any ideas?
Cancel

I'm seeking a trailing stop EA that surely must exist, any ideas?

  • Last Post
  •  
  • Page 1 2345 6
  • Page 1 234 6
  •  
  • Post #1
  • Quote
  • First Post: May 11, 2010 7:10am May 11, 2010 7:10am
  •  BenScoobert
  • | Joined Jan 2008 | Status: Pipping along | 907 Posts
I'd like a trailing stop EA that trails by a percentage value of the amount you are in profit.

So for emample 3 variables.

Trail from = 10
Trail max = 50
Trail percent = 50

So in this example ts would be placed when you are 10pips (trail from) in profit, and it would place it 5pips (50% trailpercent) from the current price. Then as price moves in your favour it trail by 50%, so at 12 pips profit it trails by 6 14 by 7 and so on.....

When it reaches 100 pips profit it then trails by 50 pips (Trail max)

Surely someone else has done this before, I just cant find it anywhere.
  • Post #2
  • Quote
  • Edited 10:59am May 11, 2010 9:45am | Edited 10:59am
  •  kennyhubbard
  • Joined Sep 2008 | Status: Member | 354 Posts
Here you go,

In order to test it, I have it opening 2 orders(1 buy & 1 sell). You can then run it in visual backtest mode to see it in operation.

When ready to use, just delete the couple of lines at the beginning of the start() function that sends the orders.

You need to feed it the MagicNumber of the trades to manage. Leave the MagicNumber at 0 to manage all trades. I'll work on the instrument specific version later if required.

Lol.......This actually makes a halfway decent trading stratgey by itself. Check it out the attached backtest graph. I might just play around with this a bit more.

Anyway, have fun and report any bugs or alterations here.
Attached Image (click to enlarge)
Click to Enlarge

Name: StrategyTester - Ben Trail Stop.gif
Size: 6 KB
Attached File(s)
File Type: mq4 Ben_trail_stop.mq4   4 KB | 1,628 downloads
 
1
  • Post #3
  • Quote
  • May 11, 2010 10:11am May 11, 2010 10:11am
  •  BenScoobert
  • | Joined Jan 2008 | Status: Pipping along | 907 Posts
Lol thank you very much, I didn't expect someone to code it for me.

I just figured it seemed such an obvious thing that it must exist already.

Thanks again, I'll get to testing
 
 
  • Post #4
  • Quote
  • May 11, 2010 11:25am May 11, 2010 11:25am
  •  BenScoobert
  • | Joined Jan 2008 | Status: Pipping along | 907 Posts
OK I found a bug, if you set magic to 0 then I think it may be calculating the SL for all pairs based on the price of the chart it is attached to.

So if i put it on EurJpy it works fine, and set magic to 0 is fine, then I open a trade on another pair and I get a recurring error 130.
 
 
  • Post #5
  • Quote
  • May 11, 2010 11:32am May 11, 2010 11:32am
  •  kennyhubbard
  • Joined Sep 2008 | Status: Member | 354 Posts
Hi there,

I think you are right. Well spotted. Here is the (hopefully) fixed version.
Attached File(s)
File Type: mq4 Ben_trail_stop.mq4   5 KB | 1,128 downloads
 
1
  • Post #6
  • Quote
  • May 11, 2010 11:53am May 11, 2010 11:53am
  •  BenScoobert
  • | Joined Jan 2008 | Status: Pipping along | 907 Posts
Quoting kennyhubbard
Disliked
Hi there,

I think you are right. Well spotted. Here is the (hopefully) fixed version.
Ignored
now it seems to be not trying at all on other pairs, but fine on the one its attached to
 
 
  • Post #7
  • Quote
  • May 11, 2010 12:16pm May 11, 2010 12:16pm
  •  kennyhubbard
  • Joined Sep 2008 | Status: Member | 354 Posts
Ya, it needs to be on the chart of the instrument that it is controlling.....

But I have changed it now to use the correct Bid/Ask price, so , hopefully, this one will control all properly.

You will also notice an OrderModify error 1 from time to time. This is not serious. It simply means that the stoploss was already at what it was trying to set it to and, therefore, there was no change to the stoploss. I am trying to track down where it is modifying the order unneccesarily, but for now you can just ignore the error.
Attached File(s)
File Type: mq4 Ben_trail_stop.mq4   4 KB | 897 downloads
 
 
  • Post #8
  • Quote
  • May 11, 2010 12:21pm May 11, 2010 12:21pm
  •  BenScoobert
  • | Joined Jan 2008 | Status: Pipping along | 907 Posts
Quoting kennyhubbard
Disliked
Ya, it needs to be on the chart of the instrument that it is controlling.....

But I have changed it now to use the correct Bid/Ask price, so , hopefully, this one will control all properly.

You will also notice an OrderModify error 1 from time to time. This is not serious. It simply means that the stoploss was already at what it was trying to set it to and, therefore, there was no change to the stoploss. I am trying to track down where it is modifying the order unneccesarily, but for now you can just ignore the error.
Ignored
Damn you're fast, thanks a lot.

Its on the charts now, is the equity cut a bail out at that much percent drawdown?
 
 
  • Post #9
  • Quote
  • May 11, 2010 12:23pm May 11, 2010 12:23pm
  •  kennyhubbard
  • Joined Sep 2008 | Status: Member | 354 Posts
Yup, that was the idea. I was just playing around and have removed the bits that I was playing with.....left that in by mistake, so at the moment it does nothing.
 
 
  • Post #10
  • Quote
  • May 12, 2010 11:03pm May 12, 2010 11:03pm
  •  BenScoobert
  • | Joined Jan 2008 | Status: Pipping along | 907 Posts
that last version seems to work perfectly

to stop it opening trades i just changed the value to 0 from 2

thanks again, it lets me fire and forget much easier

if i could vouch for you i would, of course if you vouched for me i could vouch right back lol
 
 
  • Post #11
  • Quote
  • May 17, 2010 6:04am May 17, 2010 6:04am
  •  BenScoobert
  • | Joined Jan 2008 | Status: Pipping along | 907 Posts
Quoting BenScoobert
Disliked
that last version seems to work perfectly

to stop it opening trades i just changed the value to 0 from 2

thanks again, it lets me fire and forget much easier

if i could vouch for you i would, of course if you vouched for me i could vouch right back lol
Ignored
I take it back I found a bug LOL

When price is over 100 pips, it should trail by 50 pips fixed.

What happens is once the sl trails to 50 pips from the original entry price, it just stops moving rather than trailing by a fixed 50 pips.

am I making sense?
 
 
  • Post #12
  • Quote
  • May 17, 2010 6:16am May 17, 2010 6:16am
  •  kennyhubbard
  • Joined Sep 2008 | Status: Member | 354 Posts
Yup, you are making perfect sense.

I think I have spotted the bug. Gimme a couple of hours and I have it fixed.
 
 
  • Post #13
  • Quote
  • May 17, 2010 10:00am May 17, 2010 10:00am
  •  kennyhubbard
  • Joined Sep 2008 | Status: Member | 354 Posts
Ok, I think I nailed it. Please check it out and report any bugs as usual.
Attached File(s)
File Type: mq4 Ben_trail_stop_v2.mq4   4 KB | 984 downloads
 
 
  • Post #14
  • Quote
  • May 17, 2010 12:53pm May 17, 2010 12:53pm
  •  BenScoobert
  • | Joined Jan 2008 | Status: Pipping along | 907 Posts
We're getting close, I found another.

If you set your "Trail_From"value to 20 for example. The chart it is attached to will trail from 20, but on a 5 digit broker all the other charts trail from 2pips
 
 
  • Post #15
  • Quote
  • May 17, 2010 1:35pm May 17, 2010 1:35pm
  •  kennyhubbard
  • Joined Sep 2008 | Status: Member | 354 Posts
Hi Ben,

Well spotted, I think I solved the problem and here is the working version. Thanks for the detailed feedback, exactly what is needed for efficient debugging.

I normally correct for 5 digit brokers in the init() function but obviously(well now it is anyway) each order needs to be corrected individually.

We'll get there eventually!
Attached File(s)
File Type: mq4 Ben_trail_stop_v2_ECN.mq4   4 KB | 1,017 downloads
 
 
  • Post #16
  • Quote
  • May 17, 2010 2:37pm May 17, 2010 2:37pm
  •  BenScoobert
  • | Joined Jan 2008 | Status: Pipping along | 907 Posts
that version doesnt set anything, nothing experts log too
 
 
  • Post #17
  • Quote
  • May 17, 2010 3:01pm May 17, 2010 3:01pm
  •  kennyhubbard
  • Joined Sep 2008 | Status: Member | 354 Posts
Sorry, I think I had finger trouble there. Try this
Attached File(s)
File Type: mq4 Ben_trail_stop_v2_ECN.mq4   4 KB | 1,118 downloads
 
 
  • Post #18
  • Quote
  • May 17, 2010 4:40pm May 17, 2010 4:40pm
  •  dantom
  • | Commercial Member | Joined May 2010 | 22 Posts
This is a great thread. I've been searching for the same thing. An equity trailing stop EA. It could be put on a chart and control the whole account.

It would be especially nice if it could be set to operate in PERCENTAGES or DOLLARS. The other important thing is the ability to CANCEL ALL PENDING ORDERS when it closes all trades.

Thanks. I'm new here.

Dan
 
 
  • Post #19
  • Quote
  • May 18, 2010 3:20am May 18, 2010 3:20am
  •  BenScoobert
  • | Joined Jan 2008 | Status: Pipping along | 907 Posts
Quoting dantom
Disliked
This is a great thread. I've been searching for the same thing. An equity trailing stop EA. It could be put on a chart and control the whole account.

It would be especially nice if it could be set to operate in PERCENTAGES or DOLLARS. The other important thing is the ability to CANCEL ALL PENDING ORDERS when it closes all trades.

Thanks. I'm new here.

Dan
Ignored
theres a load of useful stuff on this thread
http://www.forexfactory.com/showthre...13#post2996813

but none of them did exactly what i required

thanks again kenny
 
 
  • Post #20
  • Quote
  • Edited 3:34pm May 18, 2010 3:18pm | Edited 3:34pm
  •  BenScoobert
  • | Joined Jan 2008 | Status: Pipping along | 907 Posts
Quoting kennyhubbard
Disliked
Sorry, I think I had finger trouble there. Try this
Ignored
Thanks Kenny
That appears to be running perfectly now on all pairs.

Now am I allowed to be a pain in the rear?
Could it have a boolean for it to either handle the one chart its attached to or all open trades?
 
 
  • Platform Tech
  • /
  • I'm seeking a trailing stop EA that surely must exist, any ideas?
  • Reply to Thread
    • Page 1 2345 6
    • Page 1 234 6
0 traders viewing now
  • More
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023