OPEN-SOURCE SCRIPT

ChunkbrAI-NN INDI

70
ChunkbrAI-NN INDI: The Neural Network Odyssey

A Native Pine Script Neural Network Research Engine

Welcome to ChunkbrAI-NN 5.3. This is not a standard technical indicator; it is a proof-of-concept Artificial Intelligence engine built entirely from scratch within Pine Script.

Neural Networks typically require iterating over massive datasets, a task that usually times out on TradingView. ChunkbrAI solves this by introducing a novel "Chunking Architecture"—a system that breaks history into digestible learning blocks and trains a Multilayer Perceptron (MLP) using a "Chunking" approach.

It features a living ecosystem where neurons have "genes," grow mature, and adapt to market regimes using a highly sophisticated Context-Aware normalization engine.

-----------------------------------------------------------
The Core Concept: "The Time Wheel"

To bypass Pine Script's execution limits, this script does not train linearly from the beginning of time. Instead, it operates like a spinning wheel of experience.

* The Chunk System: On every bar update, the engine reaches back into history (up to 5000 bars) and grabs random or sequential "Chunks" of data. It treats these chunks as isolated training samples.

* Experience Replay: By constantly revisiting past market scenarios (Chunks), the network slowly converges its weights, learning to recognize patterns across different eras of price action.


-----------------------------------------------------------
Architecture & Modules

A. The Neural Core (MLP)
At the heart is a raw neural network built with arrays:
* Topology: A dense network with a customizable Hidden Layer (Default: 60 Neurons).
* Timewarp (Stride): When enabled, the network uses "dilated" inputs (skipping bars, e.g., 1, 3, 5...). This increases the network's Field of View without increasing computational load.
* Forecasting: The network outputs a standardized prediction which is then de-normalized to project the future price path on your chart.

B. The Context System (The "Eyes")
Raw prices confuse neural networks. A $1000 move in Bitcoin is massive in 2016 but noise in 2024. ChunkbrAI uses a relativistic Context System:
* Regime Detection: It uses a Zero-Lag Moving Average (ZLMA) and Non-Linear Regression to measure the current market "Vibe" (Volatility & Trend).
* Dynamic Normalization: The inputs are scaled based on this context. If the market is volatile, the data is compressed; if calm, it is expanded. This ensures the brain receives consistent signal patterns regardless of the absolute price.

C. The Gene System (Neuro-Plasticity)
This is the experimental "biology" layer. Neurons are not just static math; they have life cycles.
* Maturity: Neurons start "Young" (highly plastic, high mutation rate). As they successfully reduce error, they become "Wise" (stable, low mutation).
* Mutation: If a "Wise" neuron begins failing (high error), it is demoted and forced to mutate. This allows the brain to "forget" obsolete behaviors and adapt to new market paradigms automatically.
* Profiles: You can initialize the brain with different personalities (e.g., Dreamer, Young Chaos, Zen Monk).

D. The Brain Scheduler (Adaptive Learning)
A static Learning Rate (LR) is inefficient. The Brain Scheduler acts as the heartbeat:
* Panic vs. Flow: It monitors the derivative of the error. If the error spikes (Panic), the Scheduler slows down learning to prevent the model from exploding. If the error smooths out (Flow), it accelerates learning (Infinite LR Mode).

-----------------------------------------------------------
Forecasting Modes

The script provides two distinct ways to visualize the future:

1. Direct Projection (Green Line):
The network takes the current window of price action and predicts the immediate next step. If Timewarp is active, it interpolates the result to draw a smooth curve.

2. Autoregression (Cyan Line):
Available in "Auto" mode. The network feeds its *own* predictions back into itself as inputs to generate multi-step forecasts.
* Wave Segmentation: The script intelligently guesses the current market cycle length and attempts to project that specific duration forward.

-----------------------------------------------------------
Operation Manual

The script has two distinct training loops: first, when you add it to a chart, Pine runs through the available historical bars once, and this initial history pass is the main training phase where the network iterates chunk-by-chunk using your configured chunk count/iterations (e.g., if chunk count is 3, it performs 3 chunk updates per step), but pushing chunk count, iterations, or model sizing too high can hit Pine’s execution limits; after that, once real-time candles start printing, the script can either keep training (weights continue updating) or freeze the weights and run inference only, producing predictions from the learned parameters, and if live training is enabled it can also simulate “bars-back” style training during live mode by iterating across prior bars as if doing another history pass—which again can run into limits if chunks/iterations/sizing are too heavy—so when changing parameters to evaluate behavior you change them carefully and individually, because multiple simultaneous increases make it hard to attribute effects and can more easily trigger those execution constraints.

Weight Persistence (Save/Load):

Pine Script can’t write files or persist weights directly, so ChunkbrAI uses a library-based workaround that’s honestly tricky and kind of a pain: you enable the weight-export alerts so the script emits the weights (W1/W2/biases etc.) as text, and those payloads are chunked as well; then, outside TradingView, I use a separate Python script to parse the alert emails, reconstruct and format the chunked weights properly, and generate the corresponding library code files; after that, the libraries have to be published/updated, and only then can the main script “restore” by reading the published lib constants on chart load, effectively starting with the pre-trained weights instead of relying purely on the fresh history-run training pass. I don’t recommend this process unless you really have to—it’s fragile and high-effort—but until TradingView implements some simple built-in data storage for scripts, it’s basically the only practical way to save and reload your models.


-----------------------------------------------------------
Limitations & Notes

* Calculation Limits: This script pushes Pine Script to its absolute edge. If you increase Chunk Size or Hidden Size too much, you WILL hit execution limits. Use the defaults as a baseline.
* Non-Deterministic: Because the "Wheel" picks random chunks for training, two instances of this script might evolve slightly different brains unless you use the Restore Weights feature.
* Experimental: This is a research tool designed to explore Neural Networks and Genetic Algorithms on the chart. Treat it as an educational engine, not financial advice.

Credits: Concept and Engineering by funkybrown.

Declinazione di responsabilità

Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.