CopyTicks in indicator

 
According to docs, "when called from an indicator, CopyTick() immediately returns all available ticks of a symbol, and will launch synchronization of the tick database, if available data is not enough." 

My question is, how can i check data is sync, if it returns immediately without error and with result>0 ?

I tried  SymbolIsSynchronized(_Symbol) function, but it returns true event if all data gaps have not be filled by trading server yet.

 

Normally SymbolIsSynchronized should work (and worked for me). If you can locate the problem feel free to post a test case for the bug.

Also you probably want to check TerminalInfoInteger(TERMINAL_CONNECTED) before all other checks, and also look at SeriesInfoInteger(_Symbol, _Period, SERIES_SYNCHRONIZED).

 
Stanislav Korotky #:

Normally SymbolIsSynchronized should work (and worked for me). If you can locate the problem feel free to post a test case for the bug.

Also you probably want to check TerminalInfoInteger(TERMINAL_CONNECTED) before all other checks, and also look at SeriesInfoInteger(_Symbol, _Period, SERIES_SYNCHRONIZED).

I tried to also add these checks before copyTicks call, but alway give me true.

The simple test i do is disable network on my pc, wait some minutes, and reconnect. Indicator pass all three checks - TerminalInfoInteger(TERMINAL_CONNECTED) and  SeriesInfoInteger(_Symbol, _Period, SERIES_SYNCHRONIZED) and SymbolIsSynchronized(_Symbol) - call copyTicks using "from time" the time before disconnection, but give me only current tick, skipping the precedent ones... 

onCalculate is called with prev_calculated=0, more than one time, so terminal "signaling" indicator it is filling gaps, but i need to call copyTicks just when history is synch, not before. Is there no way to check this?

 
antony23 #:

I tried to also add these checks before copyTicks call, but alway give me true.

The simple test i do is disable network on my pc, wait some minutes, and reconnect. Indicator pass all three checks - TerminalInfoInteger(TERMINAL_CONNECTED) and  SeriesInfoInteger(_Symbol, _Period, SERIES_SYNCHRONIZED) and SymbolIsSynchronized(_Symbol) - call copyTicks using "from time" the time before disconnection, but give me only current tick, skipping the precedent ones... 

onCalculate is called with prev_calculated=0, more than one time, so terminal "signaling" indicator it is filling gaps, but i need to call copyTicks just when history is synch, not before. Is there no way to check this?

Seems i found the problem, when copyTicks result is greater than 0, we need also check the error code. In fact, i get 2 ticks as result of CopyTicks and error code ERR_HISTORY_TIMEOUT 4403. We have to check both, return value and error code.
 
antony23 #:
Seems i found the problem, when copyTicks result is greater than 0, we need also check the error code. In fact, i get 2 ticks as result of CopyTicks and error code ERR_HISTORY_TIMEOUT 4403. We have to check both, return value and error code.

This is not how it's supposed to work.

From documentation :

Returned value

The number of copied tick or -1 in case of an error.

Documentation on MQL5: Runtime Errors / Constants, Enumerations and Structures
Documentation on MQL5: Runtime Errors / Constants, Enumerations and Structures
  • www.mql5.com
GetLastError() is the function that returns the last error code that is stored in the predefined variable _LastError . This value can be reset to...
 
antony23 #:
Seems i found the problem, when copyTicks result is greater than 0, we need also check the error code. In fact, i get 2 ticks as result of CopyTicks and error code ERR_HISTORY_TIMEOUT 4403. We have to check both, return value and error code.
Yes, copying tick via an indicator can be tricky, as they run in sing le threads, so terminal returns tick instantly whether good or not good, like to avoid affecting other indicators.

To fix this use an Expert Advisor to maybe run tick down loa. Takes time based on tick size, then run your indicator on the tick. 
 
Alain Verleyen #:

This is not how it's supposed to work.

From documentation :

So or documentation is wrong or terminal is buggy. I can confirm i can get result>0 and also error code.
 
antony23 #:
So or documentation is wrong or terminal is buggy. I can confirm i can get result>0 and also error code.
Following works:

Add your tick volumes from your bars, given to you via OnCalculate. Use this to verify your bid ticks received via CopyTicks.

If they are the same value, you can assume, you are in sync.

Beware, frequent calls to CopyTicks for most up to date ticks can sometimes yield a small portion of ticks missing in the result array, which you have recently received in a prior call. - This is most likely due to the terminal locking the last added ticks while updating its internal data.

Extracting reliability and consistency out of the terminal is a challenge.

Edit: ignore the error code. Its useless in this regard.
 
antony23 #:
So or documentation is wrong or terminal is buggy. I can confirm i can get result>0 and also error code.

This is not what I meant : yes you can get an error code but if the result is >0 it should be irrelevant (there are a lot of situations where an error code is set without a final error returned, as discussed on the forum several times).

If you think it's an MQL5 issue please post the code to reproduce it.

 
In general all this topic is unproductive without code to discuss concretely.