| Overall Statistics |
|
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 |
class MACDTrendAlgorithm(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(1980, 1, 4) #Set Start Date
self.SetEndDate(2018, 1, 1) #Set End Date
self.SetCash(10000) #Set Strategy Cash
## This will add your custom data
self.eurusd = self.AddData(EuroDollar, "D_EURUSD", Resolution.Daily).Symbol
## This will add QC Forex data
self.AddForex('EURUSD', Resolution.Daily)
self.UniverseSettings.Leverage = 50
## Make indicators generic and not attached to a particular symbol
## This will require manual update, but will allowseamless transition once
## QC data is available
self.sma_actual = SimpleMovingAverage(2)
self.sma = SimpleMovingAverage(100)
self.psar = ParabolicStopAndReverse(0.04,0.04,0.4)
self.rsi = RelativeStrengthIndex(100, MovingAverageType.Simple)
self.previous = datetime.min
## Get historical data to warm-up indicators
history = self.History(self.eurusd, 100, Resolution.Daily)
for tuple in history.itertuples():
self.sma_actual.Update(tuple.Index[1], tuple.close)
self.sma.Update(tuple.Index[1], tuple.close)
self.psar.Update(QuoteBar(tuple.Index[1], self.eurusd, Bar(tuple.open, tuple.high, tuple.low, tuple.close), 0,
Bar(tuple.open, tuple.high, tuple.low, tuple.close), 0))
self.rsi.Update(tuple.Index[1], tuple.close)
def OnData(self, data):
self.Log(f'{data.Time} >> {[x.Value for x in data.Keys]}')
## Check to see which ticker is present and select which
## QuoteBar you want to use
bar = None
if data.ContainsKey('D_EURUSD') and data.ContainsKey('EURUSD'):
bar = data['EURUSD']
elif data.ContainsKey('D_EURUSD') and not data.ContainsKey('EURUSD'):
bar = data['D_EURUSD']
elif data.ContainsKey('EURUSD') and not data.ContainsKey('EURUSD'):
bar = data['EURUSD']
## Do things here
## Be sure to update indicators
if bar is not None:
self.UpdateIndicators(bar)
def UpdateIndicators(self, bar):
self.sma_actual.Update(bar.EndTime, bar.Close)
self.sma.Update(bar.EndTime, bar.Close)
self.psar.Update(QuoteBar(bar.EndTime, self.eurusd, Bar(bar.Open, bar.High, bar.Low, bar.Close), 0,
Bar(bar.Open, bar.High, bar.Low, bar.Close), 0))
self.rsi.Update(bar.EndTime, bar.Close)
class EuroDollar(PythonData):
'''EURUSD Custom Data Class'''
def GetSource(self, config, date, isLiveMode):
return SubscriptionDataSource("https://www.dropbox.com/s/6q49hksqtz48sy9/EURUSD1440.csv?dl=1", SubscriptionTransportMedium.RemoteFile)
def Reader(self, config, line, date, isLiveMode):
if not (line.strip() and line[0].isdigit()): return None
# New Nifty object
currency = EuroDollar()
currency.Symbol = config.Symbol
try:
# Example File Format:
# Date, Open High Low Close Volume Turnover
# 2011-09-13 7792.9 7799.9 7722.65 7748.7 116534670 6107.78
data = line.split(',')
currency.Time = datetime.strptime(data[0], "%Y.%m.%d")
currency.Value = data[5]
currency["Open"] = float(data[2])
currency["High"] = float(data[3])
currency["Low"] = float(data[4])
currency["Close"] = float(data[5])
except ValueError:
# Do nothing
return None
return currency