grid system of buy limit orders: I need to know the last two price level when appen: opened or closed of two consecutive orders; opened and closed an order

 

In a grid system of orders of one type (example buy limit) I need to know the values of price levels when the order is opened or closed.

I need to know the last 2 price levels in which an order has been opened, closed, or opened and closed.

If the orders are, for example, of the buy limit type, I can have 3 situations:

A) The price drops and opens several orders consecutively: I need to know the last 2 levels of the opening price of the orders;

B) The price go long and closes several orders consecutively: I need to know the last 2 levels of closing price of the orders;

C) The price goes down by opening a buy limit order and then goes up to closing the same order: in this case the two previous price levels are the opening and after the closing one.

I need a code that gives me the two price levels (last and second to last) based on which of the 3 situations occur.

Can someone help me and resolve this question?

Thank you J

 

If you want to code it yourself you will have to post your attempt if you need help.

Otherwise you can try the Freelance section.