INNER CODE UNIT · Python
cmo_trading_strategy
liamhartley/cryptotradingbot · backtesting_scripts/coinbase_backtesting.py:88
def cmo_trading_strategy(gemini, data):
base_currency = LOGICAL_PARAMS['PAIR'].split('-')[0]
quote_currency = LOGICAL_PARAMS['PAIR'].split('-')[1]
if len(data) >= CMO_PERIOD:
# cmo = poloniex_cmo_logic_no_pandas(pair=quote_currency+'_'+base_currency, period=api_period)
cmo = coinbase_cmo_logic_no_pandas(pair=LOGICAL_PARAMS['PAIR'], period=api_period)
assert -100 <= cmo <= 100
if cmo < OVERSOLD_VALUE:
gemini.account.enter_position(type_="Long",
entry_capital=ENTRY_SIZE,
entry_price=data.iloc[-1]['high'])
print(f'Open position @ {data.iloc[-1]["low"]}')
elif cmo > OVERBOUGHT_VALUE and len(gemini.account.positions) > 0:
gemini.account.close_position(position=gemini.account.positions[0],
percent=1,
price=data.iloc[-1]['low'])
print(f'Close position @ {data.iloc[-1]["low"]}')