Alright, I had another thread where I was trying to find where ratios are deviating between pairs and when they reach an outlier 2.5*Standard Deviation to short one and go long the other. Here is the code that I came up with... again, I am terrible at Quant coding so go easy.
I still think it needs work to exit the pair trade before entering a new one. Also, the leverage is really bad and I don't know how to fix that. Any help is appreciated.