Overall Statistics
Total Trades
87
Average Win
0.73%
Average Loss
-1.16%
Compounding Annual Return
-17.102%
Drawdown
18.400%
Expectancy
-0.285
Net Profit
-17.781%
Sharpe Ratio
-1.504
Loss Rate
56%
Win Rate
44%
Profit-Loss Ratio
0.63
Alpha
-0.137
Beta
0.128
Annual Standard Deviation
0.085
Annual Variance
0.007
Information Ratio
-1.632
Tracking Error
0.126
Treynor Ratio
-0.992
Total Fees
$0.00
import numpy as np
import math

class BasicTemplateAlgorithm(QCAlgorithm):
	
	def __init__(self):
		self.stoploss = 0.02
		self.take_profit = 0.006


	def Initialize(self):

		self.SetCash(25000)
		self.SetStartDate(2016,1,1)
		self.SetEndDate(2017,1,15)
		
		self.gbp = self.AddForex("GBPUSD", Resolution.Daily).Symbol
		history = self.History(7,Resolution.Daily)
		self.historical = []
		for slice in history:
			bar = slice[self.gbp]
			self.historical.append(float(bar.Close))
			
		
		self.mid = (self.historical[0] + self.historical[-1])/2
			
			
		self.Schedule.On(self.DateRules.Every(DayOfWeek.Sunday,DayOfWeek.Sunday), self.TimeRules.At(12, 0), Action(self.action))

	def OnData(self, slice):
		self.historical.append(float(slice[self.gbp].Close))
		self.historical = self.historical[-7:]
		self.data = slice
		price = float(slice[self.gbp].Close)
		if self.Portfolio[self.gbp].Quantity > 0:
			if price/self.long_price -1 >= self.take_profit:
				self.Liquidate()
			elif price/self.long_price <= 1-self.stoploss:
				self.Liquidate()
			else:
				return
		elif self.Portfolio[self.gbp].Quantity < 0:
			if price/self.long_price -1 >= self.stoploss:
				self.Liquidate()
			elif price/self.long_price <= 1-self.take_profit:
				self.Liquidate()
			else:
				return
		else:
			return
				
	def action(self):
		self.mid = (self.historical[0] + self.historical[-1])/2
		price = float(self.data[self.gbp].Close)
		quantity = math.floor(float(self.Portfolio.Cash)/price)
		if price > self.mid:
			self.LimitOrder(self.gbp, -quantity, price)
			self.short_price = price
		elif price< self.mid:
			self.LimitOrder(self.gbp, quantity, price)
			self.long_price = price
			
		
		
	
	# def OnOrderEvent(self,event):
		
	# 	if event.Status not in (2,3):
	# 		return
		
	# 	if (self.profit_order) == None or (self.loss_order) == None:
	# 		return
		
	# 	filled = event.OrderId
		
	# 	if self.profit_order == filled:
	# 		self.loss_order.Cancel()
	# 		self.Log(str('loss order canceled'))

	# 	elif self.loss_order.OrderId == filled:
	# 		self.profit_order.Cancel()
	# 		self.Log(str('profit order canceled'))
			
	# 	else:
	# 		return