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)
{
Close all trades;
Start trade = false; (Stop further trade)
Get today day of the week; ( assume it's Tuesday)
}
Example 2.
If( OrderTotal < 0 & week != Newweek) Continue:
If(OrderTotal < 0) & week ==Newweek)
If(dayofweek = Tuesday) start trade = true ( resume trading


 
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;
if(TimeCurrent() < allowedToTrade) return;
⋮
if(condition) allowedToTrade=next_week();
⋮
//////////////////////////////////////////////////////////////////////////////
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.

See also

  1. Dealing with Time (Part 1): The Basics - MQL5 Articles (2021.10.01)
  2. Dealing with Time (Part 2): The Functions - MQL5 Articles (2021.10.08)
  3. date/time (2017)
  4. Find bar of the same time one day ago - MQL4 programming forum (2017)

Don't double post! You already had this thread open.
          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:


Close all trades;

startTrade = false;

datetime waitUntil = TimeCurrent() + 604800;


if(TimeCurrent()>=waitUntil){ startTrade = true ;}

 

Don't double post! You already had another thread open.

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


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
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       timeofTrade        = TimeCurrent();
   MqlDateTime    timeofTradeStruc;
   TimeToStruct(timeofTrade, timeofTradeStruc);

//Plan Next Trade
  datetime       timeofNextTrade     =  timeofTrade + (3600 * 24 * 6); //6 days in the future 
   MqlDateTime    timeofNextTradeStruc;
   TimeToStruct(timeofNextTrade, timeofNextTradeStruc);

//Check next trade time
   if((timeofNextTrade <= TimeCurrent())  && (timeofTradeStruc.day_of_week == timeofNextTradeStruc.day_of_week))   //Will execute 7 days later
     {
      //resume trading
      //reset timeofNextTrade & timeofNextTradeStruc
     }
 
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 

 
trustfultrading #:

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:


Close all trades;

startTrade = false;

datetime waitUntil = TimeCurrent() + 604800;


if(TimeCurrent()>=waitUntil){ startTrade = true ;}

 
trustfultrading #:

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.

Pause trade functions


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:


Close all trades;

startTrade = false;

datetime waitUntil = TimeCurrent() + 604800;

if(TimeCurrent()>=waitUntil){ startTrade = true ;}


if(NewBarFlag)

      {     if(CheckTradeTime(TradeStartTime,TradeEndTime)) //ea start by 13gmt, stop 23gmt

            {

            MARTINGALE_BUY();

            MARTINGALE_SELL();

            if(iTotalS >=1)GoMartingalesell();

            if(iTotalB >=1)GoMartingalebuy();

            }

        }

   }

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

/* 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))

          {

          CloseAllBuy();

          CloseAllSell();

          }

   return (AccountBalance());

  }






Something like this:


Close all trades;

startTrade = false;

datetime waitUntil = TimeCurrent() + 604800;


if(TimeCurrent()>=waitUntil){ startTrade = true ;}

 
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:

Pause trade functions


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:


Close all trades;

startTrade = false;

datetime waitUntil = TimeCurrent() + 604800;

if(TimeCurrent()>=waitUntil){ startTrade = true ;}


if(NewBarFlag)

      {     if(CheckTradeTime(TradeStartTime,TradeEndTime)) //ea start by 13gmt, stop 23gmt

            {

            MARTINGALE_BUY();

            MARTINGALE_SELL();

            if(iTotalS >=1)GoMartingalesell();

            if(iTotalB >=1)GoMartingalebuy();

            }

        }

   }

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

/* 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))

          {

          CloseAllBuy();

          CloseAllSell();

          }

   return (AccountBalance());

  }






 
trustfultrading #:

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(starttrade == true)

{ If(fma1> ma2) buy&sell; }

If (acctEgty < acctBal- 2000)

{  Closeall; 

starttrade = false;

datetime waituntil = TimeCurrent()+ 604800; 

}

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

This does not work...please help me to fix this. I have attach d ea .


 


Something like this:


Close all trades;

startTrade = false;

datetime waitUntil = TimeCurrent() + 604800;


if(TimeCurrent()>=waitUntil){ startTrade = true ;}

Files: