I'm new here and to Python in general, and am trying to port my scripts from thinkorswim into QuantConnect and am having beginner's confusion.

This is the start of my SPY pullback strategy. Right now I only have 2 questions:

1. what is the sytax error I am getting and how do i fix it?

2. how do I define variables in python for buy and sell orders. For example I want to have a primary condition, in this case SPYHigh>SMA200. and use this to determine if I buy with 1 set of criteria or another. I have these conditions ## out in the code.


import numpy as np

class BasicTemplateAlgorithm(QCAlgorithm):
    '''Basic template algorithm simply initializes the date range and cash'''

    def Initialize(self):
        self.SetStartDate(2007,1, 1)  #Set Start Date
        self.SetEndDate(2018,9,31)    #Set End Date
        self.SetCash(10000)           #Set Strategy Cash
        self.AddEquity("SPY", Resolution.Day)
        self.AddEquity("UPRO", Resolution.Day)
        self.RSI = self.RSI("SPY", 2)
        SMA200 = self.sma = self.SMA("SPY", 200)
        SMA20 = self.sma = self.SMA("SPY", 20) ## will use this later on

    def OnData(self, data):
        if not self.RSI.IsReady: 
#var buy1 = RSI<24 && adx>20;
#var buy2 = RSI<10 && adx>30;
#if _spyhigh>Avg200 then buy1 else buy2;

        if self.spy.Current.High>SMA200 && rsi<24 and self.Portfolio["UPRO"].Invested <= 0:
            self.Debug("UPRO buy")
            self.MarketOrder("UPRO", 5000)
            self.Debug("Market order was placed")
#var sell1 = _spy>_Avg20 && RSI>85;
#var sell2 = _spy>Avg20 && RSI>80;
#if _spyhigh<SMA200 then sell1 else sell2;        
        if self.spy.Current.High<SMA200 then rsi<80 else rsi>85:
            self.Debug("UPRO sell")