| 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, 29)) #Set Start Date
self.SetStartDate(datetime.now() - timedelta(2)) #Set Start Date
#self.SetEndDate(DateTime(2020, 7, 1)) #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("XAUUSD", 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("XAUUSD", gold_thirtyMinuteConsolidator)
self.sto_wti = Stochastic("WTICOUSD", 105, 21, 30)
self.cci_wti = CommodityChannelIndex("WTICOUSD", 200)
#self.sto_naturalgas = Stochastic(self.naturalgas_symbol, 18, 20, 14)
self.sto_gold = Stochastic("XAUUSD", 172, 21, 95)
self.cci_gold = CommodityChannelIndex("XAUUSD", 200)
#self.RegisterIndicator("WTICOUSD", self.sto, thirtyMinuteConsolidator)
#self.RegisterIndicator("WTICOUSD", self.cci, thirtyMinuteConsolidator)
self.PlotIndicator("Indicator-WTICOUSD ", self.sto_wti.StochD)
self.PlotIndicator("Indicator-CommodityChannelIndex_WTI ", self.cci_wti.TypicalPriceAverage)
self.PlotIndicator("Indicator-XAUUSD ", self.sto_gold.StochD)
self.PlotIndicator("Indicator-CommodityChannelIndex_GOLD", self.cci_gold.TypicalPriceAverage)
self.SetWarmup(200*30, Resolution.Minute)
def OnData(self, data):
pass
def ThirtyMinuteQuoteBarHandler(self, sender, consolidated):
self.sto_wti.Update(consolidated)
self.cci_wti.Update(consolidated)
sto_value_wti = self.sto_wti.StochD
cci_value_wti = self.cci_wti.TypicalPriceAverage
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(62) and float(str(sto_value_wti.Current.Value)) < float(67):
self.Notify.Email("martintolmusk@gmail.com", "WTICOUSD Stochastic between 62 and 67", "BUY ALERT for 1,300 pips = Stochastic", str(sto_value_wti.Current.Value))
self.Notify.Email("martintolmusk@gmail.com", "WTICOUSD CCI", "BUY ALERT for 1,300 pips", str(cci_value_wti))
#self.Log(f'{self.Time} STO >> {sto_value_wti.Current.Value}')
#self.Debug(f'{self.Time} STO >> {sto_value_wti.Current.Value}')
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.wti_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_gold.Update(consolidated)
sto_value_gold = self.sto_gold.StochD
cci_value_gold = self.cci_gold.TypicalPriceAverage
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 float(str(sto_value_gold.Current.Value)) > float(59) and float(str(sto_value_gold.Current.Value)) < float(65):
self.Notify.Email("martintolmusk@gmail.com", "GOLD Stochastic between 61 and 64", "BUY ALERT 15 dollars", str(sto_value_gold.Current.Value))
self.Notify.Email("martintolmusk@gmail.com", "GOLD CCI", "BUY ALERT 15 dollars", str(cci_value_gold))
#self.Debug(f'{self.Time} STO >> {sto_value_gold.Current.Value}')
else:
self.Notify.Email("martintolmusk@gmail.com", "Nonsense", "Nonsense email")
#self.Debug(f'{self.Time} >> STO >> {sto_value_gold.Current.Value} ')
self.gold_thirtyMinute = consolidated