So you have an array of bars, the length of each bar defined by barsecs, then the array size is (86400 seconds) / (barsecs seconds) bars. When new tick arrives you calculate to which bar the tick belongs to and you update that bar with new tick's data. So you download real time data but you use bars for analysis, right?
Interesting thread tiagor. Alot of people are troubled by the idea of coding an infrastructure before you have a trading strategy but I approached this the same way you are. The idea being that you need the mechanisms anyway and you can work out a strategy once you have the modules working right. Some of the stuff you are writing is also needed if you want a backtesting module and it makes sense to start out with very simple strategies while you are still developing and debugging. It is pretty exciting when you have data and have your code running and start testing simple strategies. Its worth the effort to spend alot of time studying and coding accepted measures of performance so you can discuss outcomes with other people (Sharpe etc) in terms they will understand. It is also worth the time to validate the accuracy of the performance measures that you code by canning a reference data set for which performance has been measured by others for a very very simple strategy. The first time my ATS made a real trade and worked it made about $60.00 and I couldn't stop grinning for that whole day and the next. Amazing satisfaction even if it didn't make me rich. Even if your ATS only pays for your lunch it is still fun and nothing is stopping you from doing some discretionary trading in parallel. One thing though, don't be tempted to run your ATS unattended for a good long time until you've had time to watch it work through quite a variety of different market conditions. You probably don't need to be told this but make sure you really stay on top of updates to the API made by the broker. They *will* break something occasionally. I'll be watching your thread. Good luck and thanks for sharing.
Agreed. If you really insist on having all the quotes from the last 10 minutes, though, just stuff the quotes into some sort of FIFO queue (in C++ this could be std::queue, std::list or std::deque). Every time you get a tick, examine and pop all the quotes which are older than ten minutes. Something like Code: void tick() { while (true) { Quote q = theQueue.peek(); if (currentTime() - q.time() <= tenMinutes) break; theQueue.pop(); } } Your stuff should all be running on ticks. If you need bars for some particular task, just reconstruct them from the quotes. This thread is pretty fun, I enjoy reading the posts here.
As above, use a List or similar. Put the ticks into the list over the 10 mins, then when the first 10 mins expires, calc the average. From there on, re-calc the average every second or whatever, while the list is still being populated with new ticks, and, discard the ticks that are now older than 10 mins ... thus maintaining the window. *you may need to get familiar with locking for this to not crash. That being said, I don't think there is any efficacy in using a 10 min sma for really anything at all. Sorry to be a dick ..
I got it about the "window" concept. THX to you and previous posters too. You do not use any of MA for your strategies? Or it's 10 min SMA that troubles you, I just used 10 min as an example.
No MAs at all really. Occasionally a vwap over the day, but nothing where each trade is assigned the same weight. Scoring all trades with the same weight would imply that everyone knows what they are doing & all trades are equally informed. This is, in my view, ridiculously fanciful.
There is nothing about MAs that requires fixed-time buckets. I can see the rational behind fixed-price and fixed-volume and fixed-tick-count bars, all of which will produce variable-time bars, but fixed-time bars have never really made sense to me.