This should probably belong in a programming or trading section, but this is where the sponsor resides. Trying to earn some goodwill points(why, it's free anyway). You may find the research paper interesting as well.
I could write this in less code with Interactive Brokers API. Haha just kidding. Thanks for the post.