N-days exit

Post Reply
User avatar
glabbeek
Trader
Posts: 104
Joined: Tue Aug 21, 2012 8:09 am
Location: In the middle of the Netherlands

N-days exit

Post by glabbeek »

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,
Regards,
Willem-Bram
User avatar
fxdaytrader
Trader
Posts: 190
Joined: Sun Jun 10, 2012 7:03 am
Location: Poon-Town (germany, se-asia, se-europe) ...

Re: N-days exit

Post by fxdaytrader »

Not testet, but I think this should work, e.g.:

int days=5;
if (iBarShift(Symbol(),PERIOD_D1,OrderOpenTime()) >= days) OrderClose(.....
User avatar
glabbeek
Trader
Posts: 104
Joined: Tue Aug 21, 2012 8:09 am
Location: In the middle of the Netherlands

Re: N-days exit

Post by glabbeek »

Thanks,

I'll give this a try.
Regards,
Willem-Bram
dudest
Trader
Posts: 1847
Joined: Tue May 08, 2012 2:37 pm

Re: N-days exit

Post by dudest »

Another way to do it:

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)
}
Cheers!
Post Reply

Return to “Automated trading systems”