Overall Statistics
Total Trades
225
Average Win
0.65%
Average Loss
-0.50%
Compounding Annual Return
15.595%
Drawdown
6.400%
Expectancy
0.286
Net Profit
36.410%
Sharpe Ratio
1.321
Loss Rate
44%
Win Rate
56%
Profit-Loss Ratio
1.31
Alpha
0.106
Beta
-0.035
Annual Standard Deviation
0.079
Annual Variance
0.006
Information Ratio
0.319
Tracking Error
0.139
Treynor Ratio
-3.01
Total Fees
$0.00
#
#   QuantConnect Basic Template:
#	Fundamentals to using a QuantConnect algorithm.
#
#	You can view the QCAlgorithm base class on Github: 
#	https://github.com/QuantConnect/Lean/tree/master/Algorithm
#

import numpy as np
import statsmodels.api as sm
import pandas as pd
import math

class ForexLive(QCAlgorithm):

	def Initialize(self):
		# Set the cash we'd like to use for our backtest
		# This is ignored in live trading 
		self.SetCash(100000)
		
		# Start and end dates for the backtest.
		# These are ignored in live trading.
		self.SetStartDate(2015,7,1)
		self.SetEndDate(2017,8,20)
		
		forex = "EURUSD"
		
		# Add assets you'd like to see
		self.aud = self.AddForex(forex, Resolution.Hour).Symbol
		self.bb = self.BB(forex, 30, 2, MovingAverageType.Exponential, Resolution.Hour)
		self.rsi = self.RSI(forex,14, MovingAverageType.Exponential, Resolution.Hour)
		self.ao = self.AROON(forex,14,14,Resolution.Hour)
		
		self.bbupCount = 0
		self.bblowCount = 0
		self.rsi70Count = 0
		self.rsi30Count = 0
		self.aoupCount = 0
		self.aolowCount = 0

		
	def OnData(self, slice):
		if not self.bb.IsReady: return
		if not self.rsi.IsReady: return
		if not self.ao.IsReady: return

		close = slice[self.aud].Close
	
		bbup = self.bb.UpperBand.Current.Value < close
		bblow = self.bb.LowerBand.Current.Value > close
		rsi70 = self.rsi.Current.Value > 70
		rsi30 = self.rsi.Current.Value < 30
		aoup = self.ao.Current.Value > 50
		aolow = self.ao.Current.Value < -50

		
		self.bbupCount += bbup
		self.bblowCount += bblow
		self.rsi70Count += rsi70
		self.rsi30Count += rsi30
		self.aoupCount += aoup
		self.aolowCount += aolow

		if (bbup and self.bbupCount>1) and ((rsi70 and self.rsi70Count>1) or aoup) :
			self.SetHoldings(self.aud,-1)
			self.bbupCount = self.bblowCount = self.rsi70Count = self.rsi30Count = self.aoupCount = self.aolowCount = 0
		elif (bblow and self.bblowCount>1) or (rsi30 and self.rsi30Count>1 and aolow):
			self.SetHoldings(self.aud,1)
			self.bbupCount = self.bblowCount = self.rsi70Count = self.rsi30Count = self.aoupCount = self.aolowCount = 0