Back to Community
Golden Cross and RSI Algo

Result of my Algo, during the time period (09/01/2018 - 11/15/2019)

Clone Algorithm
2
Loading...
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
import talib 
import numpy as np 
import pandas as pd 

# Golden Cross plus RSI Algo 
def initialize(context):
    set_benchmark(sid(8554))
    context.stock = sid(351)
    
    schedule_function(ma_crossover_handling, date_rules.every_day(), time_rules.market_close(minutes=1),
                     time_rules.market_open(minutes=65))
            
def ma_crossover_handling(context, data):
    
    prices = data.history(context.stock, 'price', 200, '1d')
    rsi = talib.RSI(prices, timeperiod=14)[-1]
    sma_200 = prices.mean()
    sma_50 = prices[-50:].mean()
    sma_10 = prices[-10:].mean()
    
    open_orders = get_open_orders() 
    
    
    if (sma_200 > sma_50 and sma_50>sma_10) or rsi > 80:
        if context.stock not in open_orders:
            order_target_percent(context.stock, -1.0)
    elif (sma_200 < sma_50 and sma_10>sma_50) or rsi < 20:
        if context.stock not in open_orders:
            order_target_percent(context.stock, 1.0)
There was a runtime error.