docs: update documentation to reflect Inverse ETP strategy and virtual balance logic
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
# Trading212 Python Scalping Bot - "Touch & Turn" (Opening Range Reversal)
|
||||
|
||||
This project implements the "Touch & Turn" scalping strategy, originally designed for ProRealTime, translated into Python for the Trading212 API.
|
||||
This project implements the "Touch & Turn" scalping strategy, originally designed for ProRealTime, translated into Python for the Trading212 API. It is optimized for the UK ISA environment using Inverse ETPs for shorting.
|
||||
|
||||
## Project Overview
|
||||
|
||||
* **Strategy:** Opening Range Liquidity Reversal (Touch & Turn).
|
||||
* **Asset Class:** US Stocks (e.g., Netflix, Apple, Tesla).
|
||||
* **Asset Class:** US Stocks (e.g., NVDA, ARM, TSLA).
|
||||
* **Timeframe:** 15-minute chart.
|
||||
* **Operating Window:** 09:30 - 11:00 EST (Opening of the US Regular Trading Session).
|
||||
|
||||
@@ -13,26 +13,28 @@ This project implements the "Touch & Turn" scalping strategy, originally designe
|
||||
|
||||
1. **Identify the Opening Candle:** Capture the `High`, `Low`, `Open`, and `Close` of the first 15-minute candle of the session (09:30 to 09:45 EST).
|
||||
2. **Filter for Liquidity:**
|
||||
- Calculate the 14-day ATR (Average True Range).
|
||||
- The opening range (`High - Low`) must be at least **25% of the ATR**. If smaller, the bot stays flat for the day.
|
||||
- The opening range (`High - Low`) must be at least **25% of the 14-day ATR**. If smaller, the bot stays flat.
|
||||
3. **Determine Direction:**
|
||||
- If the candle is **Bearish** (Close < Open): Prepare for a **LONG** entry at the `Low`.
|
||||
- If the candle is **Bullish** (Close > Open): Prepare for a **SHORT** entry at the `High`.
|
||||
4. **Calculate Targets (Fibonacci):**
|
||||
- The target price is the **38.2% Fibonacci level** of the opening candle's range.
|
||||
5. **Risk Management:**
|
||||
- **Take Profit (TP):** The distance from the entry to the 38.2% Fib level.
|
||||
- **Stop Loss (SL):** Half the TP distance (Risk:Reward ratio of 1:2).
|
||||
6. **Automatic Exit:** Force close any open positions at 11:00 EST.
|
||||
- If the candle is **Bearish** (Close < Open): Prepare for a **LONG** entry.
|
||||
- If the candle is **Bullish** (Close > Open): Prepare for a **SHORT** entry.
|
||||
4. **ISA-Compliant Shorting:**
|
||||
- Since standard shorting is forbidden in a UK ISA, the bot automatically substitutes SHORT signals with **BUY orders for 3x Inverse ETPs** (e.g., 3SLA for TSLA).
|
||||
5. **Execution:**
|
||||
- Uses **Market Orders** at 09:45 EST for immediate entry.
|
||||
- Recalculates SL/TP brackets based on the **Actual Fill Price** fetched from the portfolio.
|
||||
6. **Risk Management:**
|
||||
- **Position Sizing:** Risks **1% of account balance** per trade.
|
||||
- **Virtual Balance:** In demo mode, subtracts £4,750 from total value to simulate a realistic £250 starting point.
|
||||
- **Targets:** 38.2% Fibonacci retracement level. Risk:Reward ratio of 1:2.
|
||||
7. **Automatic Exit:** Force close any open positions at 11:00 EST via Market Order.
|
||||
|
||||
## Technical Architecture
|
||||
|
||||
* **API Client (`src/api/client.py`):** Handles REST calls to Trading212.
|
||||
* **Strategy Engine (`src/strategy/touch_turn.py`):**
|
||||
- Monitors the clock for the 09:45 EST trigger.
|
||||
- Fetches 14-day ATR and the 09:30-09:45 15m candle.
|
||||
- Calculates entry/TP/SL levels.
|
||||
* **Execution Engine (`src/execution/manager.py`):** Places the limit orders and manages the position lifetime.
|
||||
* **API Client (`src/api/client.py`):** Handles REST Basic Auth calls to Trading212.
|
||||
* **Strategy Engine (`src/strategy/touch_turn.py`):** Calculates setup, Fibonacci levels, and percentage-based targets.
|
||||
* **Execution Manager (`src/execution/manager.py`):** Handles ticker swapping for ISA mode, market order placement, protection bracketing, and status monitoring.
|
||||
* **Orchestrator (`main.py`):** Automates the morning routine: scanning, backtesting, and spawning parallel execution threads.
|
||||
* **Data resilient:** Implements retry loops and random jitter to handle API delays and rate limits (429/403/404 errors).
|
||||
|
||||
## Getting Started
|
||||
|
||||
@@ -41,13 +43,18 @@ This project implements the "Touch & Turn" scalping strategy, originally designe
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
2. **Configuration:**
|
||||
- Set `TRADING212_API_KEY` and `TRADING212_BASE_URL` in your `.env` file.
|
||||
- Ensure your system clock is accurate or handle timezone conversions to EST.
|
||||
- Set credentials in your `.env` file.
|
||||
- `ISA_MODE=True` enables Inverse ETP substitution.
|
||||
3. **Operation:**
|
||||
- Best deployed via a systemd timer at 09:30 America/New_York time.
|
||||
|
||||
## TODOs
|
||||
|
||||
- [x] Document the strategy logic.
|
||||
- [x] Implement ATR calculation in the strategy engine.
|
||||
- [x] Implement the 15m candle capture logic.
|
||||
- [x] Implement the entry/exit order placement logic in the execution manager.
|
||||
- [x] Create a backtesting script (optional but recommended).
|
||||
- [x] Implement ATR calculation and Fibonacci targets.
|
||||
- [x] Implement 15m candle capture with timezone resilience.
|
||||
- [x] Implement ISA-compliant shorting via Inverse ETP mapping.
|
||||
- [x] Implement Risk-based position sizing (Virtual Balance logic).
|
||||
- [x] Create a leaderboard-based backtesting engine.
|
||||
- [x] Implement resilient execution (Retry loops, Jitter, Portfolio-checks).
|
||||
- [x] Add daily logging and P&L tracking (CSV).
|
||||
|
||||
Reference in New Issue
Block a user