| Overall Statistics |
|
Total Trades 3 Average Win 0.43% Average Loss -2.24% Compounding Annual Return -82.177% Drawdown 5.100% Expectancy -0.404 Net Profit -3.710% Sharpe Ratio -8.936 Loss Rate 50% Win Rate 50% Profit-Loss Ratio 0.19 Alpha -1.423 Beta -0.425 Annual Standard Deviation 0.118 Annual Variance 0.014 Information Ratio -0.624 Tracking Error 0.276 Treynor Ratio 2.471 Total Fees $0.00 |
#
import clr
clr.AddReference("System")
clr.AddReference("QuantConnect.Algorithm")
clr.AddReference("QuantConnect.Indicators")
clr.AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
class MovingAverageCrossAlgorithm(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(2019, 8, 1) #Set Start Date
self.SetEndDate(2019, 8, 8) #Set End Date
self.SetCash(5000) #Set Strategy Cash
# Find more symbols here: http://quantconnect.com/data
self.AddForex("GBPAUD", Resolution.Minute, Market.Oanda)
self.eurusd = self.AddForex("GBPAUD", Resolution.Minute).Symbol
self.numberOfBars = 5
def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''
# a couple things to notice in this method:
# 1. We never need to 'update' our indicators with the data, the engine takes care of this for us
# 2. We can use indicators directly in math expressions
# 3. We can easily plot many indicators at the same time
# define a small tolerance on our checks to avoid bouncing
tolerance = 0.00015
holdings = self.Portfolio["GBPAUD"].Quantity
self.price = data["GBPAUD"].Price
##############################################
self.df = self.History(self.eurusd, self.numberOfBars, Resolution.Minute)
if not self.df.empty:
self.eurusd_quotebars = self.df.loc["GBPAUD"]
self.high = self.eurusd_quotebars["high"]
self.low = self.eurusd_quotebars["low"]
self.highestHigh = max(self.high)
self.lowestLow = min(self.low)
###############################################
if holdings == 0:
if self.price >= self.highestHigh * (1 + tolerance):
self.Buy("GBPAUD", 5000)
if self.price <= self.lowestLow * (1 - tolerance):
self.Sell("GBPAUD", 5000)
else:
if self.price >= self.highestHigh * (1 + tolerance) and holdings < 0:
self.Buy("GBPAUD", 10000)
if self.price <= self.lowestLow * (1 - tolerance) and holdings > 0:
self.Sell("GBPAUD", 10000)