Hi,
i have a doubt about reliability of data obtained via CopyBuffer in EA.
Considering this example. Let's assume we have a custom indicator where each tick in onCalculate sets 3 buffer:
Now let's consider getting these values in EA:
My question is: How i can be sure, when reading data copied using CopyBuffer, that i can get A[0],B[0],C[0] setted at the same "call" of OnCalculated? That is, it could happen that i can get A[0] setted on latest OnCalculate excution and getting B[0] and C[0] setted on latest-1 OnCalculated execution? I need to avoid getting inconsistent data from indicator.
Summary, is a single buffer thread safe? Are indicator buffers (all togheter) thread safe?
No, they are not thread safe. Indicators are run in the chart thread, EAs have their own thread. It is very likely to receive old values from the indicators buffers.
I would say it's possible, but not "very likely". Anyway, if you need synchronization, the result is the same.
Or just add a "all-at-once" buffer with data you need to be synchronized, so it's one call to CopyBuffer().
Maybe do you mean putting these data on the same buffer with different indexing?
That coudl be done, of course, but who garantee me that a single CopyBuffer call, example from index 0, count 3, would give me consistent data? Could happen that CopyBuffer copy at example index 0 an 1 values from the latest OnCalculate excution and index 2 from lastest-1 OnCalculate execution?
In fact in the first post i did two questions, the first was: "is a single buffer thread safe?"
The problem is not having old values inside EA, but that these values, even if old, are consistent, that is calculated in the same "OnCalculate" iteration.
To me seems very absurd that CopyBuffer function is not thread safe realtive to arrays used to copy from and to. The same documentation advice to divide actions, that is calculated on Indicators and use data calculated on EA, but without data integrity it is impossible.
That coudl be done, of course, but who garantee me that a single CopyBuffer call, example from index 0, count 3, would give me consistent data? Could happen that CopyBuffer copy at example index 0 an 1 values from the latest OnCalculate excution and index 2 from lastest-1 OnCalculate execution?
In fact in the first post i did two questions, the first was: "is a single buffer thread safe?"
Yes. Of course a single buffer is thread safe, otherwise it would be absurd design.
An indicator is running in 1 thread, with the data. While the indicator is running to update data (write on the buffer), you can't read it at the same time.
EDIT: Actually we both don't know how it's done in practice, my guess was MQ made it thread safe, but you could be right. I will ask them more information.
An indicator is running in 1 thread, with the data. While the indicator is running to update data (write on the buffer), you can't read it at the same time.
EDIT: Actually we both don't know how it's done in practice, my guess was MQ made it thread safe, but you could be right. I will ask them more information.
An indicator is running in 1 thread, with the data. While the indicator is running to update data (write on the buffer), you can't read it at the same time.
EDIT: Actually we both don't know how it's done in practice, my guess was MQ made it thread safe, but you could be right. I will ask them more information.
The things are these:
- or copybuffer is thread safe, but that would mean that also writing data in buffers, inside Oncalculate, should be done using copybuffer and not setting single index value in a loop. And i didn't read this anywhere in documentation.
- or the deisgn is done in the way that OnCalulate and OnTicks, on the same chart, are executing sequentially, even if in its own thread. Using separate threads for EAs could be usefull to execute, instead, more OnTick events on the same symbol, from different EAs (and so from different charts) simultenously.
I suspect the second is the most likely, otherwise this simultaneous data access problem should have been very well documented, but instead I haven't found anything about it, and I've searched really hard.
Anyway i'll wait for your news.
Thanks.
The things are these:
- or copybuffer is thread safe, but that would mean that also writing data in buffers, inside Oncalculate, should be done using copybuffer and not setting single index value in a loop. And i didn't read this anywhere in documentation.
- or the deisgn is done in the way that OnCalulate and OnTicks, on the same chart, are executing sequentially, even if in its own thread. Using separate threads for EAs could be usefull to execute, instead, more OnTick events on the same symbol, from different EAs (and so from different charts) simultenously.
I suspect the second is the most likely, otherwise this simultaneous data access problem should have been very well documented, but instead I haven't found anything about it, and I've searched really hard.
Anyway i'll wait for your news.
Thanks.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
i have a doubt about reliability of data obtained via CopyBuffer in EA.
Considering this example. Let's assume we have a custom indicator where each tick in onCalculate sets 3 buffer:
Now let's consider getting these values in EA:
My question is: How i can be sure, when reading data copied using CopyBuffer, that i can get A[0],B[0],C[0] setted at the same "call" of OnCalculated? That is, it could happen that i can get A[0] setted on latest OnCalculate excution and getting B[0] and C[0] setted on latest-1 OnCalculated execution? I need to avoid getting inconsistent data from indicator.
Summary, is a single buffer thread safe? Are indicator buffers (all togheter) thread safe?