I have a code from an old trading platform that I need to convert to quantopian logic. This pits VTI:SPY as a pair trading system:

Here is the old code, sorry I'm really bad at algorithmic code and need help. This is a steady wealth accumulator. I have added notes to describe what I am trying to accomplish.

Thanks for anyone that is willing to help!

SYMLIST(VTI,SPY)

/*CALCULATE THE PAIR RATIO*/

SET{LEFT, IND(VTI,CLOSE)}

SET{RIGHT, IND(SPY,CLOSE)}

SET{RATIO, LEFT / RIGHT}

SET{PAIRSPREAD, LEFT - RIGHT}

/*DETERMINE THE 14 DAY MOVING AVERAGE FOR THE RATIO*/

SET{RATIOMA14, CMA(RATIO,14)}

SET{SPREADMA14, CMA(PAIRSPREAD,14)}

/*DETERMINE THE PERCENT ABOVE/BELOW THE MA(14) FOR THE RATIO*/

SET{RATIOPCT1, RATIO / RATIOMA14}

SET{RATIOPCT2, RATIOPCT1 - 1}

SET{RATIOPCT, RATIOPCT2 * 100}

/*DETERMINE THE 14 DAY ZSCORE FOR THE RATIO*/

SET{RATIOSTD14, CSTDDEV(RATIO,14)}

SET{RATIO2STD, 2 * RATIOSTD14}

SET{RATIOUPPERBB, RATIOMA14 + RATIO2STD}

SET{RATIOLOWERBB, RATIOMA14 - RATIO2STD}

SET{RATIODIFF14, RATIO - RATIOMA14}

SET{RATIOZSCORE, RATIODIFF14 / RATIOSTD14}

SET{SPREADSTD14, CSTDDEV(PAIRSPREAD,14)}

SET{SPREADDIFF14, PAIRSPREAD - SPREADMA14}

SET{SPREADZSCORE, SPREADDIFF14 / SPREADSTD14}

/*DETERMINE DIRECTION OF PAIR TRADE AND THE NUMBER OF SHARES TO BE BOUGHT OR SOLD*/

SET{BELOWLBB, COUNT(RATIOZSCORE BELOW -2,1)}

SET{ABOVEUBB, COUNT(RATIOZSCORE ABOVE 2,1)}

SET{LEFTSHARES1, 10000 / LEFT}

SET{LEFTSHARES, ROUND(LEFTSHARES1, 0)}

SET{LEFTLONG, BELOWLBB * LEFTSHARES}

SET{LEFTSHORT, ABOVEUBB * LEFTSHARES}

SET{RIGHTSHARES1, 10000 / RIGHT}

SET{RIGHTSHARES, ROUND(RIGHTSHARES1, 0)}

SET{RIGHTLONG, ABOVEUBB * RIGHTSHARES}

SET{RIGHTSHORT, BELOWLBB * RIGHTSHARES}

Hopefully this can be coded as it has a 100% winning record from 2011!