I'm building an algorithm which uses a live market data feed to updates its P&L and other metrics. I've been noticing that sometimes in the time and sales there are anomalous prints - prices many standard deviations above or below the best bid/offer on the level 2. Where are these sales coming from? And is there a good method to filter them from the time and sales prints my algorithm is reading? As currently, these anomalous prints are throwing my algo's P&L way off and leading to unnecessary stops.
There should be a code attached to all trades that your program receives from a data feed. This code tells you the condition of the trade like a cross trade, an out of sequence trade (your problem above), etc. You need to make these codes part of your program so that your program knows how to handle the info it is getting from the data feed. I have attached a link to info from SIAC on the NYSE website. It's an exciting read. Good luck!