- Learn how to design a trading system by RSI
- Urgent Help needed in using Time Function in mt4
- start a function when the market is closed?
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
- Dealing with Time (Part 1): The Basics - MQL5 Articles (2021.10.01)
- Dealing with Time (Part 2): The Functions - MQL5 Articles (2021.10.08)
- date/time (2017)
- 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.
- 2017.03.09
- www.mql5.com
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 }
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 ;}
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 ;}
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());
}
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 ;}
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use