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 QuantConnect.Brokerages import *

class BasicTemplateAlgorithm(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.'''
        self.total_cash = 20000
        self.SetStartDate(2017, 1, 3)  # Set Start Date
        self.SetEndDate(2018, 12, 28)  # Set End Date
        self.SetCash(self.total_cash)  # Set Strategy Cash
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage)
        self.capital_per_trade = 10000  # self.total_cash/2.0
        self.symbol = "GLD"
        # Find more symbols here: http://quantconnect.com/data
        self.AddEquity(self.symbol, Resolution.Minute)
        self.AddEquity("SPY", Resolution.Minute)

        dailyConsolidator = TradeBarConsolidator(TimeSpan.FromDays(1))
        self.SubscriptionManager.AddConsolidator(self.symbol, dailyConsolidator)
        dailyConsolidator.DataConsolidated += self.dailyBarHandler

        dailyConsolidator2 = TradeBarConsolidator(TimeSpan.FromDays(1))
        self.SubscriptionManager.AddConsolidator("SPY", dailyConsolidator2)
        dailyConsolidator2.DataConsolidated += self.dailyBarHandler


    def dailyBarHandler(self, sender, bar):
        currentdatetime = str(self.Time)
        currentdate = currentdatetime[:10]
        currenttime = currentdatetime[11:20]
        self.Debug(str(self.Time) + ":CurrentTime" + str(currenttime) +  ":CurrentBar" + str(bar) +
                   ":bar high" + str(bar.High) + ":bar low" + str(bar.Low))

        # THIS DOES NOT WORK AS BAR OBJECT IS NOT INDEXABLE
        # self.Debug(str(self.Time) + ":CurrentTime" + str(currenttime) +  ":CurrentBar" + str(bar["GLD"]) +
        #            "bar high" + str(bar["GLD"].High))
        # self.Debug(
        #     str(self.Time) + ":CurrentTime" + str(currenttime) + ":CurrentBar" + str(bar["SPY"]) +
        #     "bar high" + str(bar["SPY"].High))
        
    def dailyBarHandler2(self, sender, bar):
        currentdatetime = str(self.Time)
        currentdate = currentdatetime[:10]
        currenttime = currentdatetime[11:20]
        self.Debug(str(self.Time) + ":CurrentTime" + str(currenttime) +  ":CurrentBar" + str(bar) +
                   ":bar high" + str(bar.High) + ":bar low" + str(bar.Low))