| 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 Probabilistic 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 |
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Data.Consolidators import *
from datetime import timedelta
from QuantConnect.Indicators import CommodityChannelIndex, Stochastic
from QuantConnect.Data import Slice
class NotebookProject(QCAlgorithm):
wti_thirtyMinute = None
naturalgas_thirtyMinute = None
gold_thirtyMinute = None
wticcousd_symbol = "WTICOUSD"
naturalgas_symbol = "NATGASUSD"
gold_symbol = "XAUUSD"
def Initialize(self):
self.SetTimeZone("Europe/London")
self.SetBrokerageModel(BrokerageName.OandaBrokerage)
#self.SetStartDate(DateTime(2020, 6, 18)) #Set Start Date
self.SetStartDate(datetime.now() - timedelta(1)) #Set Start Date
#self.SetEndDate(DateTime(2020, 6, 19)) #Set End Date
self.SetEndDate(datetime.now()) #Set End Date
self.wticousd = self.AddCfd("WTICOUSD", Resolution.Minute, Market.Oanda)
#self.natgasusd = self.AddCfd(self.naturalgas_symbol, Resolution.Minute, Market.Oanda)
#self.gold = self.AddCfd(self.gold_symbol, Resolution.Minute, Market.Oanda)
self.wticousd.SetDataNormalizationMode(DataNormalizationMode.Raw)
#self.natgasusd.SetDataNormalizationMode(DataNormalizationMode.Raw)
#self.gold.SetDataNormalizationMode(DataNormalizationMode.Raw)
#WEST TEXAS
thirtyMinuteConsolidator = QuoteBarConsolidator(timedelta(minutes=30))
thirtyMinuteConsolidator.DataConsolidated += self.ThirtyMinuteQuoteBarHandler
self.SubscriptionManager.AddConsolidator("WTICOUSD", thirtyMinuteConsolidator)
#NATURAL GAS
#naturalgas_thirtyMinuteConsolidator = QuoteBarConsolidator(timedelta(minutes=30))
#naturalgas_thirtyMinuteConsolidator.DataConsolidated += self.naturalgas_ThirtyMinuteQuoteBarHandler
#self.SubscriptionManager.AddConsolidator(self.naturalgas_symbol, naturalgas_thirtyMinuteConsolidator)
#GOLD
#gold_thirtyMinuteConsolidator = QuoteBarConsolidator(timedelta(minutes=30))
#gold_thirtyMinuteConsolidator.DataConsolidated += self.gold_ThirtyMinuteQuoteBarHandler
#self.SubscriptionManager.AddConsolidator(self.naturalgas_symbol, gold_thirtyMinuteConsolidator)
self.sto_wti = Stochastic("WTICOUSD", 105, 21, 30) #18, 21, 41
#self.sto_naturalgas = Stochastic(self.naturalgas_symbol, 18, 20, 14)
#self.sto_gold = Stochastic(self.gold_symbol, 172, 21, 95)
#self.cci = CommodityChannelIndex(self.wticcousd_symbol, 200)
#self.RegisterIndicator("WTICOUSD", self.sto, thirtyMinuteConsolidator)
#self.RegisterIndicator("WTICOUSD", self.cci, thirtyMinuteConsolidator)
self.SetWarmup(200*30, Resolution.Minute)
def OnData(self, data):
pass
def ThirtyMinuteQuoteBarHandler(self, sender, consolidated):
self.sto_wti.Update(consolidated)
sto_value_wti = self.sto_wti.StochD
if self.IsWarmingUp:
return
#TESTING
#if (str(consolidated.Symbol) == "WTICOUSD" and (self.Time.month == 6 and self.Time.day == 18 and self.Time.hour == 9 and self.Time.minute == 0)):
#self.Debug(f'{self.Time} >> STO >> {sto_value_wti} CCI >> {cci_value}')
#self.Notify.Email("martintolmusk@gmail.com", "WTICOUSD Stochastic above 60", str(sto_value_wti))
# self.Debug(f'{self.Time} >> STO >> {sto_value_wti}')
#LIVE
if float(str(sto_value_wti.Current.Value)) >= float(71):
self.Notify.Email("martintolmusk@gmail.com", "WTICOUSD Stochastic above 71", "Stochastic above")
#self.Log(f'{self.Time} STO >> {sto_value_wti.Current.Value}')
#self.Debug(f'{self.Time} STO >> {sto_value_wti}')
else:
self.Notify.Email("martintolmusk@gmail.com", "Nonsense", "Nonsense email")
#self.Log(f'{self.Time} >> STO >> {sto_value_wti.Current.Value} ')
#self.Debug(f'{self.Time} >> STO >> {sto_value_wti.Current.Value} ')
#self.Debug(f'{self.Time} >> STO >> {consolidated.Symbol}')
self.thirtyMinute = consolidated
#def naturalgas_ThirtyMinuteQuoteBarHandler(self, sender, consolidated):
#self.sto_naturalgas.Update(consolidated)
#self.cci.Update(consolidated)
#sto_value_natgas = self.sto_naturalgas.StochD
#cci_value = self.cci.Current.Value
#if self.IsWarmingUp:
# return
#TESTING
#if self.Time.month == 6 and self.Time.day == 18 and self.Time.hour >= 7 and self.Time.hour <= 11:
#self.Debug(f'{self.Time} >> STO >> {sto_value_natgas} CCI >> {cci_value}')
#self.Notify.Email("martintolmusk@gmail.com", "WTICOUSD Stochastic above 60", str(sto_value_natgas))
#self.Debug(f'{self.Time} >> STO >> {sto_value_natgas}')
#LIVE
# if consolidated.Symbol == self.naturalgas_symbol and float(str(sto_value_natgas)) >= 62 and float(str(sto_value_natgas)) <= 66:
# self.Notify.Email("martintolmusk@gmail.com", "Natural Gas Stochastic above 62", str(sto_value_natgas))
# self.naturalgas_thirtyMinute = consolidated
#def gold_ThirtyMinuteQuoteBarHandler(self, sender, consolidated):
#self.sto_gold.Update(consolidated)
#self.cci.Update(consolidated)
#sto_value_gold = self.sto_gold.StochD
#cci_value = self.cci.Current.Value
#if self.IsWarmingUp:
# return
#TESTING
#if self.Time.month == 6 and self.Time.day == 18 and self.Time.hour >= 7 and self.Time.hour <= 11:
#self.Debug(f'{self.Time} >> STO >> {sto_value_gold} CCI >> {cci_value}')
#self.Notify.Email("martintolmusk@gmail.com", "WTICOUSD Stochastic above 60", str(sto_value_gold))
#self.Debug(f'{self.Time} >> STO >> {sto_value_gold}')
#LIVE
#if consolidated.Symbol == self.naturalgas_symbol and float(str(sto_value_gold)) >= 59 and float(str(sto_value_gold)) <= 61:
# self.Notify.Email("martintolmusk@gmail.com", "Gold Stochastic BUY between 59 and 61", str(sto_value_gold))
#if consolidated.Symbol == self.naturalgas_symbol and float(str(sto_value_gold)) <= 68 and float(str(sto_value_gold)) >= 66:
# self.Notify.Email("martintolmusk@gmail.com", "Gold Stochastic SELL between 66 and 68 - Look to sell", str(sto_value_gold))
#self.gold_thirtyMinute = consolidated