-> TWAP is an anchored moving average. This means that it is a moving average, for which the period is incremented by 1 for each bar.
-> TWAP is only a simple moving average (SMA) on charts with a fixed period. The reason is simple. If all bars have the same duration, the weight used for each bar is one, and the TWAP is identical with an anchored SMA.
-> On other chart types, such as tick, range or volume chart, the bars do not have the same duration, so a time-weighting is necessary to calculate the TWAP. In this case the TWAP is a time-weighted moving average (TWMA).
-> If you divide a large order and execute it over time in a linear fashion, that is at a constant execution speed, at the end of the day your execution price will be the TWAP. I believe that nobody is doing this anymore.
Sure - the bar periodicity controls the sampling frequency. The start bar controls the anchor point. If you don't want that to be at the beginning of a session you'd have to write a couple of lines of extra code.
bomberone1 has been posting for some while now round the internet asking 'can you give me TWAP code', I thought I'd try and help. If you explain exactly what you need bomber it should not be too hard to point you in the right direction.
Compared to VWAP TWAP is ....well... trivial to implement. VWAP is much tricker especially if you want to use an online algorithm (making it suitable for large data sets like tick data) and include stuff like SD's.
Maybe its just semantics but if you speak to most traders about TWAP they will assume you are talking about execution. Platforms that offer TWAP execution do indeed break up a large order and executes it as a batch of smaller orders over time. That's all I meant there
What I don't understand is what bomber wants. If it is TWAP execution there are platforms that offer it, if it's plotting it on a chart its pretty straight forward.
Incidentally I glanced at the code that you have and it appears OK Bomber, what do you want improved?
The following user says Thank You to NickA for this post:
I think that you cannot easily spot them. If I had to code a TWAP execution algorithm, I would include at least two elements
-> breaking up the order into equal slices over the execution period
-> use another algorithm which acts in a similar fashion as a random generator to hide the execution
Also TWAP is really the first generation of execution algorithms, and there are much better options.
However, you may well examine the ticker tape for non-random properties. If a specific ordersize regularly occurs on the order book, you may at least conclude that a larger order is executed by a primitve algorithm and decide to exploit it. If the time intervals between these orders are identical, it may well be a TWAP algorithm working, But how would you want to generate profits?