Overall Statistics
import numpy as np
from datetime import timedelta
from datetime import datetime
import pandas as pd


class MovingAverage(QCAlgorithm):

 

     def Initialize(self):
        self.SetStartDate(2018, 1, 1)
        #self.SetEndDate(2016, 1, 10)
        self.SetCash(100000)
        self.vixy = self.AddEquity("VIXY", Resolution.Minute).Symbol
        self.svxy = self.AddEquity("SVXY", Resolution.Minute).Symbol
        self.SetWarmUp(2860,Resolution.Hour)
        self.previous = None
        self.position = None
        self.macd1 = self.MACD(self.vixy, 40, 85, 30, MovingAverageType.Exponential, Resolution.Hour)
        self.macd2 = self.MACD(self.svxy, 40, 85, 30, MovingAverageType.Exponential, Resolution.Hour)
        #self.rsi_vixy = self.RSI("VIXY", 18, MovingAverageType.Exponential,Resolution.Hour)
        #self.rsi_svxy = self.RSI("SVXY", 18, MovingAverageType.Exponential,Resolution.Hour)

        

     def OnData(self,Data):
        if self.IsWarmingUp: return
     
     
     
     
        if self.macd1.Current.Value > self.macd1.Signal.Current.Value and self.macd2.Current.Value < self.macd2.Signal.Current.Value:
            #self.rsi_spy.Current.Value >= 70
            
            if self.position == None:
                    self.SetHoldings("SVXY", -.5)
                    self.SetHoldings("VIXY", .5)
            else:
                    self.Liquidate("SVXY")
                    self.SetHoldings("VIXY", .5) 
                    self.SetHoldings("SVXY", -.5)
                    self.SetHoldings("VIXY", .5)
            
            
                    
                
                  
                  
        if self.macd1.Current.Value < self.macd1.Signal.Current.Value and self.macd2.Current.Value > self.macd2.Signal.Current.Value:
                #self.rsi_spy.Current.Value <= 40
                
            if self.position == None:
                self.SetHoldings("VIXY", -.5)
                self.SetHoldings("SVXY", .5)
            else:
                self.SetHoldings("SVXY", .5)
                self.Liquidate("VIXY") 
                self.SetHoldings("VIXY", -.5)
                self.SetHoldings("SVXY", .5)