# Stop trading for the whole week

I want my EA to stop trading for d week when my condition to close all trade is met. And resume trading the upper week at the same day of last week when it closes all trade and stopped
Example1
```If (xy < ab)
{
Get today day of the week; ( assume it's Tuesday)
}
Example 2.
If( OrderTotal < 0 & week != Newweek) Continue:
If(OrderTotal < 0) & week ==Newweek)

Teddy Odafe if my condition to close all trade is met, and to resume trade the next week at same day.

Not tested, not compiled, just typed.

```static datetime allowedToTrade=0;
⋮
⋮
//////////////////////////////////////////////////////////////////////////////
datetime next_week(){
#define HR2400 86400
datetime now   = TimeCurrent();
datetime bod   = now - now % HR2400; // Beginning of the day (00:00)
return bod + 7*HR2400;
}
```

Not tested, not compiled, just typed.

General rules and best pratices of the Forum. - General - MQL5 programming forum (2017)

Hi,

I would calculate that in seconds. I believe there are 604,800 seconds in a week. Just add that to your close time and wait until the current time TimeCurrent() is greater than that result.

Something like this:

datetime waitUntil = TimeCurrent() + 604800;

Moderator's note: The other topic has been deleleted.

General rules and best pratices of the Forum. - Forex Forum on automated trading systems and testing trading strategies
• 2017.03.09
• www.mql5.com
Forum on trading, automated trading systems and testing trading strategies. You have a question about your ea written in mql 5  ===> post in the  expert advisors and automated trading section. How do you like the new design of the site

Here is some code which may help - adjust it to make it what you want

```//When Trade executes set time

datetime       timeofNextTrade     =  timeofTrade + (3600 * 24 * 6); //6 days in the future

{
}
```

R4tna C #:

Here is some code which may help - adjust it to make it what you want

I am very happy to see you helping me. Thanks in a billion.
I will run this in d morning.

Teddy Odafe #:
I am very happy to see you helping me. Thanks in a billion.
I will run this in d morning.

Sure - good luck

Hi,

I would calculate that in seconds. I believe there are 604,800 seconds in a week. Just add that to your close time and wait until the current time TimeCurrent() is greater than that result.

Something like this:

datetime waitUntil = TimeCurrent() + 604800;

Hi,

I would calculate that in seconds. I believe there are 604,800 seconds in a week. Just add that to your close time and wait until the current time TimeCurrent() is greater than that result.

I would calculate that in seconds. I believe there are 604,800 seconds in a week. Just add that to your close time and wait until the current time TimeCurrent() is greater than that result.

Something like this:

datetime waitUntil = TimeCurrent() + 604800;

if(NewBarFlag)

{

MARTINGALE_SELL();

if(iTotalS >=1)GoMartingalesell();

}

}

}

//---------------------------------------

/* I want d ea to pause further trading for a week, when the below conditions  are met, it should resumed after d pause days. Example: d conditions were met on Tuesday and all trade were close, d ea should halt further trading for this current week, until d upper week Tuesday were it will resume trading.  */

double MaxLossAmount_Monday()

{

if(MaxLossAmt_closs == true)

if((OrdersTotal()>1) && (AccountEquity() <= (AccountBalance() - MaxLoss_Amount))

{

CloseAllSell();

}

return (AccountBalance());

}

Something like this:

datetime waitUntil = TimeCurrent() + 604800;

Please can help arrange it...I have tried with several suggestions and Guessing, yet to find d answer.
Please I attach piece of d code:

I would calculate that in seconds. I believe there are 604,800 seconds in a week. Just add that to your close time and wait until the current time TimeCurrent() is greater than that result.

Something like this:

datetime waitUntil = TimeCurrent() + 604800;

if(NewBarFlag)

{

MARTINGALE_SELL();

if(iTotalS >=1)GoMartingalesell();

}

}

}

//---------------------------------------

/* I want d ea to pause further trading for a week, when the below conditions  are met, it should resumed after d pause days. Example: d conditions were met on Tuesday and all trade were close, d ea should halt further trading for this current week, until d upper week Tuesday were it will resume trading.  */

double MaxLossAmount_Monday()

{

if(MaxLossAmt_closs == true)

if((OrdersTotal()>1) && (AccountEquity() <= (AccountBalance() - MaxLoss_Amount))

{

CloseAllSell();

}

return (AccountBalance());

}

Hi,

I would calculate that in seconds. I believe there are 604,800 seconds in a week. Just add that to your close time and wait until the current time TimeCurrent() is greater than that result.

Thank you. The code is simple but it has not worked. I have attached d ea to this reply.

For a quick. Example:

If (acctEgty < acctBal- 2000)

{  Closeall;

datetime waituntil = TimeCurrent()+ 604800;

}

If( TimeCurrent () > waituntil)starttrade = true;

Something like this: