https://docs.mql4.com/dateandtime/timecurrent
During testing in the Strategy Tester, TimeCurrent() is simulated according to historical data.

- docs.mql4.com
Ok I just read somewhere that back-tester time-current and real-life time-current can never be the same.
I just want to know in which scale does it differ, can it be worked around so that it can be the same. Or any other way to count seconds after a function is executed? that can if not close match tester and live counts.
Problem is solved.
On Live OnTick() TimeCurrent() wait for a tick from a broker, if there is no tick, TimeCurrent calculations do not work. While on tester ticks are always available so TimeCurrent calculations are accurate.
So I added Sleep(100) and TimeCurrent calculations seems to return accurate e.g Hline updated every after 2sec.
//+------------------------------------------------------------------+ //| Testing.mq4 | //| Copyright 2015, MetaQuotes Software Corp. | //| https://www.mql5.com | //+-----------------------------------------------------------Ndumiso+ #property copyright "Copyright 2015, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" extern double TimeToChnge=2;//The Hline will move after 2 seconds extern double Dis=5; double UsePoint; int TimeBar,Obj; //+------------------------------------------------------------------+ //| Expert initialization function | //+-----------------------------------------------------------Ndumiso+ int OnInit() { //--- UsePoint = PipPoint(Symbol()); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+-----------------------------------------------------------Ndumiso+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+-----------------------------------------------------------Ndumiso+ void OnTick() { while (!IsStopped())//Added { if(ObjectFind(0,"Hline")!=0){ if(ObjectCreate("Hline", OBJ_HLINE, 0,0,NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK)+Step * UsePoint,Digits),0,0)!=-1) TimeBar=TimeCurrent(); ObjectSet("Hline", OBJPROP_STYLE, 3); ObjectSet("Hline", OBJPROP_COLOR, LimeGreen);} if(ObjectFind(0,"Hline")!=-1) {Pric=ObjectGet("Hline",OBJPROP_PRICE1); Obj=ObjectGet("Hline",OBJPROP_PRICE1);}else Pric=0; if (Obj!=0) { if (TimeBar<=TimeCurrent()-TimeToChnge) { Print(TimeToStr(TimeCurrent(),TIME_SECONDS)); if(ObjectSet("Hline",OBJPROP_PRICE1,NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK) + Step * UsePoint,Digits))) TimeBar=TimeCurrent(); } } Sleep (1000);//And added } } //+------------------------------------------------------------------+ //| Broker Digits | //+-----------------------------------------------------------Ndumiso+ double PipPoint(string Currency) { int CalcDigits = MarketInfo(Currency,MODE_DIGITS); if(CalcDigits == 2 || CalcDigits == 3)double CalcPoint = 0.01; else if(CalcDigits == 4 || CalcDigits == 5) CalcPoint = 0.0001; return(CalcPoint); } //+------------------------------------------------------------------+ //| End | //+-----------------------------------------------------------Ndumiso+

- 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 have noticed something which I do not know if its true yet, I would like someone to give their opinion on this.
I think Strategy Tester calculations on TimeCurrent() gives different results than live, for an example, If I send an order ==> record the time when it is sent ==> take the recorded time and compare it with (current time - 2seconds). On Tester 2 seconds might be faster compared to real life?
To get same Speed Live as was in Strategy Tester, I think 2 seconds would have to be -2seconds because 2 seconds will be too slow Live.
A code of what I am saying here: