This may be good code to review if you are looking for more samples. It increases the position size as a z score hits predefined levels.

https://robotwealth.com/pairs-trading-zorro/