| Overall Statistics |
|
Total Trades 131 Average Win 0.17% Average Loss -0.12% Compounding Annual Return -28.899% Drawdown 6.200% Expectancy -0.086 Net Profit -1.115% Sharpe Ratio -1.695 Loss Rate 63% Win Rate 37% Profit-Loss Ratio 1.47 Alpha -0.062 Beta 0.163 Annual Standard Deviation 0.124 Annual Variance 0.015 Information Ratio 3.901 Tracking Error 0.178 Treynor Ratio -1.287 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, 7, 28) #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.'''
holdings = self.Portfolio["GBPAUD"].Quantity
self.price = data["GBPAUD"].Price
##############################################
self.df = self.History(self.eurusd, self.numberOfBars)
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:
self.Buy("GBPAUD", 5000)
if self.price <= self.lowestLow:
self.Sell("GBPAUD", 5000)
else:
if self.price >= self.highestHigh and holdings < 0:
self.Buy("GBPAUD", 10000)
if self.price <= self.lowestLow and holdings > 0:
self.Sell("GBPAUD", 10000)