Lets say I have two stocks x and y and their corresponding stock price p(x) and p(y). consider HR as hedge ratio. Then we can calculate the spread using this equation.

$spread=p(x)-HR*p(y)$

from this step what rationale should we use for buying and selling pairs?

This is my logic

Pairs trading works for two highly correlated stocks. We then sell the costlier stock and buy cheaper stock simultaneously.

If spread is positive the price of x is higher than price of y so we will sell x and buy y . if spread is negative y is costlier than x then we sell y and buy x simultaneously. So the total return on pairs trading can be return as

$TotalReturn=sell(return of asset 1)-HR*buy( return of asset2)$

pseudocode

if(spread>0 and entry_threshold=True)



is this rationale correct?

another question? If price of x is 13 dollar and price of y is 63 dollar then how many shares of x and y should we buy and sell simultaneously in a pairs trading?

In fact, the whole point of the hedge ratio is to assume that it is the ratio that the stocks will revert back to over time. So if we denote the spread at time $t$ by $s_t$ and the hedge ratio as $\beta$, we have $$s_t = p(x_t) - \beta p(y_t) + \epsilon_t$$ where $\epsilon_t$ is the deviation from the equilibrium state. When you get your signal and let's say $s_t>0$, you sell \$1 worth of$x$and buy \$ $\beta$ worth of $y$.
How do you decide $\beta$? Well, usually by doing a linear regression using some past data. In the stated model it is natural to regress $x_t$ on $y_t$ and force the intercept to be $0$.