Overall Statistics Total Trades 15 Average Win 0.82% Average Loss -0.56% Compounding Annual Return 12.635% Drawdown 4.100% Expectancy 0.639 Net Profit 2.564% Sharpe Ratio 1.163 Loss Rate 33% Win Rate 67% Profit-Loss Ratio 1.46 Alpha 0.071 Beta 0.775 Annual Standard Deviation 0.106 Annual Variance 0.011 Information Ratio 0.829 Tracking Error 0.068 Treynor Ratio 0.16 Total Fees \$42.89
```from QuantConnect.Data.Market import TradeBar
from datetime import timedelta
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
import decimal as d

class MyAlgorithm(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.SetStartDate(2015,05,1) #Set Start Date
self.SetEndDate(2015,07,19)
self.SetCash(100000) #Set Strategy Cash

consolidator.DataConsolidated += self.OnDailyData

consolidatorm.DataConsolidated += self.OnMinuteData

self.Schedule.On(self.DateRules.EveryDay(),
self.TimeRules.At(9, 31),
Action(self.One))

self.Schedule.On(self.DateRules.EveryDay(),
self.TimeRules.At(15, 59, 56),
Action(self.End))

# Add daily bar to daily rolling window
def OnDailyData(self, sender, bar):

def OnMinuteData(self, sender, bar):

def One(self):
openOrders = self.Transactions.GetOpenOrders()
currBar = self.window[0].Close
yesterdayc = self.daily[1].Close
minuteBarC = self.minute[1].Close
minuteBar0 = self.minute[1].Open
self.Debug(str(self.Securities["SPY"].Price) + "," + str(currBar)+str(minuteBar0)+str(minuteBarC))
if not self.Portfolio.Invested and currBar<yesterdayc and minuteBar0<minuteBarC and "SPY" not in openOrders:
self.SetHoldings("SPY", 1)
if not self.Portfolio.Invested and currBar>yesterdayc and minuteBar0>minuteBarC:
self.SetHoldings("SPY", -1)

def End(self):
if self.Portfolio["SPY"].Quantity < 0:
self.SetHoldings("SPY", 0)

# Add second bar to window rolling window
def OnData(self, data):
if data["SPY"] is None:
return