Overall Statistics Total Trades2393Average Win0.88%Average Loss-0.74%Compounding Annual Return-6.385%Drawdown65.700%Expectancy-0.102Net Profit-59.431%Sharpe Ratio-0.37Loss Rate59%Win Rate41%Profit-Loss Ratio1.20Alpha-0.06Beta0.241Annual Standard Deviation0.148Annual Variance0.022Information Ratio-0.505Tracking Error0.148Treynor Ratio-0.228Total Fees\$4585.58
```from datetime import datetime
import decimal
import numpy as np

class DualThrustAlgorithm(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(2004,1,1)
self.SetEndDate(2017,8,30)
self.SetCash(100000)
self.syl = equity.Symbol

# schedule an event to fire every trading day for a security
# the time rule here tells it to fire when market open

self.Schedule.On(self.DateRules.EveryDay(self.syl),self.TimeRules.AfterMarketOpen(self.syl,0),Action(self.SetSignal))
self.selltrig = None
self.currentopen = None

def SetSignal(self):
history = self.History(4, Resolution.Daily)

k1 = 0.5
k2 = 0.5
self.high = []
self.low = []
self.close = []
for slice in history:
bar = slice[self.syl]
self.high.append(bar.High)
self.low.append(bar.Low)
self.close.append(bar.Close)
# Pull the open price on each trading day
self.currentopen = self.Portfolio[self.syl].Price

HH, HC, LC, LL = max(self.high), max(self.close), min(self.close), min(self.low)
if (HH - LC) >= (HC - LL):
signalrange = HH - LC
else:
signalrange = HC - LL

self.selltrig = self.currentopen - decimal.Decimal(k2) * signalrange
self.buytrig = self.currentopen + decimal.Decimal(k1) * signalrange

def OnData(self,data):

'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''

if not data.ContainsKey(self.syl) or self.syl not in data.Keys:
return

holdings = self.Portfolio[self.syl].Quantity

self.Log('Holdings: ' + str(holdings))
if holdings >= 0:
self.SetHoldings(self.syl, 0.8)
else:
self.Liquidate(self.syl)
self.SetHoldings(self.syl, 0.8)

elif self.Portfolio[self.syl].Price < self.selltrig:
if holdings >= 0:
self.Liquidate(self.syl)
self.SetHoldings(self.syl, -0.8)
else:
self.SetHoldings(self.syl, -0.8)