Strategy vault / Mean reversion
Sharing RSI Overbought and Oversold Strategy
Python strategy by 盯盘狗 - 策略出租.
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.
/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- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- 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
- ATR and EMA based Dynamic Take Profit and Stop Loss Adaptive StrategyPine Script · Mean reversion · 1h
- Adaptive Mean Reversion Trading Strategy Based on Chande Momentum OscillatorPine Script · Mean reversion · 1d
- Adaptive RSI Oscillator Dynamic Trading Strategy with Threshold OptimizationPine Script · Mean reversion · 1d
- Advanced 15 Minute Chart Trading Signal StrategyPine Script · Mean reversion · 3h
- Advanced Fibonacci Retracement Trend Following and Reversal Trading StrategyPine Script · Mean reversion · 3h
- Advanced Momentum EMA Trend Following with RSI Overbought Oversold Trading StrategyPine Script · Mean reversion · 1d