Hi

Based on the data in the Tick data folder, which includes trade and quote, I have attached an algorithm to create a limit order book (L2 data).

Due to backtesting limitations, I have drawn price and volume charts every 5 minutes. The midprice and weighted order imbalance ratio are plotted in the chart. As far as I know this ratio is important in HFT and by using this ratio we can have a better price forecast.

I would be very happy if you make a suggestion regarding increasing the accuracy of the results and its usability.

In some cases, the getLOrders method does not work properly by changing the date of the algorithm due to the presence of some Trade orders at the time before the market Open or quote orders outside the range. It is clear that Cancel orders are not considered in this algorithm. I would be happy if you have a suggestion to correct it.

I hope we can better predict midprice in intrady trading by using this algorithm and ML ideas and statistics and parameter optimization. As there are many papers on this topic. And it can be used in the Algorithm Framework to send more accurate Insights.

Best,
R.Faidi