For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Newbie error in both RSI and MACD



  • Both my strategies work fine when going long individually. However they don't work together. Can someone please help?

    Here is my MACD code:

    def next(self):
                if self.position.size== 0:
                    if ((self.crossover >0)& (self.macd.macd>0) & (self.macd.signal>0)) :
                        amount_to_invest=self.params.order_percentage*self.broker.cash
                        self.size=math.floor(amount_to_invest/self.data.close)
                        
                        print("BUY CREATED at {}".format(self.data.close[0]))
                        self.order= self.buy(size= self.size) 
                    elif ((self.crossover <0)& (self.macd.macd<0) & (self.macd.signal<0)) :
                        amount_to_invest=self.params.order_percentage*self.broker.cash
                        self.size=math.floor(amount_to_invest/self.data.close)
                        
                        print("SELL at {}".format(self.data.close[0]))
                        self.order= self.sell(size= self.size)
                elif (self.position.size >0):
                    if ((self.crossover <0)&(self.order.isbuy())):
                        print("close at {}".format(self.data.close[0])) 
                        self.close()
                    elif ((self.crossover>0) & (self.order.issell())):
                        print("close at {}".format(self.data.close[0])) 
                        self.close()
    

    Here is my RSI code:

    def next(self):
                if self.position.size== 0:
                    if self.rsi < self.params.lowerbound:
                        amount_to_invest=self.params.order_percentage*self.broker.cash
                        self.size=math.floor(amount_to_invest/self.data.close)
                            
                        print("BUY at {}".format(self.data.close[0]))
                        self.buy(size= self.size)
                    elif self.rsi> self.params.upbound:
                        amount_to_invest=self.params.order_percentage*self.broker.cash
                        self.size=math.floor(amount_to_invest/self.data.close)
                            
                        print("SELL Created at {}".format(self.data.close[0]))
                        self.sell(size= self.size)
                
                if self.position.size > 0:
                    if (self.rsi < self.params.upbound) or ( self.rsi> self.params.lowerbound):
                         print("Sell at {}".format(self.data.close[0])) 
                         self.close()'''


  • Can you include the combined code that didn't work and your error messaage?



  • @run-out I mean there is no error message. My algorithm seems to always underperform in MACD.


Log in to reply
 

});