I am new to this system but not to programming. I am somewhat mystified by the behavior of the strategy tester with regard to the simple code snippet – which is simply trying to test for a new day beginning. The code is:
datetime Yesterday;
int LastDay = 0;
bool started = false;
//+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+
int init()
{
//----
Yesterday = 0;
Alert("Init!");
//----
return(0);
}
int deinit()
{
//----
//----
return(0);
}
int start()
{
//----
datetime Today;
Today = 0;
Today = TimeCurrent();
Alert( TimeToStr(Today),":",TimeSeconds(Today), " ",TimeToStr(Yesterday),":",TimeSeconds(Yesterday)); Alert (TimeDay(Today)," ",LastDay);
if (TimeDay(Today) != LastDay)
{
Alert("New Day");
}
Yesterday = Today;
LastDay = TimeDay(Today);
//----
return(0);
}
//+------------------------------------------------------------------+
When I run this attached to a chart the code recognizes a new day when it occurs and prints it out as an alert. However, when I run in the strategy tester LastDay is never zero and the "New Day" alert never occurs. Am I missing something really obvious here? I have attached the file
Files:
dayturner.mq4
2 kb
- First EA : How to confirm tick is coming in
- Alert/print seems to not be executed, in start function
- Questions from Beginners MQL5 MT5 MetaTrader 5
Where's an air-rifle when you need one?
CB
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register