Overall Statistics
Total Trades
23
Average Win
1.09%
Average Loss
-0.23%
Compounding Annual Return
-1.177%
Drawdown
2.300%
Expectancy
-0.475
Net Profit
-1.344%
Sharpe Ratio
-0.771
Loss Rate
91%
Win Rate
9%
Profit-Loss Ratio
4.78
Alpha
-0.008
Beta
0.115
Annual Standard Deviation
0.012
Annual Variance
0
Information Ratio
0.101
Tracking Error
0.068
Treynor Ratio
-0.082
Total Fees
$0.00
#
#   Trading Orders Algorithm
#
#   Ref: https://www.quantconnect.com/docs#Trading-and-Orders
#        https://www.quantconnect.com/docs#Charting
#
import decimal
from datetime import timedelta 

class TradingOrdersAlgorithm(QCAlgorithm):

	def Initialize(self):
		# Set cash allocation for backtest
		# In live trading this is ignored and your real account is used.
		self.SetCash(5000);

		# Start and end dates for the backtest.
		# These are ignored in live trading.
		self.SetStartDate(2016,1,1)
		self.SetEndDate(2017,1,1)

		# Specify the OANDA Brokerage: This gives lets us know the fee models & data.
		self.SetBrokerageModel(BrokerageName.OandaBrokerage)

		# Add assets you'd like to see
		self.AddForex("EURUSD", Resolution.Minute)

		self.SetBenchmark("EURUSD")
		
		self.sma = self.SMA("EURUSD", 30, Resolution.Daily)
		self.SetWarmup(timedelta(50))


	def OnData(self, slice):
		if self.Portfolio["EURUSD"].IsLong:
			return

		price = slice["EURUSD"].Value

		if price > self.sma.Current.Value:
			# Buy 1000 shares of EURUSD
			self.Buy("EURUSD", 1000)
			
			# Place a Take Profit Limit order for 5% gain  
			self.LimitOrder("EURUSD", -1000, price * decimal.Decimal(1.05))

			# Place a Stop Loss (Stop Market) order for a 1% loss
			self.StopMarketOrder("EURUSD", -1000, price * decimal.Decimal(0.99))


	def OnOrderEvent(self, orderEvent):
		if orderEvent.Status == OrderStatus.Submitted or orderEvent.Status == OrderStatus.Canceled:
			return

		if orderEvent.FillQuantity < 0:
			self.Transactions.CancelOpenOrders("EURUSD")
		else:
			self.Log("Buy EURUSD at {0}. SMA30d: {1}".format(orderEvent.FillPrice, self.sma.Current.Value))