Overall Statistics
Total Trades
73432
Average Win
0.00%
Average Loss
0.00%
Compounding Annual Return
-7.740%
Drawdown
9.600%
Expectancy
45.959
Net Profit
-1.744%
Sharpe Ratio
-0.371
Loss Rate
3%
Win Rate
97%
Profit-Loss Ratio
47.43
Alpha
0.001
Beta
-1.106
Annual Standard Deviation
0.146
Annual Variance
0.021
Information Ratio
-0.589
Tracking Error
0.176
Treynor Ratio
0.049
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.
		# cash = 7000 * 50 leverage = 350,000
		self.SetCash(7180.98);

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

		# Specify the OANDA Brokerage: This 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")
		
		#5 day mean
    #*****************THIS IS THE MEAN YOU CAN CHANGE THE 5 ******************
		self.sma = self.SMA("EURUSD", 50, Resolution.Daily)
		self.SetWarmup(timedelta(50))


	def OnData(self, slice):
		if self.Portfolio["EURUSD"].Quantity > 1:
			return
		price = slice["EURUSD"].Value
			
		difference = self.sma.Current.Value - price
			
		# order amount = 3% cash / current price
		# need to figure out how to get the current cash 
		amount = (self.Portfolio.TotalPortfolioValue * decimal.Decimal(0.0003)) / price
		
		if difference > decimal.Decimal(0.001):
			# Buy shares of EURUSD
			self.Buy("EURUSD", amount)
			
 
			# Place a Take Profit Limit order for .000005% gain  
			self.LimitOrder("EURUSD", -amount, price * decimal.Decimal(1.000005))
		
    
			# Place a Stop Loss (Stop Market) order for a .000000003% loss
			self.StopMarketOrder("EURUSD", -amount, price * decimal.Decimal(0.999999997))
				
					
					
		if difference < decimal.Decimal(-0.001):
			# Sell 1000 shares of EURUSD
			self.Sell("EURUSD", amount)
			
    
			#Place a Take Profit Limit order for .0005% gain
			self.LimitOrder("EURUSD", -amount, price * decimal.Decimal(1.000005))
			
      
			# Place a Stop Loss (Stop Market) order for a .0000003% loss
			self.StopMarketOrder("EURUSD", -amount, price * decimal.Decimal(0.999999997))
			
		
		
	
	def OnOrderEvent(self, orderEvent):
		if orderEvent.Status == OrderStatus.Submitted or orderEvent.Status == OrderStatus.Canceled:
			return