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 |
''' ICHIMOKU Cloud for 5 minute time buckets ''' #import a bunch of stuff from clr import AddReference AddReference("QuantConnect.Common") AddReference("QuantConnect.Algorithm") AddReference("QuantConnect.Algorithm.Framework") AddReference("QuantConnect.Indicators") from QuantConnect import * from QuantConnect.Indicators import * from QuantConnect.Algorithm import * from QuantConnect.Algorithm.Framework import * from QuantConnect.Algorithm.Framework.Alphas import * from QuantConnect.Algorithm.Framework.Portfolio import * from QuantConnect.Algorithm.Framework.Risk import * from QuantConnect.Algorithm.Framework.Selection import * from QuantConnect.Data.Consolidators import * from datetime import timedelta import numpy as np from System.Drawing import Color class IchimokuAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 8, 17) # Set Start Date self.SetEndDate(2020, 8, 17) # Set End Date self.SetCash(10000) # Set Strategy Cash # SET THE INSTRUMENTS WE ARE GOING TO USE IN OUR UNIVERSE self.long_symbol = self.AddEquity("SPXL", Resolution.Minute).Symbol # Ichimoku Cloud TenkanPeriod = 9 KijunPeriod = 26 SenkouAPeriod = 26 SenkouBPeriod = 52 SenkouADelay = 26 SenkouBDelay = 26 self.Ichi = self.ICHIMOKU(self.long_symbol, TenkanPeriod, KijunPeriod, SenkouAPeriod, SenkouBPeriod, SenkouADelay, SenkouBDelay) # redefine the indicators so it works on 5 min buckets self.timebucketConsolidator = TradeBarConsolidator(timedelta(minutes = 5)) self.timebucketConsolidator.DataConsolidated += self.OnBarHandler self.SubscriptionManager.AddConsolidator(self.long_symbol, self.timebucketConsolidator) self.RegisterIndicator(self.long_symbol, self.Ichi, self.timebucketConsolidator) # going to use three values for Sentiment: Bullish, Bearish and Neutral # setting default values but these will get re-set during pre-market so not a big deal self.Sentiment = "Neutral" self.CloudTop = 0 self.CloudBottom = 0 # Warmup those indicators self.SetWarmup(SenkouBPeriod) # Add a custom chart to track the SMA cross self.chart = Chart('Trade Chart') self.chart.AddSeries(Series('Price', SeriesType.Line, 0)) self.chart.AddSeries(Series('Sentiment', SeriesType.Line, 1)) self.AddChart(self.chart) def OnData(self, data): if self.IsWarmingUp: return def OnBarHandler(self, sender, bar): if self.IsWarmingUp: return ''' This is the IICHIMOKU CLOUD evaluator. This block decides whether self.Sentiment gets set to Bullish, Bearish or Neutral. Maybe move it later into its own function ''' self.CloudTop = max(self.Ichi.SenkouA.Current.Value, self.Ichi.SenkouB.Current.Value) self.CloudBottom = min(self.Ichi.SenkouA.Current.Value, self.Ichi.SenkouB.Current.Value) if (self.Sentiment == "Bullish" or self.Sentiment == "Bearish") and ((self.Ichi.Chikou.Current.Value < self.CloudTop) and (self.Ichi.Chikou.Current.Value > self.CloudBottom)): self.Sentiment = "Neutral" self.Debug("Sentiment turning Neutral") elif (self.Sentiment == "Bearish" or self.Sentiment == "Neutral") and (self.Ichi.Chikou.Current.Value > self.CloudTop): self.Sentiment = "Bullish" self.Debug("Sentiment turning Bullish") elif (self.Sentiment== "Bullish" or self.Sentiment == "Neutral") and (self.Ichi.Chikou.Current.Value < self.CloudBottom): self.Sentiment = "Bearish" self.Debug("Sentiment turning Bearish") ''' end of the ICHIMOKU CLOUD logic ''' if self.Sentiment == "Neutral": SentimentNumber = 1 if self.Sentiment == "Bullish": SentimentNumber = 2 if self.Sentiment == "Bearish": SentimentNumber = 0 self.Plot('Trade Chart', 'Price', self.Securities[self.long_symbol].Price) self.Plot('Trade Chart', 'Sentiment', SentimentNumber)