need help creating Pipeline for moving average crossover!

okay so i made my first algorithm, it buys when ema_20 > ema_40, sma_50 > sma_150 = true, i need help creating a pipeline that meet that criteria and searches for stocks above \$5 and searches for volume above 500,000.

3
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
 Returns 1 Month 3 Month 6 Month 12 Month
 Alpha 1 Month 3 Month 6 Month 12 Month
 Beta 1 Month 3 Month 6 Month 12 Month
 Sharpe 1 Month 3 Month 6 Month 12 Month
 Sortino 1 Month 3 Month 6 Month 12 Month
 Volatility 1 Month 3 Month 6 Month 12 Month
 Max Drawdown 1 Month 3 Month 6 Month 12 Month
def initialize(context):
context.aapl = sid(24)
context.msft = sid(5061)
context.amzn = sid(16841)
context.ge = sid(3149)
context.xom = sid(8347)
context.pg = sid(5938)
context.DD = sid(2119)
context.ko = sid(4283)
context.mmm = sid(4922)
context.ibm = sid(3766)

def handle_data(context, data):
hist = data.history(context.aapl, 'price', 50, '1d')
hist = data.history(context.msft, 'price', 50, '1d')
hist = data.history(context.amzn, 'price', 50, '1d')
hist = data.history(context.ge, 'price', 50, '1d')
hist = data.history(context.xom, 'price', 50, '1d')
hist = data.history(context.pg, 'price', 50, '1d')
hist = data.history(context.DD, 'price', 50, '1d')
hist = data.history(context.ko, 'price', 50, '1d')
hist = data.history(context.mmm, 'price', 50, '1d')
hist = data.history(context.ibm, 'price', 50, '1d')
ema_20 = hist.mean()
ema_40 = hist[-40:].mean()
sma_50 = (hist.mean())
sma_150 = hist[-150:].mean()

open_orders = get_open_orders()

if (ema_20 > ema_40, sma_50 > sma_150):
if context.aapl not in open_orders:
order_target_percent(context.aapl, .10)
if context.msft not in open_orders:
order_target_percent(context.msft, .10)
if context.amzn not in open_orders:
order_target_percent(context.amzn, .10)
if context.ge not in open_orders:
order_target_percent(context.ge, .10)
if context.xom not in open_orders:
order_target_percent(context.xom, .10)
if context.pg not in open_orders:
order_target_percent(context.pg, .10)
if context.DD not in open_orders:
order_target_percent(context.DD, .10)
if context.ko not in open_orders:
order_target_percent(context.ko, .10)
if context.mmm not in open_orders:
order_target_percent(context.mmm, .10)
if context.ibm not in open_orders:
order_target_percent(context.ibm, .10)

elif (ema_40 > ema_20, sma_150 > sma_50):
if context.aapl not in open_orders:
order_target_percent(context.aapl, -.10)
if context.msft not in open_orders:
order_target_percent(context.msft, -.10)
if context.amzn not in open_orders:
order_target_percent(context.amzn, -.10)
if context.ge not in open_orders:
order_target_percent(context.ge, -.10)
if context.xom not in open_orders:
order_target_percent(context.xom, -.10)
if context.pg not in open_orders:
order_target_percent(context.pg, -.10)
if context.DD not in open_orders:
order_target_percent(context.DD, -.10)
if context.ko not in open_orders:
order_target_percent(context.ko, -.10)
if context.mmm not in open_orders:
order_target_percent(context.mmm, -.10)
if context.ibm not in open_orders:
order_target_percent(context.ibm, -.10)

record(leverage = context.account.leverage)
There was a runtime error.
1 response

also how can i make this work in live trading