I am running a VPS where the time shown on the charts is different from the time input to extern variables in my EA. I uploaded the EA to the MT4 client and access it through the web. The EA uses DateTime() to convert to seconds from 1/1/70. The techs at forex.com keep telling me that it is a problem with my EA. I suggested that maybe it is the difference between MT4 time at the platform where the client runs and time at the platform where the server runs. They insist that the client and the server both run on GMT, so it must be a problem with my EA. They keep telling me that they don't offer MQL4 coding support for my EA. I keep telling them that I do not want coding support for my EA, but just would like to know why the EA code on their MT4 platform interprets and displays a time difference from the time I entered. There is nothing in the code to even suggest anything more than direct conversion of the numbers entered for time to the seconds passed since 1/1/70. Nothing to suggest an offset. The program does not see it in terms of time zones but only raw numbers. I could not get this fact accross to the techs there. They keep saying it is the EA. Yikes.....There is something going on and I do not know what it is....
If you post the code of your EA maybe someone will be able to help you. For sure problem is with the EA.
Here is the code: only included the extern variables and where they are used to set the time parameters, and where they are used for a buy of the breakout of upper range. I don't know what else could be pertinant. I more is needed let me know... Thanks.
//---- input parameters
extern int RangeStart=04;
extern int RangeEnd=08;
extern int CloseAll=23;
extern bool UseMoneyManagement = true;
extern double Risk=1.5;
extern double Lots = 1;
extern int MagicNumber = 1;
extern int Slippage = 3;
extern bool BrokerECN = true;
extern bool Broker5Digits = true;
extern bool Restart = true;
datetime bartime = 0;
datetime lasttrade = 0;
int SL = 15;
int TP = 45;
int SLMoved = 0;
int k = 1;
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int nOrderTicket = 0;
int nOrderType = -1;
int nTradesNumber = 0;
int nLongs = 0;
int nShorts = 0;
int iTicket = 0;
double sl = 0, tp = 0;
//Getting the range and its boundaries
string sts = StringConcatenate(RangeStart, ":00");
string ste = StringConcatenate(RangeEnd, ":00");
datetime ts = StrToTime(sts);
datetime te = StrToTime(ste);
int ps = iBarShift(Symbol(), 0, ts);
int pe = iBarShift(Symbol(), 0, te) + 1;
int h = iHighest(Symbol(), 0, MODE_HIGH, ps - pe, pe);
int l = iLowest(Symbol(), 0, MODE_LOW, ps - pe, pe);
string text = StringConcatenate(" Day:Hour ",DayOfWeek(),":",Hour(),", Range High: ", High[h], ", Range Low: ", Low[l]," Lots:",GetLots(SL));
Comment(text);
//If the price is above the upper boundary of the range go long
if(Bid >= High[h] + 1*Point && Bid <= High[h] + 5*Point)
{
if(SL > 0)
sl = Ask - SL*Point;
if(TP > 0)
tp = Ask + TP*Point;
if(BrokerECN)
{
iTicket = OrderSend(Symbol(), OP_BUY, GetLots(SL), Ask, Slippage, 0, 0, "", MagicNumber, 0, Blue);
if(iTicket > 0)
{
OrderModify(iTicket, OrderOpenPrice(), sl, tp, 0, CLR_NONE);
}
}
else
{
OrderSend(Symbol(), OP_BUY, GetLots(SL), Ask, Slippage, sl, tp, "", MagicNumber, 0, Blue);
}
lasttrade = Time[0];
//Getting the range and its boundaries string sts = StringConcatenate(RangeStart, ":00"); string ste = StringConcatenate(RangeEnd, ":00"); datetime ts = StrToTime(sts); datetime te = StrToTime(ste); int ps = iBarShift(Symbol(), 0, ts); int pe = iBarShift(Symbol(), 0, te) + 1; int h = iHighest(Symbol(), 0, MODE_HIGH, ps - pe, pe); int l = iLowest(Symbol(), 0, MODE_LOW, ps - pe, pe); string text = StringConcatenate(" Day:Hour ",DayOfWeek(),":",Hour(),", Range High: ", High[h], ", Range Low: ", Low[l]," Lots:",GetLots(SL)); Comment(text);
The above is where the problem occurs. (next time use the SRC button to insert code)
There is nothing in the code to even suggest anything more than direct conversion of the numbers entered for time to the seconds passed since 1/1/70. Nothing to suggest an offset.
lest I'm mistaken; ts will return last compile date not the seconds passed since 1/1/70.
Also, using StringConcatenate in start() is cumbersome. Use arithmetic operations on datetime instead.
See the example in this indicator.
good luck.
The above is where the problem occurs. (next time use the SRC button to insert code)
lest I'm mistaken; ts will return last compile date not the seconds passed since 1/1/70.
The above is where the problem occurs. (next time use the SRC button to insert code)
lest I'm mistaken; ts will return last compile date not the seconds passed since 1/1/70.
Also, using StringConcatenate in start() is cumbersome. Use arithmetic operations on datetime instead.
See the example in this indicator.
good luck.
Thanks a lot, I appreciate it. But the documentation says:
datetime StrToTime( | string value) |
Converts string in the format "yyyy.mm.dd hh:mi" to datetime type (the amount of seconds that have passed since 1 Jan., 1970).
How did you get Compile Time from that? I'm a VBA/SQL programmer by trade, not C, so I know just enough about MQL4 to add some stuff and tweak the logic a litle. I contracted out to have this algorythm coded and added some stuff from there, but changed nothing to do with the date/Time logic. I will study the example you sent and try to understand it but I may have to contract the coding out. So you think that is where the problem is.... Thanks again...
Thanks a lot, I appreciate it. But the documentation says:
datetime StrToTime( | string value) |
Converts string in the format "yyyy.mm.dd hh:mi" to datetime type (the amount of seconds that have passed since 1 Jan., 1970).
This is true if you pass the time format like "yyyy.mm.dd hh:mi".
But if you pass only hh:mi then current date on local computer is automatically added. This is not mentioned clearly in documentation.
You can try to add yyyy.mm.dd to StrToTime() parameter using Year(), Month() and Day() as they return MT4 server date.
Not true. StrToTime() will not return last compile date but local computer time where EA is running if only hh:mm is passed as parameter.
True.
To my knowledge StrToTime(04:00) will return last compile date with time(hh:mm) (consequently local time) that's what I meant.
It will return local computer time if you happen to compile it & call your indicator not long after it. But not local computer as in TimeLocal()*.
Try leaving your terminal on for an hour or until next day; detach that particular EA/Indy but don't close your MT4 -- closing it will recompile the indy on MT4 restart* -- and reattach it later. It will churn out the same compile date/time not current local time despite the StrToTime() is freshly called. FWIW.
*Edited.
Thanks a lot, I appreciate it. But the documentation says:
datetime StrToTime( | string value) |
Converts string in the format "yyyy.mm.dd hh:mi" to datetime type (the amount of seconds that have passed since 1 Jan., 1970).
How did you get Compile Time from that? I'm a VBA/SQL programmer by trade, not C, so I know just enough about MQL4 to add some stuff and tweak the logic a litle. I contracted out to have this algorythm coded and added some stuff from there, but changed nothing to do with the date/Time logic. I will study the example you sent and try to understand it but I may have to contract the coding out. So you think that is where the problem is.... Thanks again...
D'12:30:27' //equal to D'[compilation date] 12:30:27' D'' //equal to D'[compilation date] 00:00:00'
This is from the documentation link I posted. Re-read it. I've proved it (as I've mentioned above) by leaving my terminal on pass the next day (midnight) and call the StringConcatenation function again. I used the same method you used (StringConcatenate). Found it long time ago on iSessions by KimIv. I rewrote that particular sessions Indy because the algo is just not efficient. I can still recall the variable name Kim used. decTradeDay where it went to the number of days of month etc to determine the datetime used for drawing sessions.
datetime is an integer; you can add, subtract, multiply etc. to get where you need to in time. Uncomment my example on that indy to test datetime operations.
Good luck.
This is from the documentation link I posted. Re-read it. I've proved it (as I've mentioned above) by leaving my terminal on pass the next day (midnight) and call the StringConcatenation function again. I used the same method you used (StringConcatenate). Found it long time ago on iSessions by KimIv. I rewrote that particular sessions Indy because the algo is just not efficient. I can still recall the variable name Kim used. decTradeDay where it went to the number of days of month etc to determine the datetime used for drawing sessions.
datetime is an integer; you can add, subtract, multiply etc. to get where you need to in time. Uncomment my example on that indy to test datetime operations.
Good luck.
They keep telling me at Forex.com that they use GMT exclusively for the data server and the MT4 client computer. The use of yyyy.mm.dd.hh.mm instead of just hh.mm will allow designating a time range that overlaps midnight, but will make no difference if the time of the MT4 computer is 5 hours ahead of the server computer. If the MT4 computer is GMT, the code which is running on the MT4 computer must be extracting date info from my DST machine because that is what shows up on the screen. But the VPS application of MT4 is web based. From what I see of the current conditions the only fix that I can understand is to rewrite the date parameters to include yyyy.mm.dd and include an offset paramater. This EA runs on hourly charts BTW.
Suggestions :
- Call TimeCurrent() : it will tell current server/broker time.
- Determine what you want to see your RangeStart as. Do you intend " RangeStart=04:00" as 04:00 AM of your broker chart time? Or you want to see -- for example -- it as US GMT? Or US session perceived in your local TimeZone?
- Calculate the difference (plus or minus) with your intended time zone. Set that as a TimeZone difference constant (disregard DST confusion & use simpler plain GMT zone shift). Add/subtract your intended RangeStart to your intended TimeZone. In Auto_sessions I set extern AsiaStart as translated to my broker timezone, that's not too complicated.
- See the example on my indy. Discard the HH:MM:SS on that date. And add your extern worth of seconds to it.
- Now you have your RangeStart & RangeEnd correct & ready. No StringConcatenate-ion/ server/ local confusion necessary. Hope this helps.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am running a VPS where the time shown on the charts is different from the time input to extern variables in my EA. I uploaded the EA to the MT4 client and access it through the web. The EA uses DateTime() to convert to seconds from 1/1/70. The techs at forex.com keep telling me that it is a problem with my EA. I suggested that maybe it is the difference between MT4 time at the platform where the client runs and time at the platform where the server runs. They insist that the client and the server both run on GMT, so it must be a problem with my EA. They keep telling me that they don't offer MQL4 coding support for my EA. I keep telling them that I do not want coding support for my EA, but just would like to know why the EA code on their MT4 platform interprets and displays a time difference from the time I entered. There is nothing in the code to even suggest anything more than direct conversion of the numbers entered for time to the seconds passed since 1/1/70. Nothing to suggest an offset. The program does not see it in terms of time zones but only raw numbers. I could not get this fact accross to the techs there. They keep saying it is the EA. Yikes.....There is something going on and I do not know what it is....