PavelML-Dev
ML-Trading-Systems

ML SUPERTREND ULTIMATE -ML- QLearning +Per + LSTM + CNN

Last updated Jun 10, 2026
17
Stars
7
Forks
0
Issues
0
Stars/day
Attention Score
62
Language breakdown
No language data available.
โ–ธ Files click to expand
README

๐Ÿค– ML SuperTrend Ultimate: Deep Q-Learning + (Novier-Stokes xortex + mp4 expmls)

License: MIT Pine Script TradingView Made in Russia

First fully-working LSTM + Deep Q-Network trading system implemented in Pine Script!

A self-learning trading agent that uses cutting-edge machine learning techniques to adapt to market conditions in real-time โ€” no external libraries, no Python, just pure Pine Script.


๐Ÿ”ฅ What Makes This Unique?

This is NOT just another indicator. This is a complete reinforcement learning system that:

  • โœ… Learns from experience using Deep Q-Learning
  • โœ… Remembers patterns with LSTM neural networks
  • โœ… Adapts in real-time without retraining
  • โœ… Prioritizes important data with PER (Prioritized Experience Replay)
  • โœ… Works in your browser โ€” no GPU, no Python, no servers

Why It's Special

| Traditional Indicators | ML SuperTrend Ultimate | |----------------------|------------------------| | Static parameters | Learns optimal parameters | | Same for all markets | Adapts to each market | | Looks at 1-2 bars | Analyzes 8-20 bars history | | Simple rules | Deep neural networks | | No learning | Continuous learning |


โš ๏ธ DISCLAIMER

This is an experimental research project for educational purposes.

  • NOT financial advice
  • NO profit guarantees
  • Use at your own risk
  • Author bears NO responsibility for any losses
This is a learning tool, not a production trading system. Always backtest thoroughly and use proper risk management.

๐Ÿ“– What's Inside?

๐Ÿง  Deep Q-Network (DQN)

The "brain" that makes trading decisions.
  • 8 possible actions (ATR multipliers: 0.3 โ†’ 1.5)
  • 4-layer MLP (Multi-Layer Perceptron): 24 โ†’ 16 โ†’ 8 โ†’ 4 neurons
  • Q-values predict expected reward for each action
  • Epsilon-greedy exploration (10% โ†’ 2% decay)

๐Ÿ”ฎ LSTM Neural Network

Understands temporal patterns and market context.
  • 24 hidden units (configurable)
  • Dynamic timesteps (8-20 bars, adapts to volatility)
  • 4 gates: Forget, Input, Cell, Output
  • Backpropagation Through Time (BPTT)

๐Ÿ’พ Prioritized Experience Replay (PER)

Smart memory that focuses on important lessons.
  • 70,000 state buffer (replay memory)
  • Prioritized sampling based on TD-error
  • Importance sampling for bias correction
  • Beta annealing (0.4 โ†’ 1.0)

๐ŸŽฏ Adam Optimizer

State-of-the-art optimization for neural networks.
  • Adaptive learning rate (starts at 0.01)
  • Momentum + RMSprop combined
  • Gradient clipping for stability
  • Per-parameter learning rates

๐Ÿ“Š Rich Feature Set

20+ features extracted from market data:
  • Technical: RSI, MACD, ATR, Stochastic
  • Volume: OBV, Volume Rate of Change
  • Advanced: Ichimoku, VWAP, Hurst proxy
  • Volatility: Heidelberg index, ATR ratios
  • Custom: NN confidence, entropy

๐Ÿ— Architecture Overview

Market Data
    โ†“
[Feature Extraction] โ†’ 20 features
    โ†“
[LSTM Layer] โ†’ Temporal patterns (8-20 timesteps)
    โ†“
[MLP Network] โ†’ 24โ†’16โ†’8โ†’4 neurons
    โ†“
[Q-Values] โ†’ 8 actions (ATR multipliers)
    โ†“
[Action Selection] โ†’ Epsilon-greedy
    โ†“
[SuperTrend] โ†’ Adaptive coefficient
    โ†“
Trading Signals
    โ†“
[Reward] โ†’ (close - entry) / episode_length
    โ†“
[Experience Replay] โ†’ Store in buffer (70k states)
    โ†“
[PER Sampling] โ†’ Prioritize high TD-error
    โ†“
[Backpropagation] โ†’ Update Q-network
    โ†“
[LSTM BPTT] โ†’ Update LSTM weights

โšก Key Features

1. Real-Time Learning

  • No pre-training needed
  • Learns continuously as market evolves
  • TD-Error-driven updates

2. Adaptive Parameters

  • ATR multiplier: 0.3 - 1.5 (agent selects)
  • LSTM timesteps: 8-20 (volatility-based)
  • Learning rate: adaptive (0.001 - 0.05)

3. Advanced Techniques

  • Priority Experience Replay (PER)
  • Backpropagation Through Time (BPTT)
  • Gradient clipping
  • Adaptive Hinge Loss with L2 penalty
  • Dual-kernel CNN filter

4. Robust Design

  • Dropout (0.3) prevents overfitting
  • L2 regularization (0.0008 MLP, 0.0003 LSTM)
  • Leaky ReLU activation (no vanishing gradients)
  • Epsilon decay (0.10 โ†’ 0.02)

๐Ÿ”ฌ Technical Specifications

Reinforcement Learning Parameters

State Space: 20-dimensional vector (5 features ร— 4 timesteps)
Action Space: 8 discrete actions [0.3, 0.4, 0.5, 0.7, 0.9, 1.0, 1.2, 1.5]
Reward Function: (close - entryprice) / episodelength
Discount Factor (ฮณ): 0.99
Epsilon: 0.10 โ†’ 0.02 (decay: 0.999)
Training Frequency: Every 10 bars

Network Architecture

LSTM:
  Hidden Size: 8 (default, configurable)
  Timesteps: 8-20 (dynamic)
  Gates: Forget, Input, Cell, Output
  Activation: tanh (gates), sigmoid (cell)

MLP (DQN): Input: 20 features Layer 1: 24 neurons (Leaky ReLU) Layer 2: 16 neurons (Leaky ReLU) Layer 3: 8 neurons (Leaky ReLU) Layer 4: 4 neurons (Leaky ReLU) Output: 8 Q-values (linear)

Dropout: 0.3 L2 Lambda: 0.0008 (MLP), 0.0003 (LSTM)

Experience Replay

Buffer Size: 70,000 transitions
Batch Size: 6 samples
Priority Alpha (ฮฑ): 0.6
Priority Beta (ฮฒ): 0.4 โ†’ 1.0 (annealing)
Priority Epsilon: 1e-5

Optimizer

Type: Adam
Learning Rate: 0.01 (adaptive: 0.001 - 0.05)
Beta1: 0.9 (momentum)
Beta2: 0.999 (RMSprop)
Epsilon: 1e-8
Gradient Clip: 1.0

๐Ÿš€ Quick Start

Installation (TradingView)

  • Open TradingView
  • Navigate to Pine Editor (bottom panel)
  • Create new indicator
  • Copy-paste code from mlsupertrendultimate.pine
  • Click "Add to Chart"

First Run

  • Initial training: Wait for 200-500 updates
  • Monitor EMA Error: Should decrease over time
  • Watch TD-Error: Convergence indicator
  • Enable debug panel: See learning metrics

Recommended Settings

Timeframe: H1 (1 hour) or H4 (4 hours)
Asset: BTC, ETH, major forex pairs
History: At least 1000 bars for initial training
Auto Optimize: Enabled
Show Debug Panel: Enabled (while learning)

๐Ÿ“Š Performance Metrics

The system tracks several metrics to show learning progress:

Training Metrics

  • TD-Error: Should decrease from ~0.5 to <0.1
  • EMA Error: Smoothed error, should converge
  • Update Count: Number of gradient updates
  • Epsilon: Exploration rate (10% โ†’ 2%)

Q-Value Metrics

  • Avg Max Q: Average of maximum Q-values
  • Avg Old Q: Average of current Q-predictions
  • Avg Target Q: Average of target Q-values
  • Zero TD Count: How many samples have TD-error โ‰ˆ 0

Example Learning Curve

Updates 0-500:
  TD-Error: 0.5 โ†’ 0.3 (high, exploring)
  EMA Error: 0.7 โ†’ 0.5 (decreasing)
  Epsilon: 0.10 โ†’ 0.08 (still exploring)

Updates 500-2000: TD-Error: 0.3 โ†’ 0.15 (converging) EMA Error: 0.5 โ†’ 0.2 (good convergence) Epsilon: 0.08 โ†’ 0.04 (exploitation phase)

Updates 2000+: TD-Error: 0.15 โ†’ 0.05 (converged!) EMA Error: 0.2 โ†’ 0.1 (stable) Epsilon: 0.04 โ†’ 0.02 (minimal exploration)


๐ŸŽ“ Educational Value

Perfect for learning:

  • How LSTM networks work
  • Deep Q-Learning implementation from scratch
  • Reinforcement Learning for trading
  • Neural network training (Adam, BPTT)
  • Experience Replay and prioritization
  • Advanced ML techniques in constrained environment

Code Structure

๐Ÿ“ Project Root
โ”œโ”€โ”€ ๐Ÿ“„ mlsupertrendultimate.pine  (Main indicator)
โ”œโ”€โ”€ ๐Ÿ“„ README.md                     (This file)
โ”œโ”€โ”€ ๐Ÿ“„ LICENSE                       (MIT)
โ”œโ”€โ”€ ๐Ÿ“„ CHANGELOG.md                  (Version history)
โ”œโ”€โ”€ ๐Ÿ“ docs/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ ARCHITECTURE.md          (Detailed architecture)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ TRAINING.md              (Training guide)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ FAQ.md                   (Common questions)
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ RESEARCH.md              (Research notes)
โ””โ”€โ”€ ๐Ÿ“ images/
    โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ screenshot_1.png         (Trading signals)
    โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ screenshot_2.png         (Debug panel)
    โ””โ”€โ”€ ๐Ÿ–ผ๏ธ architecture.png         (System diagram)

๐Ÿค Contributing

Contributions are welcome! Please read CONTRIBUTING.md for guidelines.

Ways to Contribute

  • ๐Ÿ› Bug reports - Found an issue? Open an issue!
  • ๐Ÿ’ก Feature requests - Have an idea? Share it!
  • ๐Ÿ“ Documentation - Improve README, add examples
  • ๐Ÿ”ง Code - Submit pull requests
  • โญ Star the repo - Show your support!

Development

git clone https://github.com/YOUR_USERNAME/ml-supertrend-ultimate.git
cd ml-supertrend-ultimate

Edit mlsupertrendultimate.pine

Test on TradingView

Submit pull request


๐Ÿ“š References

This project implements techniques from cutting-edge research:

  • Deep Q-Learning
- Playing Atari with Deep Reinforcement Learning (Mnih et al., 2013)
  • Prioritized Experience Replay
- Prioritized Experience Replay (Schaul et al., 2015)
  • LSTM Networks
- Long Short-Term Memory (Hochreiter & Schmidhuber, 1997)
  • Adam Optimizer
- Adam: A Method for Stochastic Optimization (Kingma & Ba, 2014)

๐Ÿ“ž Contact & Support


โญ Show Your Support

If you find this project useful:

  • โญ Star the repository
  • ๐Ÿ”„ Share with others
  • ๐Ÿ“ Write about it
  • ๐Ÿค Contribute

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License

Copyright (c) 2025 [Diogenov Pavel]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

[Full MIT License text in LICENSE file]


๐Ÿ™ Acknowledgments

  • Created with: Claude Sonnet 4.5 by Anthropic ๐Ÿค–
  • Inspired by: DeepMind's DQN research
  • Built in: Altai Krai, Barnaul, Russia ๐Ÿ‡ท๐Ÿ‡บ
  • For: The trading & ML community ๐ŸŒ

๐Ÿ“ˆ Roadmap

v1.0 (Current)

  • โœ… LSTM + DQN implementation
  • โœ… Prioritized Experience Replay
  • โœ… Adam optimizer
  • โœ… Real-time training

v1.1 (Planned)

  • [ ] Multi-asset support
  • [ ] Improved reward shaping
  • [ ] Advanced visualization
  • [ ] Performance analytics

v2.0 (Future)

  • [ ] Dueling DQN architecture
  • [ ] Double Q-Learning
  • [ ] Rainbow DQN
  • [ ] Attention mechanisms

Made with โค๏ธ in Russia ๐Ÿ‡ท๐Ÿ‡บ

Star โญ this repo if you found it useful!

Star History Chart

๐Ÿ”— More in this category

ยฉ 2026 GitRepoTrend ยท PavelML-Dev/ML-Trading-Systems ยท Updated daily from GitHub