TickOperation, BarOperation and DataSeries thread safety

trdrbust

Member
Joined
Nov 13, 2020
Posts
18
Likes
4
So, looking at the MW provided VWAP indicator.

Looks like a ForEachTick\TickOperation class handles the historic backfill, and I read somewhere(can't find right now) that the operations run in their own background thread.

A DataSeries is passed into and saved as part the VWAP tick operation class state. This dataseries is updated from both the backfill processing and live Study.OnTick() "events".

Since the DataSeries is passed into the operation that runs on it's own thread and tickoperation writes to the Dataseries(the calculated VWAP), can I assume that DataSeries is thread-safe and supports multiple writers ? Could I have multiple TickOperations all writing to the same dataseries ? Just looking for a little insight into the whole operation concept.....
 

Spin

Well-known member
Joined
May 22, 2019
Posts
477
Likes
191
I'm not entirely sure that I understand everything you want / say, but I can tell you this:

  • You can definitely write to the DataSeries from different parts of your code (to update a Value, for instance). You could do it onTick, but also when the Bar closes, should you want to.
  • I have programmed a Strategy (that uses onTick), based on a Study that also uses onTick, but I encountered 'weird behavior', spent too many hours trying to grasp what was going on, and in the end did a major code-overhaul so that my Strat no longer needed onTick (instead I had the Study fire of signals in onTick and the Strat react to them)
  • Most of the time (in the standard MW Studies & Strategies) it's actually Calculate or CalculateStudies that 'backfill' the chart. onTick can obviously do this as well, but imo the former two are better suited. I try to avoid onTick as much as I can. Only calculations that HAVE to happen on each tick get a seat at the tick-table :)
This is just my 2 cents. As always in coding endeavours: your mileage may vary :cool:
 
Top