It basically a heuristic way to break down orders according to where the price is relative to the target price. The variables are mostly based on experiments. You can play with them or we can make them dynamic. I also add the initial file. We took a bunch of stocks and collected prices every 2 sec. Algo measures the price relative to the target and breaks order size in relation to that. It is simulation so one would have to extract the part of the code that does the decision-making to make a separate function to include in real execution algo. I will do that in a little while too. You can try to rewrite it in Python too. I think I have a Python version somewhere. But this code gives you a feeling of how a good execution strategy should work. This one achieves (at least in the simulation) almost 0 slippage (in fact a slightly negative slippage) and almost 100 % fill. You can break the algo and invent your own inspired on this one.