Forex Factory
  • Login

  • Username: Password:
  • 12:52pm

  • Search
  • Home

  • Forums

  • Trades

  • Calendar

  • News

  • Market

  • Brokers

Options

Search
Search
Search

Subscribe to Thread

Bookmark Thread

First Page First Unread Last Page Last Post

Printable Version

  • Platform Tech
  • /
  • Reply to Thread
  • 8

EA - That uses MA for SL

  • Last Post
  • First Unread
  •  
  • Page 1 2 3
  •  
  • Post# 1
  • Quote
  • First Post: Oct 31, 2009 12:32am
  • PiPologi$t
    Joined Oct 2009 | 15 Posts | Status: Member
Anyone know of an EA that uses an adjustable MA as a Stop Loss, or is willing to write one for me?
  • Post# 2
  • Quote
  • Nov 2, 2009 4:33pm | Edited at 4:37pm – more detail
  • CodeMeister ● Online
    Joined Sep 2009 | 1,391 Posts | Status: Making Code While Making Pips
I have written an EA for closing the order when the profits hit an EMA level. It would be easy to modify to do what you want. Its quite flexible as it allows for closing part of the order and also has a TP in pips of profit option. Let me know what kind of MA you are thinking of.
  • Post# 3
  • Quote
  • Nov 2, 2009 11:08pm | Edited Nov 3, 2009 4:49am
  • PiPologi$t
    Joined Oct 2009 | 15 Posts | Status: Member
I'm looking for one the has an adjustable MA. ie. able to change: Period, MA method (Simple, Exponential, and Smoothed), and Apply to: (low, High, Open, Close)
  • Post# 4
  • Quote
  • Nov 6, 2009 1:47am
  • CodeMeister ● Online
    Joined Sep 2009 | 1,391 Posts | Status: Making Code While Making Pips
I have made the mods you requested and the EA is ready.

The input settings are:

MAperiods - the number of periods to be used by the MA calculation.
MAmethod - the method to be used by the MA calculation ('S', 'W', 'E', 'M'). Allowed values for MA Method are E(Exponential), S(Simple), M(Smoothed) or W(Weighted).
MAapply - the price type to be used by the MA calculation ('O', 'C', 'H', 'L'). Allowed values for MA Apply are O(Open), C(Close), H(High) or L(Low).
Lotsize - Part of the order can be closed. 0 means close all lots.
Attached File
File Type: mq4 OrdMgrSL.mq4   6 KB | 417 downloads
  • Post# 5
  • Quote
  • Nov 9, 2009 4:09am | Edited at 4:26am
  • PiPologi$t
    Joined Oct 2009 | 15 Posts | Status: Member
CodeMeister,

Thank you for the mod, but I can't get it to work.

It will not close the order.

For the Lotsize: I have used 0 and the actual lot size.

Can you advise

Also, can you add an alert to sound when order closes

Thanks again
  • Post# 6
  • Quote
  • Nov 9, 2009 11:17pm | Edited at 11:24pm – spelling
  • CodeMeister ● Online
    Joined Sep 2009 | 1,391 Posts | Status: Making Code While Making Pips
I can say with certainty that the problem was not related to the lot size. Setting it to 0 will close it without fail.

So now I am left to guess what the problem might be. I looked at my code again. There was a problem with it not resetting properly. By this I mean that it would have closed the open order(s) at startup but any subsequent orders would not have closed unless you changed one of the settings. This problem was easily fixed.

But you didn't describe your problem as happening in those conditions, so I kept on guessing what might the problem be. I think that there might have been a different expectation between us. I wrote the EA as a simple minded stop loss. But while testing it today, I noticed a scenario where it would have been advantageous to have more functionality such as a trailing stop capability. As can be seen in the attached picture, order #1 (short) closed successfully when it hit the MA line. Order #2 (long) never closed, because it was still in profit when it hit the MA line.

I think I will add the trailing stop logic. I'm not going to make any promises as to when I will have this done because the testing needs to be thorough.
Attached Image
  • Post# 7
  • Quote
  • Nov 10, 2009 4:17am
  • PiPologi$t
    Joined Oct 2009 | 15 Posts | Status: Member
CodeMeister,

I might have been unclear when I said Stop Loss. I want the order to close when It hits the MA when in profit or loss.

IF this EA should do that then we're on the same page.

Could I be having trouble because I use a 5 digit broker?
  • Post# 8
  • Quote
  • Nov 10, 2009 8:17am
  • CodeMeister ● Online
    Joined Sep 2009 | 1,391 Posts | Status: Making Code While Making Pips
Quoting PiPologi$t
CodeMeister,

I might have been unclear when I said Stop Loss. I want the order to close when It hits the MA when in profit or loss.

IF this EA should do that then we're on the same page.

Could I be having trouble because I use a 5 digit broker?
As I stated, the EA at present will only stop losses, but I will add the trailing stop logic.

The EA has no dependency on 4 digit logic.
  • Post# 9
  • Quote
  • Nov 10, 2009 9:09am
  • dbeach777
    Joined Oct 2006 | 381 Posts | Status: Infinite Possibilities
Hi, Here is a thread I started some time ago with a similar request, but I called it a Take Profit at ___ ema.

CodeMeister was so kind as to write the ea that is posted on post #7 at this thread http://www.forexfactory.com/showthread.php?t=200649

Hope this is what you're looking for



Quoting PiPologi$t
CodeMeister,

I might have been unclear when I said Stop Loss. I want the order to close when It hits the MA when in profit or loss.

IF this EA should do that then we're on the same page.

Could I be having trouble because I use a 5 digit broker?
  • Post# 10
  • Quote
  • Nov 17, 2009 10:15pm
  • CodeMeister ● Online
    Joined Sep 2009 | 1,391 Posts | Status: Making Code While Making Pips
Quoting CodeMeister
As I stated, the EA at present will only stop losses, but I will add the trailing stop logic.

The EA has no dependency on 4 digit logic.
The new logic was added and tested.
Attached File
File Type: mq4 OrdMgrSL.mq4   7 KB | 522 downloads
  • Post# 11
  • Quote
  • Nov 19, 2009 6:50pm
  • PiPologi$t
    Joined Oct 2009 | 15 Posts | Status: Member
CodeMeister,

Just got a chance to play with the new EA, and it works great, thank you very much.

K-
  • Post# 12
  • Quote
  • Nov 21, 2009 4:27am
  • dmitry_dos
    Joined Sep 2008 | 100 Posts | Status: Member
Quoting CodeMeister
The new logic was added and tested.
Hi,
I was wondering if you have a similar EA that opens positions, in the same direction, when the candle crosses a particular EMA?
Thank you for your time.
  • Post# 13
  • Quote
  • Nov 21, 2009 1:17pm
  • CodeMeister ● Online
    Joined Sep 2009 | 1,391 Posts | Status: Making Code While Making Pips
No I don't have an EA with that functionality and right now I'm in the middle of a number of other things. Once I get time, I see how easy it is.
  • Post# 14
  • Quote
  • Nov 21, 2009 4:19pm
  • dmitry_dos
    Joined Sep 2008 | 100 Posts | Status: Member
Quoting CodeMeister
No I don't have an EA with that functionality and right now I'm in the middle of a number of other things. Once I get time, I see how easy it is.
I really appreciate that, thank you.
  • Post# 15
  • Quote
  • Nov 23, 2009 2:29am
  • pilotui
    Joined Jul 2009 | 614 Posts | Status: Disabled Vet
Just what I was looking for

Thank you sir!
  • Post# 16
  • Quote
  • Nov 23, 2009 4:02am
  • dmitry_dos
    Joined Sep 2008 | 100 Posts | Status: Member
Quoting pilotui
Just what I was looking for

Thank you sir!
Yes, that close order EA when price hits MA is pretty neat
  • Post# 17
  • Quote
  • Nov 24, 2009 12:07am
  • jdwbryan
    Joined Oct 2009 | 65 Posts | Status: Only losers care about losing.
First of all, thanks for this great EA CodeMeister!

If/when it is possible and if/when you have the time, I'm wondering if you would you be able to add these two functions:

  1. Rather than set the stop ON the MA line, set stops X number of pips "behind" the MA line.
  2. Set a minimum number of pips from Open that the MA (not price) has to move before it will begin moving stops. (ie-MA has to move 60 pips from Open price before it starts trailing the stops to 30 pips "behind" the MA)
I know nothing of coding so I don't know if it's even possible, so if not, feel free to tell me "where to go"!

If it can be done, this would be the ultimate EA for me!

Thanks again!

Jack
  • Post# 18
  • Quote
  • Nov 26, 2009 1:37am | Edited at 6:58am
  • jdwbryan
    Joined Oct 2009 | 65 Posts | Status: Only losers care about losing.
I'm guessing adding the "shift" field to the MA could help accomplish the same goal? At least it seems close enough for me...

*EDIT* - Changing settings on the MA a bit creates the results I'm looking for too! Duh! Would still be nice to have a delay before it kicks in though...
  • Post# 19
  • Quote
  • Nov 28, 2009 9:14pm
  • luxinterior
    Joined Nov 2006 | 268 Posts | Status: MQL4 Coder
I posted a trailing stop MA with buffer some time ago. You can find it here...

http://www.automatedtradingsoftware....ers-with-an-ma

Good luck

Lux
  • Post# 20
  • Quote
  • Nov 29, 2009 2:10am
  • jdwbryan
    Joined Oct 2009 | 65 Posts | Status: Only losers care about losing.
Thanks Lux, I'll give that a whirl too!
Thread Tools Search this Thread
Show Printable Version Show Printable Version
Email This Thread Email This Thread
Search this Thread:

Advanced Search

  • Platform Tech
  • /
  • EA - That uses MA for SL
  • Reply to Thread
    • Page 1 2 3
0 traders viewing now
  • More

©2013 Forex Factory, Inc. / Terms of Use / Privacy Policy

Forex Factory® is a registered trademark.

Connect

  • Facebook
  • Twitter
  • RSS

Company

  • About FF
  • FF Blog
  • Careers at FF
  • Advertising
  • Contact FF

Products

  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer

Website

  • Homepage
  • Search
  • User Guide
  • Member List
  • Online Now
  • Report a Bug