Hi all,

I am new to programming and algorithms in general, so please bear with me. 

I just started programming my first algo over at Quantopian (QP) this week when I realized that QC is probably the better place to be at the moment. I am now trying to simply migrate my basic algo over to QC, and was hoping to find some kind help on this forum. My algo is very simple for obvious reasons, but I still find it hard to figure out how to go about converting it to QC standards. 

The algo is based on two technical indicators (ADX and Parabolic SAR). The algo goes long when the ADX crosses a certain threshold and when the parabolic SAR is indicating an up-trend, It exists the long posistion and switches to a second asset at exit when similar conditions are met by the SAR and ADX indicator. The aglo from QP currently imports Talib for the mentioned indicators, and this is the difficult part to migrate. The code from QP currently looks like this: 

# ---------------------------------------------------------------------  

# ADX, PLUS_DI, MINUS_DI, SAR  
import talib  
# ---------------------------------------------------------------------  
stock, bond, period = symbol('dia'), symbol('tlt'), 14; bars = period*2  
# ---------------------------------------------------------------------  
def initialize(context):  
    schedule_function(trade , date_rules.every_day(), time_rules.market_open(minutes = 65))
    set_benchmark(symbol('dia'))
    set_slippage(slippage.FixedSlippage(spread=0.02))
    set_commission(commission.PerShare(cost=0.01, min_trade_cost=1))
    

def trade (context, data):  
    if get_open_orders(): return  

    H = data.history(stock,'high', bars, '1d').dropna()  
    L = data.history(stock,'low', bars, '1d').dropna()  
    C = data.history(stock,'close', bars, '1d').dropna()  

    adx = talib.ADX(H, L, C, period)[-1]  
    mdi = talib.MINUS_DI(H, L, C, period)[-1]  
    pdi = talib.PLUS_DI(H, L, C, period)[-1]  
    sar = talib.SAR(H, L, 0.02, 0.2)[-1]

    if (adx < 15 and mdi > pdi and sar > C[-1]):  
        wt_stk, wt_bnd = 0, 1
    elif (adx > 15 and mdi < pdi):  
        wt_stk, wt_bnd = 3, 0  
    else: return  

    if all(data.can_trade([stock, bond])):  
        order_target_percent(stock, wt_stk)  
        order_target_percent(bond, wt_bnd)  

def before_trading_start(context,data):  
    x = context.account.leverage
    y =  context.account.net_leverage  
    record(leverage = x,net_leverage = y)
# ---------------------------------------------------------------------  

I hope this community can help me get started with learning how to program on this platform. 

Thank you all in advance!

 

 

Author