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.401
Tracking Error
0.09
Treynor Ratio
0
Total Fees
₹0.00
Estimated Strategy Capacity
₹0
Lowest Capacity Asset
from AlgorithmImports import *
from datetime import timedelta, datetime

class Nifty(PythonData):
    '''NIFTY Custom Data Class'''
    def GetSource(self, config, date, isLiveMode):

        # # Daily data with one shift down
        # return SubscriptionDataSource("https://docs.google.com/spreadsheets/d/e/2PACX-1vQlc_VXbDlxnimhv2g1XJ0NMNNn7nhC-urAwN9hkuMil6I30ER0REJdlCspvLSAuWJ4Rm5YfazFOIZ5/pub?gid=158304737&single=true&output=csv", SubscriptionTransportMedium.RemoteFile)
        
        # # Daily data 
        # return SubscriptionDataSource("https://docs.google.com/spreadsheets/d/e/2PACX-1vQbXiiCjnSADlGe1AqvQ7PDfmOWoHZVh2U9frGAwHcqnemVcVTxOInxD91QHCl_lQTMNHQgISjH9vqJ/pub?gid=158304737&single=true&output=csv", SubscriptionTransportMedium.RemoteFile)
        
        # # Minute data of CUSTOM_EQUITY_SYMBOL stock incorrect data
        # return SubscriptionDataSource("https://docs.google.com/spreadsheets/d/e/2PACX-1vTQS1Nivrmjf7WKZjW8qp2y1kSysdwAcCAX7NnfEEjbQbgYDdfWycoHOFn01RPXG0atykDBJXFmIjQ5/pub?gid=694106200&single=true&output=csv", SubscriptionTransportMedium.RemoteFile)
        
        # Minute data of CUSTOM_EQUITY_SYMBOL stock correct data
        return SubscriptionDataSource("https://docs.google.com/spreadsheets/d/e/2PACX-1vTMuqf8BArhREgnWyUPkCiPNZkhgO3ooDUtXRki7Q4FdwDMDZc7lnxKLJe2prrdgWuHH9sN5oYKIrhy/pub?gid=762702799&single=true&output=csv", SubscriptionTransportMedium.RemoteFile)
        # Daily data of CUSTOM_EQUITY_SYMBOL stock
        # return SubscriptionDataSource("https://docs.google.com/spreadsheets/d/e/2PACX-1vQPfRm1MsaFwsHCe3JlvbFoMDVBlJucaEHClGeNpQ0v6D1QRqQUKewhTYmSP7uxFBhYuntbFbLz4q6U/pub?gid=1447268042&single=true&output=csv", SubscriptionTransportMedium.RemoteFile)
        # return SubscriptionDataSource("https://docs.google.com/spreadsheets/d/e/2PACX-1vSxvw0rd-Kg4ilZOUOYYOwXnXH_lLitQTIuCiVvvDS64Yf_SxERd66fjQ_rjGiWMsRfQVLl0xG9GI7J/pub?gid=59450821&single=true&output=csv", SubscriptionTransportMedium.RemoteFile)
        # return SubscriptionDataSource("https://www.dropbox.com/s/rsmg44jr6wexn2h/CNXNIFTY.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
        index = Nifty()
        index.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(',')
            # index.Time = datetime.strptime(data[0], "%Y-%m-%d")
            index.Time = datetime.strptime(data[0], "%Y-%m-%d %H:%M:%S")

            index.EndTime = index.Time + timedelta(minutes=1)
            index.Value = data[4]
            index["Open"] = float(data[1])
            index["High"] = float(data[2])
            index["Low"] = float(data[3])
            index["Close"] = float(data[4])


        except ValueError:
                # Do nothing
                return None
        return index



class Tryindicatorwithconsolidator(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2021,8,15)
        self.SetEndDate(2021,9,24)
        self.SetAccountCurrency("INR")
        self.SetTimeZone(TimeZones.Kolkata)
        self.SetCash(1000000000)
        # self.btc = self.AddEquity("BAJFINANCE", Resolution.Minute, Market.India).Symbol
        self.btc = self.AddData(Nifty, "CUSTOM_EQUITY_SYMBOL", Resolution.Minute).Symbol
        self.SetBrokerageModel(BrokerageName.Zerodha, AccountType.Cash)
        self.Consolidate("CUSTOM_EQUITY_SYMBOL", timedelta(minutes=15), self.FifteenMinuteBarHandler)        
        self.SetWarmUp(3*24*60, Resolution.Minute)
        # self.aroon = AroonOscillator(25, 25)
        self.smafast = SimpleMovingAverage(1*24*60//15) 
        self.smaslow = SimpleMovingAverage(3*24*60//15)
        fifteenMinuteConsolidator = self.ResolveConsolidator("CUSTOM_EQUITY_SYMBOL", timedelta(minutes=15))
        self.SubscriptionManager.AddConsolidator("CUSTOM_EQUITY_SYMBOL", fifteenMinuteConsolidator)
        # self.RegisterIndicator("CUSTOM_EQUITY_SYMBOL", self.aroon, fifteenMinuteConsolidator)
        self.RegisterIndicator("CUSTOM_EQUITY_SYMBOL", self.smafast, fifteenMinuteConsolidator)
        self.RegisterIndicator("CUSTOM_EQUITY_SYMBOL", self.smaslow, fifteenMinuteConsolidator)
        
    
    def FifteenMinuteBarHandler(self, consolidated):
        if self.IsWarmingUp: return
        # if not self.aroon.IsReady: return    
        if not self.smafast.IsReady or not self.smaslow.IsReady: return    
    
        price = self.Securities["CUSTOM_EQUITY_SYMBOL"].Price
        self.Plot("Price Plot", "Price", price)
        self.Plot("Price Plot", "smafast", self.smafast.Current.Value)
        self.Plot("Price Plot", "smaslow", self.smaslow.Current.Value)
        
        # self.Plot("AROON", "aroonup", self.aroon.AroonUp.Current.Value)
        # self.Plot("AROON", "aroondown", self.aroon.AroonDown.Current.Value)
# class TestAlgorithm(QCAlgorithm):
#     def Initialize(self):
#         self.SetStartDate(2021,8,15)
#         self.SetEndDate(2021,9,24)
#         # self.SetCash(100000000000)
#         self.btc = self.AddEquity("AAPL", Resolution.Minute).Symbol
#         # self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash)
#         self.Consolidate("AAPL", timedelta(minutes=15), self.FifteenMinuteBarHandler)        
#         self.SetWarmUp(3*24*60, Resolution.Minute)
#         self.aroon = AroonOscillator(25, 25)
#         self.smafast = SimpleMovingAverage(1*24*60//15) 
#         self.smaslow = SimpleMovingAverage(3*24*60//15)
#         fifteenMinuteConsolidator = TradeBarConsolidator(timedelta(minutes=15))
#         self.SubscriptionManager.AddConsolidator("AAPL", fifteenMinuteConsolidator)
#         self.RegisterIndicator("AAPL", self.aroon, fifteenMinuteConsolidator)
#         self.RegisterIndicator("AAPL", self.smafast, fifteenMinuteConsolidator)
#         self.RegisterIndicator("AAPL", self.smaslow, fifteenMinuteConsolidator)
        
    
#     def FifteenMinuteBarHandler(self, consolidated):
#         if self.IsWarmingUp: return
#         if not self.aroon.IsReady: return    
#         if not self.smafast.IsReady or not self.smaslow.IsReady: return    
    
#         price = self.Securities["AAPL"].Price
#         self.Plot("Price Plot", "Price", price)
#         self.Plot("Price Plot", "smafast", self.smafast.Current.Value)
#         self.Plot("Price Plot", "smaslow", self.smaslow.Current.Value)
        
#         self.Plot("AROON", "aroonup", self.aroon.AroonUp.Current.Value)
#         self.Plot("AROON", "aroondown", self.aroon.AroonDown.Current.Value)