Overall Statistics
Total Orders
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Start Equity
1000.00
End Equity
1000
Net Profit
0%
Sharpe Ratio
0
Sortino 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
-1.978
Tracking Error
0.105
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
Portfolio Turnover
0%
# region imports
from AlgorithmImports import *
# endregion

class IchimokuKinkoHyoAlgorithm(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2023, 1, 1)
        self.set_end_date(2024, 3, 31)
        self.set_cash(1000)

        self._symbol = self.add_crypto("BTCUSD", Resolution.DAILY, market = Market.COINBASE).symbol
        self._indicator = self.ichimoku(self._symbol, 9, 26, 26, 52, 26, 26, Resolution.DAILY)

        # Creo un consolidatore di candele da 4 ore
        # self._consolidator = TradeBarConsolidator(timedelta(hours = 4))
        # self._consolidator.data_consolidated += self._consolidation_handler

        # self.subscription_manager.add_consolidator(self._symbol, self._consolidator)

        chart = Chart("IchimokuKinkoHyo")
        chart.add_series(Series("buy", SeriesType.SCATTER, "$", Color.from_known_color(KnownColor.GREEN), ScatterMarkerSymbol.TRIANGLE))
        chart.add_series(Series("sell", SeriesType.SCATTER, "$", Color.from_known_color(KnownColor.RED), ScatterMarkerSymbol.TRIANGLE_DOWN))
        self.add_chart(chart)

    def on_data(self, slice: Slice) -> None:
        if not self._indicator.is_ready:
           return
        
        bar = slice.bars.get(self._symbol)

        close = bar.close
        tenkan_sen = self._indicator.tenkan.current.value
        kijun_sen = self._indicator.kijun.current.value
        senkou_span_a = self._indicator.senkou_a.current.value
        senkou_span_b = self._indicator.senkou_b.current.value
        chikou_span = self._indicator.chikou.current.value

        self.plot("IchimokuKinkoHyo", "price", bar)
        self.plot("IchimokuKinkoHyo", "tenkan", tenkan_sen)
        self.plot("IchimokuKinkoHyo", "kijun", kijun_sen)
        self.plot("IchimokuKinkoHyo", "senkou_a", senkou_span_a)
        self.plot("IchimokuKinkoHyo", "senkou_b", senkou_span_b)
        self.plot("IchimokuKinkoHyo", "chikou", chikou_span)

    '''
    def _consolidation_handler(self, sender: object, consolidated_bar: TradeBar):
        self._indicator.update(consolidated_bar)

        if not self._indicator.is_ready:
            self.debug(str(self.time) + ': indicatore non pronto!')
            return

        close = consolidated_bar.close
        tenkan_sen = self._indicator.tenkan.current.value
        kijun_sen = self._indicator.kijun.current.value
        senkou_span_a = self._indicator.senkou_a.current.value
        senkou_span_b = self._indicator.senkou_b.current.value
        chikou_span = self._indicator.chikou.current.value
        delayed_tenkan_senkou_a = self._indicator.delayed_tenkan_senkou_a.current.value
        delayed_kijun_senkou_a = self._indicator.delayed_kijun_senkou_a.current.value

        # Plot all attributes of self._ichimoku
        self.plot("IchimokuKinkoHyo", "price", consolidated_bar)
        self.plot("IchimokuKinkoHyo", "tenkan", tenkan_sen)
        self.plot("IchimokuKinkoHyo", "kijun", kijun_sen)
        self.plot("IchimokuKinkoHyo", "senkou_a", senkou_span_a)
        self.plot("IchimokuKinkoHyo", "senkou_b", senkou_span_b)
        self.plot("IchimokuKinkoHyo", "chikou", chikou_span)
        self.plot("IchimokuKinkoHyo", "delayed_tenkan_senkou_a", delayed_tenkan_senkou_a)
        self.plot("IchimokuKinkoHyo", "delayed_kijun_senkou_a", delayed_kijun_senkou_a)

        if close > senkou_span_a and chikou_span > senkou_span_a and kijun_sen > tenkan_sen and senkou_span_a > senkou_span_b:
            if not self.portfolio.invested:
                self.set_holdings(self._symbol, 1)
                self.plot("IchimokuKinkoHyo", "buy", close)
        elif self.portfolio.invested:
            self.Liquidate(self._symbol)
            self.plot("IchimokuKinkoHyo", "sell", close)
    '''