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

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

I Have 10 Buy Open Positions - I need to calculate 4 Buys open 2 replies

MT4 does not show my open positions 1 reply

Hotkey to liquidate all open positions on MT4? 2 replies

Open positions based on close above / below a horizontal line 0 replies

how to install MT4 and instant closing of all positions 7 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 3
Attachments: MT4 EA closing open positions based on MA
Exit Attachments
Tags: MT4 EA closing open positions based on MA
Cancel

MT4 EA closing open positions based on MA

  • Post #1
  • Quote
  • First Post: Edited Oct 11, 2012 12:57am Oct 9, 2012 10:19am | Edited Oct 11, 2012 12:57am
  •  Totoro
  • | Joined Sep 2012 | Status: Member | 34 Posts
This EA is closing open positions (long/short) if the price hits the other side of the moving average (below/above).
It basically works like a stop loss, without the need to trail it manually, while price and moving average fluctuate.

Input Options

 

  1. TimeFrame (1=M1,5=M5,15=M15,30=M30,60=H1,240=H4,1440=D1,10080=W1,43200=MN,0=variable)
  2. MAType (0=SMA,1=EMA,2=SMMA,3=LWMA)
  3. MAPeriod (Number of prices that are calculated into the MA)
  4. MAPrice (0=Close,1=Open,2=High,3=Low,4=Median,5=Typical,6=Weighted)
  5. Tolerance (How far the price is tolerated to break the MA, absolute value)
  6. BarCheck (true=checking previous bar close, false=checking latest price)
  7. Slippage (Maximum deviation from the market price when closing a trade)
  8. AlertMessage (true=shows alert message before closing a trade)

Feel free to share and/or modify this EA.

Note: I've coded it as simple, clean and clear as possible, so it can be the basis for more complex EA's.

Update to Version 1.1: Fixed some major issues and added the AlertMessage Option
Update to Version 1.2: Fixed some minor issues and added the TimeFrame Option
Update to Version 1.2b: Fixed an issue regarding multiple open positions

Attached Image (click to enlarge)
Click to Enlarge

Name: ss_ma_close.gif
Size: 44 KB
Attached File(s)
File Type: mq4 MA_Close.mq4   3 KB | 4,431 downloads
  • Post #2
  • Quote
  • Edited 11:20pm Oct 9, 2012 8:06pm | Edited 11:20pm
  •  Totoro
  • | Joined Sep 2012 | Status: Member | 34 Posts
Sidenote: The EA is checking and acting based on the current symbol/pair and it's current timeframe.
It should work on all timeframes. I'll do some testing soon, to see, if everything works fine.

Edit1: There seems to be a problem, it doesn't close the position on the 1 Minute Chart. I'm checking that.
Edit2: Found an error with conditional statements. Fixing that and checking further.
Edit3: Finally it works. I'll upload the fixed EA asap. Still need to test it on higher timeframes.
 
 
  • Post #3
  • Quote
  • Edited Oct 10, 2012 1:34am Oct 9, 2012 11:45pm | Edited Oct 10, 2012 1:34am
  •  Totoro
  • | Joined Sep 2012 | Status: Member | 34 Posts
I'll change the EA, so it's working on basis of a constant timeframe.
You can switch the timeframe while it's activated then, without changing EA's operation modus.

Edit: I've fixed some minor issues (some lines of code have gone missing in v1.1) and added the timeframe option.

Everthing should work fine now, but please let me know if something isn't working. I'll fix it asap then.
 
 
  • Post #4
  • Quote
  • Edited Oct 11, 2012 1:03am Oct 10, 2012 10:34pm | Edited Oct 11, 2012 1:03am
  •  Totoro
  • | Joined Sep 2012 | Status: Member | 34 Posts
After doing some detailed testing and fixing, it's running stable now. No more problems now in my opinion.

The TimeFrame Option "variable" means, the EA changes it's TimeFrame together with the trader changing the chart timeframe

Maybe some of you have got an idea about what to improve or add.
 
 
  • Post #5
  • Quote
  • Oct 23, 2012 7:38am Oct 23, 2012 7:38am
  •  streamyx
  • | Joined Sep 2009 | Status: Member | 7 Posts
hi
thanks for sharing the EA
is it possible to make another EA the other way round ie the EA will OPEN new order when price cross certain moving average?

thanks
 
 
  • Post #6
  • Quote
  • Apr 9, 2014 12:23pm Apr 9, 2014 12:23pm
  •  4xPIPAHOLIC
  • Joined Aug 2009 | Status: Member | 2,576 Posts
Hi Totoro,

Thanks for the EA ...I will test it out. An idea would be to have an option that only on the close of the bar on the other side of the MA the position to close, not just of the crossover.

4x
 
 
  • Post #7
  • Quote
  • Oct 16, 2014 11:41pm Oct 16, 2014 11:41pm
  •  vincentj
  • | Joined Dec 2009 | Status: Member | 22 Posts
Dear everyone,


Can anyone just create Alert POP-UP message, if PRICE hit Moving Average (EMA) 100 or 200 or 364.

Please create EA for above ALERT

Many thanks, awaiting your reply.
 
 
  • Post #8
  • Quote
  • Oct 22, 2014 9:29am Oct 22, 2014 9:29am
  •  addegsson
  • | Joined Oct 2014 | Status: Junior Member | 2 Posts
Very useful EA, thanks!
 
 
  • Post #9
  • Quote
  • Oct 23, 2014 3:12am Oct 23, 2014 3:12am
  •  cenetti
  • | Commercial Member | Joined May 2014 | 145 Posts
Quoting 4xPIPAHOLIC
Disliked
Hi Totoro, Thanks for the EA ...I will test it out. An idea would be to have an option that only on the close of the bar on the other side of the MA the position to close, not just of the crossover. 4x
Ignored

Exactly! This is what I need. Close position when the price closes above/below MA. Anyone ?
 
 
  • Post #10
  • Quote
  • Apr 22, 2015 6:25am Apr 22, 2015 6:25am
  •  birdland
  • Joined Aug 2010 | Status: . | 3,915 Posts
Quoting streamyx
Disliked
hi thanks for sharing the EA is it possible to make another EA the other way round ie the EA will OPEN new order when price cross certain moving average? thanks
Ignored
that would be great! i have not found any EA doing this...

does anybody know such an EA?
I know that you and I know nothing...and don't think!
 
 
  • Post #11
  • Quote
  • Apr 22, 2015 6:26am Apr 22, 2015 6:26am
  •  Price
  • | Joined Sep 2007 | Status: Member | 980 Posts
Quoting vincentj
Disliked
Dear everyone, Can anyone just create Alert POP-UP message, if PRICE hit Moving Average (EMA) 100 or 200 or 364. Please create EA for above ALERT Many thanks, awaiting your reply.
Ignored
Any crossover alert will do, just set the fast MA to 1 or 2. This way as soon as the bar closes on the other side of the slow MA, the alert will sound.

Of course, if the price is right on the line and it closes above and below - back and forth - it will ring constantly.

It would be nice to have a timer or a bar counter to make it wait a while before giving another signal.

Anyway - here is this Ma crossover alert....
Attached File(s)
File Type: mq4 MA Crossover Alert.mq4   10 KB | 1,142 downloads
 
 
  • Post #12
  • Quote
  • Apr 23, 2015 11:21am Apr 23, 2015 11:21am
  •  vincentj
  • | Joined Dec 2009 | Status: Member | 22 Posts
Dear Price

Thank you for taking time to program. I want to share this to everyone who read this message.

Each time and every time EMA 200 crosses upwards piercing EMA 300; prices move from 300 pips to 500 pips, retrace and then continue to 700 pips up to 900 pips. Same applies on a down trend .

For effective trading, try plotting the above on any currency pair ( 4 hrs or Daily chart ), lookout for these meeting each other.
Appreciate your comments.

I was also testing following method on a Daily Chart. If you can create Alert Message automatically with these conditions, One can earn min 20 pips a Day or more with a stop loss of previous Day Lowest Price or previous Day highest Price

using 2 candlestick to compare to make a decision (on a Daily Chart ) -

if the 2nd Candlestick closes below the opening of previous Day Chart, or closes below the lowest price of previous Day Chart >>> SELL alert message should be triggered, targetting 20 pips TP with a Stop Loss of of previous Day Lowest Price

if the 2nd Candlestick closes above the opening of previous Day Chart, or closes above the highest price of previous Day Chart >>> BUY alert message should be triggered, targetting 20 pips TP with a Stop Loss of of previous Day highest Price

Regarding how many pips to earn or how much pips to stop loss ; should be manually entered

Can the above be created as a EA? I want to try out on a demo account.
 
 
  • Post #13
  • Quote
  • May 27, 2016 9:24pm May 27, 2016 9:24pm
  •  linyarhu
  • | Joined Dec 2015 | Status: Junior Member | 3 Posts
Quoting Totoro
Disliked
This EA is closing open positions (long/short) if the price hits the other side of the moving average (below/above). It basically works like a stop loss, without the need to trail it manually, while price and moving average fluctuate. Input Options TimeFrame (1=M1,5=M5,15=M15,30=M30,60=H1,240=H4,1440=D1,10080=W1,43200=MN,0=variable) MAType (0=SMA,1=EMA,2=SMMA,3=LWMA) MAPeriod (Number of prices that are calculated into the MA) MAPrice (0=Close,1=Open,2=High,3=Low,4=Median,5=Typical,6=Weighted) Tolerance (How far the price is tolerated to break the...
Ignored
Thanks....
 
 
  • Post #14
  • Quote
  • Sep 18, 2016 4:59pm Sep 18, 2016 4:59pm
  •  Soyo24
  • | Joined Jan 2013 | Status: Member | 106 Posts
Quoting Totoro
Disliked
After doing some detailed testing and fixing, it's running stable now. No more problems now in my opinion. The TimeFrame Option "variable" means, the EA changes it's TimeFrame together with the trader changing the chart timeframe Maybe some of you have got an idea about what to improve or add.
Ignored
Where is the updated ea ?
Trend line Trader - The Trend Is Your Friend...
 
 
  • Post #15
  • Quote
  • Jan 13, 2017 1:52am Jan 13, 2017 1:52am
  •  nschwegl
  • | Joined Dec 2016 | Status: Member | 173 Posts
Quoting Totoro
Disliked
This EA is closing open positions (long/short) if the price hits the other side of the moving average (below/above). It basically works like a stop loss, without the need to trail it manually, while price and moving average fluctuate. Input Options TimeFrame (1=M1,5=M5,15=M15,30=M30,60=H1,240=H4,1440=D1,10080=W1,43200=MN,0=variable) MAType (0=SMA,1=EMA,2=SMMA,3=LWMA) MAPeriod (Number of prices that are calculated into the MA) MAPrice (0=Close,1=Open,2=High,3=Low,4=Median,5=Typical,6=Weighted) Tolerance (How far the price is tolerated to break the...
Ignored
I have checked this EA, it does not work
 
 
  • Post #16
  • Quote
  • Jan 13, 2017 9:53am Jan 13, 2017 9:53am
  •  Gosvic
  • | Joined Sep 2016 | Status: Member | 6 Posts
Strange Discovery; I need Help!

I discover today as I was trading using my hedging strategy that I could not place a pending order within my recovery gap again as the platform kept on saying invalid SL/TP. I sense there was a little volatility in the market then but even for like 1hrs after then, the problem persist.

Someone should kindly help; is it my broker platform setups OR that is the general attitude on MT4?
Ayobami Return Today: na
 
 
  • Post #17
  • Quote
  • Apr 23, 2018 12:22am Apr 23, 2018 12:22am
  •  kretkret
  • | Joined May 2016 | Status: Member | 13 Posts
this is a dodgy sales guy I guess
 
 
  • Post #18
  • Quote
  • Jun 7, 2018 5:01pm Jun 7, 2018 5:01pm
  •  MaXabreU
  • | Joined Jun 2018 | Status: Member | 4 Posts
I'm looking for a code or an EA, which would position and move the TP line (take profit) according to the movement of an EMA / SMA, thank you, this would help me a lot
 
 
  • Post #19
  • Quote
  • Jun 14, 2019 10:15am Jun 14, 2019 10:15am
  •  kate682
  • | Joined Mar 2012 | Status: Member | 8 Posts
Can anyone help me make this fabulous EA (MA_CLose) work on the 1min timeframe?
Thank you
Regards Gemma
 
 
  • Post #20
  • Quote
  • Last Post: Jun 20, 2019 10:00am Jun 20, 2019 10:00am
  •  perseous
  • | Joined Jun 2019 | Status: Junior Member | 1 Post
Hi everyone.
I'm just so new to forex and to this community.
This is just my 1st post!
As I found this wonderful EA, I registered this site and make a post here to ask for one favor that someone could please help me to convert this EA to MQL5 so I can use it on MT5.
It will be the best thing I ever got on all the online communities I ever joined.
God bless you and make you win win win.
 
 
  • Platform Tech
  • /
  • MT4 EA closing open positions based on MA
  • Reply to Thread
0 traders viewing now
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