• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 2:16am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 2:16am
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

How to close trade in Metatrader after amount of time or bars 30 replies

Default How to close trade in Metatrader after amount of time or amount of bars 5 replies

TP dollars amount and SL dollars amount columns (MT4) 0 replies

MT4 How to set TP to close a certain amount instead of entire amount? 3 replies

How to find out the lowest close from a certain amount of time back? 0 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 2
Attachments: Is there an EA to close trades after a certain amount of time?
Exit Attachments
Tags: Is there an EA to close trades after a certain amount of time?
Cancel

Is there an EA to close trades after a certain amount of time?

  • Last Post
  •  
  • Page 1 2
  • Page 1 2
  •  
  • Post #1
  • Quote
  • First Post: Dec 25, 2013 7:28pm Dec 25, 2013 7:28pm
  •  thesiusmaxim
  • | Joined Aug 2013 | Status: Member | 15 Posts
Hello,

Is there an EA to close trades after a certain amount of time in the RED or GREEN?

For example:

Close a trade in the RED after 3 hours.
Close a trade in the GREEN after 4 hours.
  • Post #2
  • Quote
  • Dec 26, 2013 7:18am Dec 26, 2013 7:18am
  •  fxdaytrader_
  • Joined Jan 2011 | Status: UberTroll | 1,847 Posts
you could modify the function posted at http://www.forexfactory.com/showthread.php?p=7148078 to fit your needs ...
I could do it also, but not today. If you cannot find what you're looking for I could do it within the next days maybe ...
PM me with coding requests and I'll probably put you on my ignore list
 
 
  • Post #3
  • Quote
  • Dec 28, 2013 6:00am Dec 28, 2013 6:00am
  •  thesiusmaxim
  • | Joined Aug 2013 | Status: Member | 15 Posts
Thanks for your reply. I have no idea how to edit EA's, I can't even read the code.
 
 
  • Post #4
  • Quote
  • Dec 29, 2013 9:20am Dec 29, 2013 9:20am
  •  fxdaytrader_
  • Joined Jan 2011 | Status: UberTroll | 1,847 Posts
Quoting thesiusmaxim
Disliked
Hello, Is there an EA to close trades after a certain amount of time in the RED or GREEN? For example: Close a trade in the RED after 3 hours. Close a trade in the GREEN after 4 hours.
Ignored
What do you mean by red and green? whether the order is in profit or not?

Attached is a simple ea which closes orders after a certain time.
It is an expert advisor, so it belongs to mt4/experts/-folder, settings:

FilterByMagicNumber -> true:filter by magic number, false:ignore magic numbers
CurrentPairOnly -> true:current chart pair only, false:all pairs
MagicNumber -> the magicnumber (0=manual trades)


UseTimeBasedStopLoss = TRUE (if it is false the ea does nothing, ...)
TimeBasedSLmode -> 1:days, 2:hours, 3:minuts, 4:bars
TimeBasedSLperiod -> the period (in days, hours, minutes or bars, depending what you have selected for TimeBasedSLmode )

I assume you would like to use the ea for all ordertypes (buy, sell, pendingorders)? If not I could change that (that it for example only deletes pending orders) ...
Attached File(s)
File Type: mq4 SimpleTimeBasedSL OrderManager EA.mq4   5 KB | 3,539 downloads
PM me with coding requests and I'll probably put you on my ignore list
 
1
  • Post #5
  • Quote
  • Dec 29, 2013 7:09pm Dec 29, 2013 7:09pm
  •  thesiusmaxim
  • | Joined Aug 2013 | Status: Member | 15 Posts
Hi,

Thanks very much. Do you have a donation button anywhere?

Could you split the time needed to close, for a trade in profit and a trade in a loss? Right now it just closes trades regardless if it's in profit or loss. For example, close profit trades after 3 hours, close loss trades after 4 hours.

Also, is there a way to make an option to enter a random trade every 'x' minute, or hour, or day, etc? Just for backtesting purposes to see if the EA works as it should.
 
 
  • Post #6
  • Quote
  • Dec 29, 2013 8:31pm Dec 29, 2013 8:31pm
  •  fxdaytrader_
  • Joined Jan 2011 | Status: UberTroll | 1,847 Posts
yes, I will add both, later (because I cannot sleep) or tomorrow.
PM me with coding requests and I'll probably put you on my ignore list
 
 
  • Post #7
  • Quote
  • Dec 29, 2013 9:21pm Dec 29, 2013 9:21pm
  •  fxdaytrader_
  • Joined Jan 2011 | Status: UberTroll | 1,847 Posts
pls. try, extended the userinfo (comment on screen) also ...

edit: if (orderprofit + orderswap + ordercommission) is > 0.0 of your AccountCurrency (e.g. USD) the trade is considered in profit,
a trade is considered in loss if if (orderprofit + orderswap + ordercommission) is smaller or equal (<=) 0.0
Attached File(s)
File Type: mq4 SimpleTimeBasedSL OrderManager EA v1.1.mq4   7 KB | 2,856 downloads
PM me with coding requests and I'll probably put you on my ignore list
 
 
  • Post #8
  • Quote
  • Dec 29, 2013 9:54pm Dec 29, 2013 9:54pm
  •  thesiusmaxim
  • | Joined Aug 2013 | Status: Member | 15 Posts
Hi,

Wow, it's almost done, thank you so much. After testing, the only problem left is this:

The countdown timer needs to be reset each time an individual trade goes into profit or loss. Can this be done?

For example, the timer is set to 5 hours for profit trades, and 4 hours for loss trades.
When a loss trade goes into profit, the countdown timer needs to reset back to 5 hours. And when a profit trade goes into loss, the countdown timer needs to reset back to 4 hours.

Is this possible?
 
 
  • Post #9
  • Quote
  • Dec 30, 2013 4:54am Dec 30, 2013 4:54am
  •  fxdaytrader_
  • Joined Jan 2011 | Status: UberTroll | 1,847 Posts
It is possible, but I cannot be bothered to noodle around with this at the moment.
Maybe someone else likes to implement this feature
PM me with coding requests and I'll probably put you on my ignore list
 
 
  • Post #10
  • Quote
  • Jan 3, 2014 8:00am Jan 3, 2014 8:00am
  •  21vs7
  • Joined Dec 2010 | Status: Foook Bollinger-dr.Kegel knows! | 9,724 Posts
Quoting fxdaytrader_
Disliked
It is possible, but I cannot be bothered to noodle around with this at the moment. Maybe someone else likes to implement this feature
Ignored

Aha, I see the problem.
I need for EA to look at open time of every open trade and count them for xx hours. If its not closed after x hours, EA closes it.
This one works like after 4 hours it closes all, even thou, one was just opened. Right?
Is there any simple solution for all this?
 
 
  • Post #11
  • Quote
  • Jan 3, 2014 8:22am Jan 3, 2014 8:22am
  •  fxdaytrader_
  • Joined Jan 2011 | Status: UberTroll | 1,847 Posts
yes, that is it, close after xyz hours, here: http://www.forexfactory.com/showthre...62#post7179362 and this post here http://www.forexfactory.com/showthre...06#post7178806

try on demo first
PM me with coding requests and I'll probably put you on my ignore list
 
 
  • Post #12
  • Quote
  • Jan 3, 2014 11:29am Jan 3, 2014 11:29am
  •  Fraois
  • | Joined Jul 2013 | Status: Member | 53 Posts
Quoting 21vs7
Disliked
{quote} Aha, I see the problem. I need for EA to look at open time of every open trade and count them for xx hours. If its not closed after x hours, EA closes it. This one works like after 4 hours it closes all, even thou, one was just opened. Right? Is there any simple solution for all this?
Ignored
I heard the simple solution is to close the MT4 terminal, it works better than virtual clicks that some commercial EAs may still be running. Closing the terminal guarantees no more trades
 
 
  • Post #13
  • Quote
  • Jan 3, 2014 11:34am Jan 3, 2014 11:34am
  •  21vs7
  • Joined Dec 2010 | Status: Foook Bollinger-dr.Kegel knows! | 9,724 Posts
Quoting fxdaytrader_
Disliked
yes, that is it, close after xyz hours, here: http://www.forexfactory.com/showthre...62#post7179362 and this post here http://www.forexfactory.com/showthre...06#post7178806 try on demo first
Ignored

many thanks
ill report back
 
 
  • Post #14
  • Quote
  • Jan 12, 2014 9:37pm Jan 12, 2014 9:37pm
  •  Ozzie Taz
  • Joined Mar 2009 | Status: Persistant | 227 Posts
Quick question about this line of code:

if (mode==4) {smode="bars"; TimeBasedSL = TimeBasedSLperiod * Period() * 60;}//bars


What does the * 60 do?

I assumed that if I set TimeBasedSLperiod = 4 then that would count 4 bars from the trades open time (as per your other code within the EA) and close out accordingly from there.


Cheers
Luck is where preparation meets opportunity.......
 
 
  • Post #15
  • Quote
  • Jul 22, 2014 7:45pm Jul 22, 2014 7:45pm
  •  nadmondo
  • | Joined Mar 2012 | Status: Junior Member | 1 Post
Quoting fxdaytrader_
Disliked
{quote} What do you mean by red and green? whether the order is in profit or not? Attached is a simple ea which closes orders after a certain time. It is an expert advisor, so it belongs to mt4/experts/-folder, settings: FilterByMagicNumber -> true:filter by magic number, false:ignore magic numbers CurrentPairOnly -> true:current chart pair only, false:all pairs MagicNumber -> the magicnumber (0=manual trades) UseTimeBasedStopLoss = TRUE (if it is false the ea does nothing, ...) TimeBasedSLmode -> 1:days, 2:hours, 3:minuts, 4:bars TimeBasedSLperiod...
Ignored
this expert is very good.....i tried it it works well.....but it delays for seconds..may be 2 seconds to 20.....but it works well
 
 
  • Post #16
  • Quote
  • Nov 23, 2014 6:21pm Nov 23, 2014 6:21pm
  •  Rparm
  • Joined Jul 2014 | Status: Member | 174 Posts
Quoting fxdaytrader_
Disliked
{quote} What do you mean by red and green? whether the order is in profit or not? Attached is a simple ea which closes orders after a certain time. It is an expert advisor, so it belongs to mt4/experts/-folder, settings: FilterByMagicNumber -> true:filter by magic number, false:ignore magic numbers CurrentPairOnly -> true:current chart pair only, false:all pairs MagicNumber -> the magicnumber (0=manual trades) UseTimeBasedStopLoss = TRUE (if it is false the ea does nothing, ...) TimeBasedSLmode -> 1:days, 2:hours, 3:minuts, 4:bars TimeBasedSLperiod...
Ignored
Hey Fxdaytrader, would you be able to make it close only open orders? Would be much appreciated!
A Positive Mind, and Positive Spirit lead to True Happiness
 
 
  • Post #17
  • Quote
  • Jan 19, 2015 3:03pm Jan 19, 2015 3:03pm
  •  busyguy
  • | Joined Jul 2014 | Status: Member | 5 Posts
Can this EA close a trade after 45 mins?
 
 
  • Post #18
  • Quote
  • Mar 3, 2015 7:22pm Mar 3, 2015 7:22pm
  •  ufss
  • | Joined Nov 2014 | Status: Junior Member | 2 Posts
Quoting fxdaytrader_
Disliked
pls. try, extended the userinfo (comment on screen) also ... edit: if (orderprofit + orderswap + ordercommission) is > 0.0 of your AccountCurrency (e.g. USD) the trade is considered in profit, a trade is considered in loss if if (orderprofit + orderswap + ordercommission) is smaller or equal (<=) 0.0 {file}
Ignored

Omg, sir, this is exactly the EA that I am looking for!
I am very appreciate that, you are very kindly to share that with us!
Good luck, and good pips!
 
 
  • Post #19
  • Quote
  • Edited 1:30pm Sep 3, 2015 9:11am | Edited 1:30pm
  •  NederPip
  • | Joined Apr 2010 | Status: Member | 54 Posts
Dear fxdaytrader,

Thank you very much for this EA SimpleTimeBasedSL OrderManager EA v1.1

I would like to close a losing trade exactly 120 minutes after the trades has been opened.

If I'm right, the EA now closes trades from 120 minutes on (if we set it to 120).

If 120 minutes after opening a trade is in loss, the EA closes the trade, which is fine.

But if for instance after 120 minutes a trade is in profit, but after 125 minutes it gets in loss, the EA closes the trade at minute 125. That's not how I would like it to use.

Would it be possible for you or anyone else to adjust the EA in a way that it closes the trade at 120 minutes after opening? So only at minute 120 (in this example) it closes the trade if it is in loss. From minute 121, the EA must not close trades anymore.

Also it would be great if the EA would not close pending orders.

Thank you very much!

Kind regards.
 
 
  • Post #20
  • Quote
  • Jul 3, 2016 1:26pm Jul 3, 2016 1:26pm
  •  carlos.arana
  • | Joined Jul 2016 | Status: Junior Member | 1 Post
Hi guys,

I'm sorry to bother you with this but I'm new to FF and I'm looking for an EA that closes the trade after xx time counting from the moment the trade was placed.

For example if I place a pending order at 14:00h and I set the closing time to 120 minutes then the order should be closed at 16:00h no matter if it opened at 14:05h or 15:55h. Additionally if the order never opens the trade should be cancelled at 16:00h anyway.

I did some testing to the SimpleTimeBasedSL OrderManager EA v1.1 and it only differs from my previous explanation that if the pending order is opened at some time then the timer is reseted and the trade will close xx time after it opens (and not after the pending order was placed).

Does anybody knows of an EA that can perform these features? I will be very thankful if you can provide any help on this!

Thanks in advance!
 
 
  • Platform Tech
  • /
  • Is there an EA to close trades after a certain amount of time?
  • Reply to Thread
    • Page 1 2
    • Page 1 2
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