Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
from datetime import timedelta

class IndicatorTest(QCAlgorithm):

    def Initialize(self):

        self.SetStartDate(2015,5,25)  #Set Start Date
        self.SetEndDate(2017,11,25)    #Set End Date
        self.SetCash(10000000)           #Set Strategy Cash

        self.symbols = [
            Futures.Indices.SP500EMini,
            Futures.Metals.Gold,
            "CL",
            "CG",
            #"HG",
            #"XK",
        ]
        
        self.fast = {}
        self.slow = {}
        for symbol in self.symbols:
            future = self.AddFuture(symbol, Resolution.Daily)
            future.SetFilter(timedelta(0), timedelta(182))
            
            # Note use of future.Symbol, if we use symbol string we get error regarding unsubbed asset(so use the object instead)
            self.fast[symbol] = SimpleMovingAverage(10)
            self.slow[symbol] = SimpleMovingAverage(100)
            
#        self.do_once = True


    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''
        # a couple things to notice in this method:
        #  1. We never need to 'update' our indicators with the data, the engine takes care of this for us
        #  2. We can use indicators directly in math expressions
        #  3. We can easily plot many indicators at the same time
        
        # only once per day
        #if self.previous is not None and self.previous.date() == self.Time.date():
        #    return
            
        for symbol in self.symbols:
            self.fast[symbol].Update(self.Time, data[symbol].Close)
            self.slow[symbol].Update(self.Time, data[symbol].Close)
            self.Log(str(symbol) + " : " + str(self.fast[symbol].Current.Value))
            self.Log(str(symbol) + " : " + str(self.slow[symbol].Current.Value))
            holdings = self.Portfolio[symbol].Quantity
            if holdings <= 0:
        
                if self.fast[symbol].Current.Value > self.slow[symbol].Current.Value:
                    self.Log("BUY  >> {0}".format(self.Securities[symbol].Price))
                    self.SetHoldings(symbol, 0.25)
    
            # we only want to liquidate if we're currently long
            # if the fast is less than the slow we'll liquidate our long
            if holdings > 0 and self.fast[symbol].Current.Value < self.slow[symbol].Current.Value:
                self.Log("SELL >> {0}".format(self.Securities[symbol].Price))
                self.Liquidate(symbol)
    
        #self.previous = self.Time