Overview of the Bybit Spot trading strategy.
- Database Integration and Buy Configuration
MySQL Database: Your script integrates with a MySQL database to retrieve configuration parameters (buy_config) and symbols (symbol_min_qty table).
Buy Configurations: These configurations are crucial for deciding when to buy. They include multiple parameters like RSI thresholds, Bollinger Bands settings, Moving Averages, and cooldown periods. - Market Data Fetching and Indicators Calculation
Candlestick Data Retrieval: For each symbol, historical OHLCV (Open, High, Low, Close, Volume) data is fetched from Bybit using the ccxt library.
Indicators Computation: The script calculates a series of technical indicators, each serving a specific role in determining market trends:
RSI (Relative Strength Index): Measures momentum and helps identify overbought or oversold conditions.
Bollinger Bands: Uses a moving average with upper and lower bands to determine price volatility.
MACD (Moving Average Convergence Divergence): Shows the relationship between two moving averages and is used to identify trend direction and strength.
ADX (Average Directional Index): Evaluates the strength of the trend.
VWAP (Volume-Weighted Average Price): Useful to measure the average price weighted by volume, helping gauge market strength.
OBV (On-Balance Volume): Measures buying and selling pressure. - Downtrend and Market Monitoring Logic
Downtrend Detection:
ADX Analysis: If ADX is above a certain threshold, the trend is considered strong.
DI+/DI- Analysis: Determines if the trend is bearish.
Price vs. Long Moving Average: Indicates whether the current price is below the long-term moving average, which can further confirm a downtrend.
MACD Bearish Condition: A bearish MACD crossover is used as an additional confirmation.
If all these conditions are met, the script assumes a major downtrend and skips buying for that symbol.
Cooldown Period: There is a cooldown mechanism to avoid frequent trades on the same symbol. The cooldown_hours parameter is checked before proceeding with any new buy decision for a symbol. - Buying Decision
Buy Conditions: For a buy order to be placed, several conditions need to be met, indicating a high probability of a price reversal or uptrend:
Low RSI: Indicates oversold conditions, and a low RSI might trigger a buy.
Price Near Lower Bollinger Band: The price must be close to the lower Bollinger Band, suggesting that it’s potentially a good entry point.
Price Below VWAP: Price should be below the VWAP, indicating a possible undervaluation.
Positive OBV: Positive On-Balance Volume suggests buying pressure, which supports a potential price increase.
MACD Crossover: MACD line crosses above the Signal line, which is a bullish signal.
Price Stabilization & Rebound: The price needs to stabilize and rebound, which further confirms the end of a downtrend.
Execution: If all these conditions are met, the script triggers a buy action by calling an external script (buy.py) with the relevant symbol and order quantity. - Data Logging
Indicator Data Logging: After each symbol is analyzed, the script logs various indicator values to the indicator_data table in the MySQL database. This provides a historical record of the conditions at the time of analysis, which can be useful for future review or tuning the strategy. - Looping Through Symbols
The script continuously loops through the symbols, fetching market data, calculating indicators, and making buy decisions.
After each complete loop through all symbols, it sleeps for a period defined by min_buy_period to avoid overtrading and give time for market conditions to change. - Strategy Summary
Primary Goal: The strategy aims to identify low-risk buying opportunities by detecting the bottom of a price movement using several indicators.
Combining Indicators: It relies on a mix of momentum (RSI), volatility (Bollinger Bands), trend strength (ADX), volume (OBV), and moving averages to form a holistic view of the market for each symbol.
Focus on Oversold Conditions: The RSI is a key component of this strategy, with the logic designed to buy when the market is likely oversold (low RSI), but it does not rely on RSI alone, reducing the chance of false signals.
Avoid Buying During Major Downtrends: The strategy takes a cautious approach by avoiding buys during strong bearish trends, which are identified using ADX, DI+/DI-, and MACD. - Strengths and Weaknesses
Strengths:
Multi-Factor Analysis: The use of multiple indicators reduces the reliance on any one metric, improving the robustness of your buy decisions.
Data Logging: Logging indicator values helps with backtesting and refining your strategy.
Cooldown Mechanism: The cooldown period avoids repeated buys, potentially saving you from frequent losses during high volatility periods.
Weaknesses:
Complexity: Given the number of conditions, the strategy may be too conservative, potentially leading to missed opportunities.
Over-Reliance on Historical Indicators: Indicators like RSI and MACD are lagging, which means they depend on historical data and may not always accurately predict future price movements.
Conclusion
Your strategy combines several indicators to create a fairly cautious trading system. It aims to enter trades at favorable moments while avoiding buying during major downtrends, thus balancing between risk and reward. The focus on oversold conditions (using RSI) combined with additional indicators like MACD, ADX, and Bollinger Bands makes it a thoughtful approach.