# Ping-Pong Trading Strategy (RSI & Hurst Bands) The Ping-Pong strategy is an **accumulation and volatility harvesting system** designed for range-bound or trending markets. It utilizes a series of "pings" (small trades) to build a position during dips (Long) or peaks (Short) and takes profits incrementally during price reversals. ## 1. Core Indicators ### A. RSI (Relative Strength Index) - **Calculation**: Standard 14-period RSI using Rolling Moving Average (RMA) smoothing. - **Overbought/Oversold**: Default levels are **70/30**. - **Crossover Logic (Long Mode)**: - **Accumulate (BUY)**: RSI crosses **UP** through the `oversold` level (e.g., from 29 to 31). - **Partial Exit (SELL)**: RSI crosses **DOWN** through the `overbought` level (e.g., from 71 to 69). ### B. Hurst Bands - **Structure**: - **Center Line**: A Rolling Moving Average (RMA) shifted backward by half the period to center it on price action. - **Bands**: Center Line ± (Multiplier * ATR). - **Crossover Logic (Long Mode)**: - **Accumulate (BUY)**: Price (Close) crosses **DOWN** below the `hurst_lower` band. - **Partial Exit (SELL)**: Price (Close) crosses **UP** above the `hurst_upper` band. --- ## 2. Execution Logic (Long Direction) The strategy operates on a **Crossover-only** trigger mechanism on every new candle. ### A. Opening & Accumulation (`Signal: OPEN`) Triggered if **EITHER** RSI or Hurst generates a BUY signal (and both are enabled). - **Trade Size**: `pos_size_margin * exchange_leverage` (USD). - **Risk Filter**: A trade is only executed if the resulting **Total Effective Leverage** (Total Position Notional / Account Equity) is less than or equal to `max_effective_leverage`. - **Order Type**: Market Order. ### B. Closing & Partial Exit (`Signal: CLOSE`) Triggered if **EITHER** RSI or Hurst generates a SELL signal (and both are enabled). - **Exit Size**: `current_position_size * partial_exit_pct` (Default: 15%). - **Minimum Value Rule**: If the remaining position value after the partial exit would fall below `min_position_value_usd` (Default: $15), the **ENTIRE** position is closed. - **Order Type**: Market Order (with `reduceOnly=True`). --- ## 3. Server-Side Execution Workflow 1. **Polling**: The script polls the database every 5-10 seconds for the most recent candle data. 2. **Candle Detection**: When a new candle timestamp is detected, the indicator engine recalculates RSI and Hurst Bands. 3. **Signal Check**: The script compares the `latest` candle values with the `previous` candle values to identify strict crossovers. 4. **Exchange Sync**: Before execution, the script fetches the current account balance and active position from the exchange (e.g., Bybit). 5. **Order Placement**: Based on the calculated quantity and risk filters, it sends a Market Order to the exchange. --- ## 4. Key Configuration Parameters | Parameter | Type | Default | Description | | :--- | :--- | :--- | :--- | | `symbol` | string | BTCUSDT | Trading pair. | | `direction` | string | long | Strategy direction ("long" or "short"). | | `pos_size_margin` | float | 20.0 | The base USD amount for each trade (Ping). | | `exchange_leverage` | float | 3.0 | Multiplier for the individual trade size. | | `max_eff_leverage` | float | 1.0 | Hard cap on total account exposure. | | `partial_exit_pct` | float | 0.15 | Fraction of the position to close on a sell signal. | | `min_pos_val_usd` | float | 15.0 | Minimum USD value to keep a position active. | | `rsi_enabled` | boolean | true | Enable RSI as a trigger. | | `hurst_enabled` | boolean | true | Enable Hurst Bands as a trigger. |