I've been searching high and low, but I can't find this simple exit.
For testing purposes I need an EA that closes a trade after a certain number of days or bars.
By using this method you can use MyFXbook data to find the sweet spot of a certain EA. You can test if it goes into profit as expected, the average low point before going into profit and much more. Because it is a timed exit, it will not be bias of an exit strategy.
I'm surprised that I can't find any EA doing just this simple task.
Does anybody have an exit that can handle this, or know where to find it?
Regards,
N-days exit
- glabbeek
- Trader
- Posts: 104
- Joined: Tue Aug 21, 2012 8:09 am
- Location: In the middle of the Netherlands
N-days exit
Regards,
Willem-Bram
Willem-Bram
- fxdaytrader
- Trader
- Posts: 190
- Joined: Sun Jun 10, 2012 7:03 am
- Location: Poon-Town (germany, se-asia, se-europe) ...
Re: N-days exit
Not testet, but I think this should work, e.g.:
int days=5;
if (iBarShift(Symbol(),PERIOD_D1,OrderOpenTime()) >= days) OrderClose(.....
int days=5;
if (iBarShift(Symbol(),PERIOD_D1,OrderOpenTime()) >= days) OrderClose(.....
- glabbeek
- Trader
- Posts: 104
- Joined: Tue Aug 21, 2012 8:09 am
- Location: In the middle of the Netherlands
-
dudest
- Trader
- Posts: 1847
- Joined: Tue May 08, 2012 2:37 pm
Re: N-days exit
Another way to do it:
Cheers!
Code: Select all
// Global variable
datetime TimeSinceLastTrade = 0;
..
..
// After sending order to take a trade
TimeSinceLastTrade = TimeCurrent();
..
..
// In your control/checking module
if( (TimeCurrent() - LastTradeTime) > (3600*36) ) //It's more than 36 hours (in seconds) since last trade was taken
{
// close trade (e.g by ticket number)
}