TimeCurrent() lagging as hell!

 

Hi guys,

What is the best workaround for having the broker server's time update lag like hell, like refreshing only once or twice every 15 seconds or so? 

I tried to put RefreshRates();  after TimeCurrent() command but it doesn't seem to improve anything at all... even using TimeLocal with RefreshRates();  doesnt work out...

Should I try to code a timer like 1 to 5 seconds in continual loop with my command happening then?

Thanks.

 
It's not lagging at all. It is current server time. It updates when a new tick is received from the server. No tick, no change. Why do you care?
 
tayofu:

Hi guys,

What is the best workaround for having the broker server's time update lag like hell, like refreshing only once or twice every 15 seconds or so? 

I tried to put RefreshRates();  after TimeCurrent() command but it doesn't seem to improve anything at all... even using TimeLocal with RefreshRates();  doesnt work out...

Should I try to code a timer like 1 to 5 seconds in continual loop with my command happening then?

Thanks.

Server/Broker time is only updated when new price quote/tick arrives. That is not error. It is supposed to be like that!

If no tick is produced there is no reason to do anything, so why do you want a continous loop?

Do proper OnTick() and other event handling and you will not need to loop your code continously.
 
Fernando Carreiro:
Server/Broker time is only updated when new price quote/tick arrives. That is not error. It is supposed to be like that!

For completeness, there are three slightly different possible answers to tayofu's question, involving something implicit rather than fully explicit in what you and whroeder1 have covered.

TimeCurrent() only updates when a new tick is received, which only happens for symbols in the Market Watch. If the Market Watch contains something like EURUSD then the time will tick over very frequently. If it only contains something like an equity index, then it potentially won't tick over at all during hours when the underlying exchange is closed.

So, three possible answers to tayofu:

  • Your Market Watch only contains illiquid instruments. Adding something like EURUSD will cause TimeCurrent() to update more frequently.
  • All your broker's symbols, including even fx majors such as EURUSD, are bizarrely illiquid. Nothing you can do about this to make TimeCurrent() update more frequently. If you need a more accurate timestamp, e.g. in order to do some sort of tasks in OnTimer(), then you are going to have to use the local computer clock rather than the broker's clock.
  • There's a problem with your internet connection, and packets are being lost, causing the time only to update occasionally.
 
JC:

For completeness, there are three slightly different possible answers to tayofu's question, involving something implicit rather than fully explicit in what you and whroeder1 have covered.

TimeCurrent() only updates when a new tick is received, which only happens for symbols in the Market Watch. If the Market Watch contains something like EURUSD then the time will tick over very frequently. If it only contains something like an equity index, then it potentially won't tick over at all during hours when the underlying exchange is closed.

So, three possible answers to tayofu:

  • Your Market Watch only contains illiquid instruments. Adding something like EURUSD will cause TimeCurrent() to update more frequently.
  • All your broker's symbols, including even fx majors such as EURUSD, are bizarrely illiquid.
  • There's a problem with your internet connection, and packets are being lost, causing the time only to update occasionally.
Yes, that is a more complete answer, but it does not negate the fact that there is no need to have a continous loop if no real action is necessary. If the price on the symbols in use have not changed then there is no stops to change, nor indicators to check, etc.
 
Fernando Carreiro:
there is no need to have a continous loop if no real action is necessary. If the price on the symbols in use have not changed then there is no stops to change, nor indicators to check, etc.

If...

Without commenting on whether such a thing is likely to be profitable, there are many trading strategies with rules such as "close an order no more than 30 seconds after it was opened". That obviously requires time-based activity, and a reliable timestamp, rather than price-based activity in OnTick().

 
JC:

If...

Without commenting on whether such a thing is likely to be profitable, there are many trading strategies with rules such as "close an order no more than 30 seconds after it was opened". That obviously requires time-based activity, and a reliable timestamp, rather than price-based activity in OnTick().

That is why I wrote "handle your events properly", as OnTimer() is an event handler. There is no need for continous loops!

Actualy, to be more correct, I wrote "Do proper OnTick() and other event handling ..."

 
Which is also why I wrote "why do you care." Without context only simple facts can be stated. JC stop guessing what the OP really wants and wait for his answer.
 
whroeder1:
Which is also why I wrote "why do you care." Without context only simple facts can be stated. JC stop guessing what the OP really wants and wait for his answer.

I interpreted - perhaps quite wrongly - "why do you care?" in the same way as Fernando's question "If no tick is produced there is no reason to do anything, so why do you want a continous loop?". I took it not as an actual enquiry for more information from tayofu, but as a way of saying, as Fernando did more explicitly, "you don't need to care how often TimeCurrent() changes".

There are obviously lots of reasons why you might care about the time even if the price hasn't changed. A really big and very common one is making sure that you don't carry open positions over a period of closure of the market.

 

Thank you guys for your help and feedbacks.

My inquiry was pertaining to EURUSD not to an equity index. What is bizarre is that - even when using TimeLocal - the time refresh still lags a lot... sometimes only 1 refresh per minute or even longer... sometimes 90 seconds... my ping to the sever is less than 1ms and my vps is strong using SSD and so on.

For now what I was trying to achieve was to record say the Ask price every 5 seconds. But many times there is no TIME_SECONDS 5 it jumps from 1 to 12 or from 3 to 6 for a long period so I am trying to figure out how to record this... also SECONDS only relate to server time not to TimeLocal if I am not mistaken...

Since I dont now the number of ticks in a given 5-sec period I dont think the OnTick() command would be useful...?

Rgds.
 
tayofu:

What is bizarre is that [...]

You mention two separate things which would each be so bizarre that - and, yes, I'm guessing - I think that the problem must be in your code. Need to see some code to work out what the problem is.
Reason: