# ----------------------------------------------------------------
EQUITIES = ['AAPL','TSLA']; CRYPTOS = ['BTCUSD', 'ETHUSD']; CFDS = ['WTICOUSD']; RSI_PERIOD = 14;
# ----------------------------------------------------------------

class IndicatorForEquitiesAndCryptos(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 1, 1) #Set Start Date
        self.SetEndDate(2021, 2, 1) #Set End Date
        self.SetCash(100000)
        self.equities = [self.AddEquity(ticker, Resolution.Daily).Symbol for ticker in EQUITIES]
        self.cryptos = [self.AddCrypto(ticker, Resolution.Daily).Symbol for ticker in CRYPTOS]
        self.cfds = [self.AddCfd(ticker, Resolution.Daily).Symbol for ticker in CFDS]
        self.assets =  self.equities + self.cryptos + self.cfds
        self.rsi = {}
        self.current = {}
        self.entry_price = {}
        self.highestPrice = {}
  
        for sec in self.assets:
            self.rsi[sec] = self.RSI(sec, RSI_PERIOD, MovingAverageType.Simple, Resolution.Daily)
            self.current[sec] = None
            self.entry_price[sec] = None
            self.highestPrice[sec] = 0
        
        #self.SetWarmUp(RSI_PERIOD + 1, Resolution.Daily)
        

    def OnData(self, data):
        #if self.IsWarmingUp: return
        # self.Log(self.assets)
        count = 0
        for sec in self.assets:
            #self.Plot("RSI", sec, self.rsi[sec].Current.Value)
            self.current[sec] = self.Securities[sec].Close

            if self.current[sec] == None: continue

            #trading conditions, only when we are not invested
            if self.rsi[sec].Current.Value > 60:
                self.Debug("RSI is more than 60")
                if not self.Securities[sec].Invested:
                    self.SetHoldings(sec, 0.1) #invested 10% of our capital
                    self.entry_price[sec] = self.current[sec]
                    self.Debug(str(sec) + " Entry at: " +str(self.entry_price[sec]))
            
            #exit conditions, only if we are invested
            if self.Securities[sec].Invested:
                if self.current[sec] <= self.entry_price[sec] - (self.entry_price[sec] * 0.05): #cut loss at 5%
                    self.Liquidate(sec, "stop-loss")
                    self.Debug(str(sec) + " stopped out at: " + str(self.current[sec]))
                elif self.current[sec] >= self.entry_price[sec] + (self.entry_price[sec]*0.1): # set tp > 10%
                    self.Liquidate(sec, "take-profit")
                    self.Debug(str(sec) + " Tp at: "+ str(self.current[sec]))
            count = count + 1
            self.Debug("Count at " + str(count))

 

 

 

181324_1651556763.jpg

 

Hi, any ideas why is this algorithm executing twice a day? once at 00:00 hrs and another 19:00 hrs