The algo is not making any trades and i wonder if it is the RSI function which is the problem any helpis much appreciated.
The algo is not making any trades and i wonder if it is the RSI function which is the problem any helpis much appreciated.
@ 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)