0bps

Strategy vault / Mean reversion

Sharing RSI Overbought and Oversold Strategy

Python strategy by 盯盘狗 - 策略出租.

Author
盯盘狗 - 策略出租
Complexity
Starter · 51 lines
Parameters
0

The original spec has no written description. Read the source below.

Source Python

import talib
import numpy as np
import time

# Initialize strategy parameters
symbol = 'huobip/btc_usdt'
period = '1m'
rsi_period = 14
rsi_buy = 30
rsi_sell = 70
amount = 0.01
last_buy_price = 0

# ConnectAPI
exchange = Exchange()
exchange.SetContractType(symbol)
exchange.SetPeriod(period)

# Main loop
while True:
    # Get candlestick data
    klines = exchange.GetRecords()
    if not klines:
        continue

    # Calculate RSI indicator
    close_prices = np.array([float(k['Close']) for k in klines])
    rsi = talib.RSI(close_prices, rsi_period)

    # Get current price
    current_price = float(klines[-1]['Close'])

    # Determine whether it is overbought or oversold
    if rsi[-1] < rsi_buy and last_buy_price == 0:
        # Oversold, buy
        buy_price = current_price
        buy_amount = amount / buy_price
        exchange.Buy(buy_price, buy_amount)
        last_buy_price = buy_price
        print('Buy', buy_amount, 'BTC, at price', buy_price)
    elif rsi[-1] > rsi_sell and last_buy_price != 0:
        # Overbought, sell
        sell_price = current_price
        sell_amount = amount / sell_price
        exchange.Sell(sell_price, sell_amount)
        last_buy_price = 0
        print('Sell ', sell_amount, ' BTC, price', sell_price)

    # Wait for next loop
    time.sleep(60)

Published by 盯盘狗 - 策略出租 on the FMZ strategy square · last modified 2023-04-18. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Sharing-RSI-Overbought-and-Oversold-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open