Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
how do you code a simple RSI algo

The algo is not making any trades and i wonder if it is the RSI function which is the problem any helpis much appreciated.

2 responses

@ jolyon

Hope this will help:

# RSI Rotation

import talib  
# --------------------------------------------------------  
STOCKS, PERIOD, UB, LB = symbols('QQQ', 'TLT'), 14, 70, 30  
# --------------------------------------------------------  
def initialize(context):  
    schedule_function(trade, date_rules.every_day(), time_rules.market_open(minutes = 65)) 

def trade(context,data):  
    if get_open_orders(): return  
    wt = 1.0 / len(STOCKS)

    for stock in STOCKS:  
        prices = data.history(stock, 'price', PERIOD + 1, '1d')  
        rsi = talib.RSI(prices, PERIOD)[-1]  
        if data.can_trade(stock):  
            if rsi >= UB:  
                order_target_percent(stock, wt)  
            elif rsi <= LB:  
                order_target_percent(stock, 0)  

yes that did help a lot thanks its now working