Hi everyone,
What an amazing site and community!
I'm a few days into experimenting with this stuff so please go easy.
I'm learning by mashing a few concepts I've seen.
The current challenge is ADX trading as posted on another thread and looping that to trade the Q500US.
I hit a snag though and it seems to be a little beyond my understanding.
Any help would be greatly appreciated.
# talib ADX Indicator
import talib
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline
from quantopian.pipeline.filters import Q500US
def initialize(context):
schedule_function(
record_ADX,
date_rules.every_day(),
time_rules.market_close(hours = 1)
)
context.security_list = []
attach_pipeline(make_pipeline(), 'my_pipeline')
def make_pipeline():
return Pipeline(screen = Q500US(),)
def before_trading_start(context, data):
context.output = pipeline_output('my_pipeline')
context.security_list_org = context.output.index
def record_ADX(context, data):
for stock in context.security_list_org:
period = 30
H = data.history(stock,'high', 2*period,'1d').dropna()
L = data.history(stock,'low', 2*period,'1d').dropna()
C = data.history(stock,'price', 2*period,'1d').dropna()
ta_ADX = talib.ADX(H, L, C, period)
ta_nDI = talib.MINUS_DI(H, L, C, period)
ta_pDI = talib.PLUS_DI(H, L, C, period)
ADX = ta_ADX[-1]
nDI = ta_nDI[-1]
pDI = ta_pDI[-1]
if (ADX > 20) and (pDI > nDI):
order(stock, 500) #DOWN FROM 500
#log.debug('buy' (stk))
elif (ADX > 25) and (pDI < nDI):
order(stock, -500) #DOWN FROM 500
#log.debug('sell' (stk))