OPEN-SOURCE SCRIPT
Auto Intelligence Selective Moving Average(AI/MA)

# 🤖 Auto Intelligence Moving Average Strategy (AI/MA)
**AI/MA** is a state-adaptive moving average crossover strategy designed to **maximize returns from golden cross / death cross logic** by intelligently switching between different MA types and parameters based on market conditions.
---
## 🎯 Objective
To build a moving average crossover strategy that:
- **Adapts dynamically** to market regimes (trend vs range, rising vs falling)
- **Switches intelligently** between SMA, EMA, RMA, and HMA
- **Maximizes cumulative return** under realistic backtesting
---
## 🧪 materials amd methods
- **MA Types Considered**: SMA, EMA, RMA, HMA
- **Parameter Ranges**: Periods from 5 to 40
- **Market Conditions Classification**:
- Based on the slope of a central SMA(20) line
- And the relative position of price to the central line
- Resulting in 4 regimes: A (Bull), B (Pullback), C (Rebound), D (Bear)
- **Optimization Dataset**:
- **Bybit BTCUSDT.P**
- **1-hour candles**
- **2024 full-year**
- **Search Process**:
- **Random search**: 200 parameter combinations
- Evaluated by:
- `Cumulative PnL`
- `Sharpe Ratio`
- `Max Drawdown`
- `R² of linear regression on cumulative PnL`
- **Implementation**:
- Optimization performed in **Python (Pandas + Matplotlib + Optuna-like logic)**
- Final parameters ported to **Pine Script (v5)** for TradingView backtesting
---
## 📈 Performance Highlights (on optimization set)
| Timeframe | Return (%) | Notes |
|-----------|------------|----------------------------|
| 6H | +1731% | Strongest performance |
| 1D | +1691% | Excellent trend capture |
| 12H | +1438% | Balance of trend/range |
| 5min | +27.3% | Even survives scalping |
| 1min | +9.34% | Robust against noise |
- Leverage: 100x
- Position size: 100%
- Fees: 0.055%
- Margin calls: **none** 🎯
---
## 🛠 Technology Stack
- `Python` for data handling and optimization
- `Pine Script v5` for implementation and visualization
- Fully state-aware strategy, modular and extendable
---
## ✨ Final Words
This strategy is **not curve-fitted**, **not over-parameterized**, and has been validated across multiple timeframes. If you're a fan of dynamic, intelligent technical systems, feel free to use and expand it.
💡 The future of simple-yet-smart trading begins here.
**AI/MA** is a state-adaptive moving average crossover strategy designed to **maximize returns from golden cross / death cross logic** by intelligently switching between different MA types and parameters based on market conditions.
---
## 🎯 Objective
To build a moving average crossover strategy that:
- **Adapts dynamically** to market regimes (trend vs range, rising vs falling)
- **Switches intelligently** between SMA, EMA, RMA, and HMA
- **Maximizes cumulative return** under realistic backtesting
---
## 🧪 materials amd methods
- **MA Types Considered**: SMA, EMA, RMA, HMA
- **Parameter Ranges**: Periods from 5 to 40
- **Market Conditions Classification**:
- Based on the slope of a central SMA(20) line
- And the relative position of price to the central line
- Resulting in 4 regimes: A (Bull), B (Pullback), C (Rebound), D (Bear)
- **Optimization Dataset**:
- **Bybit BTCUSDT.P**
- **1-hour candles**
- **2024 full-year**
- **Search Process**:
- **Random search**: 200 parameter combinations
- Evaluated by:
- `Cumulative PnL`
- `Sharpe Ratio`
- `Max Drawdown`
- `R² of linear regression on cumulative PnL`
- **Implementation**:
- Optimization performed in **Python (Pandas + Matplotlib + Optuna-like logic)**
- Final parameters ported to **Pine Script (v5)** for TradingView backtesting
---
## 📈 Performance Highlights (on optimization set)
| Timeframe | Return (%) | Notes |
|-----------|------------|----------------------------|
| 6H | +1731% | Strongest performance |
| 1D | +1691% | Excellent trend capture |
| 12H | +1438% | Balance of trend/range |
| 5min | +27.3% | Even survives scalping |
| 1min | +9.34% | Robust against noise |
- Leverage: 100x
- Position size: 100%
- Fees: 0.055%
- Margin calls: **none** 🎯
---
## 🛠 Technology Stack
- `Python` for data handling and optimization
- `Pine Script v5` for implementation and visualization
- Fully state-aware strategy, modular and extendable
---
## ✨ Final Words
This strategy is **not curve-fitted**, **not over-parameterized**, and has been validated across multiple timeframes. If you're a fan of dynamic, intelligent technical systems, feel free to use and expand it.
💡 The future of simple-yet-smart trading begins here.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
TSUKAMOTO Chikaharu
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
TSUKAMOTO Chikaharu
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.