Hey, guys!
I'm trying to create an algo that will execute a buy whenever MACD hits a local minimum. I've simply defined this as MACD (t-2) > MACD (t-1) < MACD (today). So I have my MACD defined, below. I'm wondering how to create MACD (t-2) and (t-1) using EMAs of two days prior and one day prior, if anyone can help, please.
//
import talib
def initialize(context):
context.stock = sid(8554)
schedule_function(trade, date_rules.every_day(), time_rules.market_open(hours=1))
def trade(context,data):
prices = data.history(context.stock,'price', 47,'1d')
ema12 = talib.EMA(prices,12)
ema26 = talib.EMA(prices,26)
macd = ema12 - ema26