Overall Statistics
from clr import AddReference

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
from QuantConnect.Python import PythonQuandl

import math
import pandas as pd
import numpy as np
from decimal import *

class DailyAlgorithm(QCAlgorithm):

    def Initialize(self):
        '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''

        # Context
        self.stock = 'SPY'
        self.SetStartDate(2018,4,1)  #Set Start Date
        self.SetEndDate(2018,7,1)    #Set End Date
        self.SetCash(10000)          #Set Strategy Cash
        self.AddEquity('SPY', Resolution.Daily)

    def OnData(self, slice):
        self.close_price = self.Securities[self.stock].Price
        self.open_price = self.Securities[self.stock].Open
        self.high_price = self.Securities[self.stock].High
        self.low_price = self.Securities[self.stock].Low
        daily_perf = (self.close_price - self.open_price) / self.open_price
        if daily_perf < 0.003:
            self.MarketOrder(self.stock, 1)
        elif daily_perf > 0.003:
            self.MarketOrder(self.stock, -1)

        self.Plot('Stock Plot', 'close', self.close_price)
        self.Plot('Stock Plot', 'open', self.open_price)
        self.Plot('Stock Plot', 'high', self.high_price)
        self.Plot('Stock Plot', 'low', self.low_price)