| Overall Statistics |
|
Total Trades 131 Average Win 0.17% Average Loss -0.11% Compounding Annual Return -21.361% Drawdown 5.400% Expectancy -0.069 Net Profit -0.787% Sharpe Ratio -1.32 Loss Rate 63% Win Rate 37% Profit-Loss Ratio 1.54 Alpha -0.017 Beta 0.144 Annual Standard Deviation 0.112 Annual Variance 0.012 Information Ratio 4.393 Tracking Error 0.172 Treynor Ratio -1.024 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.positionSize = self.Portfolio.TotalPortfolioValue
##############################################
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", self.positionSize)
if self.price <= self.lowestLow:
self.Sell("GBPAUD", self.positionSize)
else:
if self.price >= self.highestHigh and holdings < 0:
self.Buy("GBPAUD", self.positionSize * 2)
if self.price <= self.lowestLow and holdings > 0:
self.Sell("GBPAUD", self.positionSize * 2)