OPEN-SOURCE SCRIPT

INFLECTION NEXUS - SPA

745
INFLECTION NEXUS - SPA (Shadow Portfolio Adaptive)

Foreword: The Living Algorithm

For decades, technical analysis has been a conversation between a trader and a static chart. We apply our indicators with their fixed-length inputs, and we hope that our rigid tools can somehow capture the essence of a market that is fluid, chaotic, and perpetually evolving. When our tools fail, we are told to "adapt." But what if the tools themselves could learn that lesson? What if our indicators could adapt not just for us, but with us?

This script, INFLECTION NEXUS - SPA, is the realization of that vision. It is an advanced analytical framework built around a revolutionary core: the Shadow Portfolio Adaptive (SPA) Engine. The buy and sell signals you see on the chart are an evolution of the logic from my previous work, "Turning Point." However, this is not a simple combination of two scripts. The SPA engine so fundamentally transforms the nature of the analysis that it creates an entirely new class of indicator. This publication is a showcase of that groundbreaking, self-learning engine.

This system is undeniably complex. When you first load it, the sheer volume of information may feel overwhelming. That is a testament to the depth of its analysis. This guide is designed to be your comprehensive manual, to break down every single component, every color, every number, into simple, understandable concepts. By the end of this document, you will not only master its functions but will also possess a deeper understanding of the market dynamics it is designed to reveal.

Chapter 1: The Paradigm Shift - Why the SPA Engine is a Leap Forward
To grasp the innovation here, we must first deconstruct the severe limitations of traditional "adaptive" indicators.

Part A: The Traditional Model - Driving by the Rear-View Mirror
Conventional "adaptive" systems are fundamentally reactive. They operate on a slow, inefficient loop: they wait for their own specific, biased signal to fire, wait for that trade to close, and only after a long and statistically significant "warm-up" period of 50-100 trades do they finally make a small, retrospective adjustment. They are always adapting to a market that no longer exists.

Part B: The SPA Model - The Proactive Co-Pilot
The Shadow Portfolio Adaptive (SPA) engine is a complete re-imagining of this process. It is not reactive; it is proactive, data-saturated, and instantly aware.
Continuous, Unbiased Learning: The SPA engine does not wait for a signal to learn. Its Shadow Portfolio is constantly running 5-bar long and short trades in the background. It learns from every single 5-bar slice of market action, giving it a continuous, unbiased stream of performance data. It is the difference between reading a textbook chapter and having a live sparring partner in the ring 24/7.

Instantaneous Market Awareness - The End of the "Warm-Up": This is the critical innovation. The SPA engine does not require a 100-trade warm-up period. The learning does not start after 50 trades; it begins on the 6th bar of the chart when the first shadow trade closes. From that moment on, the system is market-aware, analyzing data, and capable of making intelligent adjustments. The SPA engine is not adapting to old wins and losses. It is adapting, in near real-time, to the market's ever-shifting character, volatility, and personality.

Chapter 2: The Anatomy of the SPA Engine - A Granular Deep Dive
The engine is composed of three primary systems that work in a sophisticated, interconnected symphony.

Section 1: The Shadow Portfolio (The Information Harvester)
What it is, Simply: Think of this as the script's eyes and ears. It's a team of 10 virtual traders (5 long, 5 short) who are constantly taking small, quick trades to feel out the market.
How it Works, Simply: On every new bar, a new "long" trader and a new "short" trader enter the market. Exactly 5 bars later, they close their positions. This cycle is perpetual and relentless.
The Critical 'Why': Because these virtual traders enter and exit based on a fixed time (5 bars), not on a "good" or "bad" signal, their results are completely unbiased. They are simply measuring: "What happened to price over the last 5 bars?" This provides the raw, untainted truth about the market's behavior that the rest of the system needs to learn effectively.
The Golden Metric (ATR Normalization): The engine doesn't just look at dollar P&L. It's smarter than that. It asks a more intelligent question: "How much did this trade make relative to the current volatility?"
Analogy: Imagine a flea and an elephant. If they both jump 1 inch, who is more impressive? The flea. The SPA engine understands this. A $10 profit when the market is dead quiet is far more significant than a $10 profit during a wild, volatile swing.
The Formula: realized_atr = (close - trade.entry) / trade.atr_entry. It takes the raw profit and divides it by the Average True Range (a measure of volatility) at the moment of entry. This gives a pure, "apples-to-apples" score for every single trade, which is the foundational data point for all learning.

Section 2: The Cognitive Map (The Long-Term Brain)
What it is, Simply: This is the engine's deep memory, its library of experiences. Imagine a giant, 64-square chessboard (8x8 grid). Each square on the board represents a very specific type of market environment.
The Two Dimensions of Thought (The 'How'): How does it know which square we are on? It looks at two things:
The Market's Personality (X-Axis): Is the market behaving like a disciplined soldier, marching in a clear trend? Or is it like a chaotic, unpredictable child, running all over the place? The engine calculates a "Regime" score to figure this out.
The Market's Energy Level (Y-Axis): Is the market sleepy and quiet, or is it wide-awake and hyperactive? The engine measures "Normalized Volatility" to determine this.
The Power of Generalization (The 'Why'): When a Shadow Portfolio trade closes, its result is recorded in the corresponding square on the chessboard. But here's the clever part: it also shares a little bit of that lesson with the squares immediately next to it (using a Gaussian Kernel).
Analogy: If you touch a hot stove and learn "don't touch," your brain is smart enough to know you probably shouldn't touch the hot oven door next to it either, even if you haven't touched it directly. The Cognitive Map does the same thing, allowing it to make intelligent inferences even in market conditions it has seen less frequently. Each square remembers what indicator settings worked best in that specific environment.

Section 3: The Adaptive Engine (The Central Nervous System)
What it is, Simply: This is the conductor of the orchestra. It takes information from all other parts of the system and decides exactly what to do.
The Symphony of Inputs: It listens to three distinct sources of information before making a decision:
The Short-Term Memory (Rolling Stats): It looks at the performance of the last rollN shadow trades. This is its immediate, recent experience.
The Long-Term Wisdom (Cognitive Map): It consults the grand library of the Cognitive Map to see what has worked best in the current market type over the long haul.
The Gut Instinct (Bin Learning): It keeps a small "mini-batch" of the most recent trades. If this batch shows a very strong, sudden pattern, it can trigger a rapid, reflexive adjustment, like pulling your hand away from a flame.
The Fusion Process: It then blends these three opinions together in a sophisticated way. It gives more weight to the opinions it's more confident in (e.g., a Cognitive Map square with hundreds of trades of experience) and uses your Adaptation Intensity (dialK) input to decide how much to listen to its "gut instinct." The final decision is then smoothed to ensure the indicator's parameters change in a stable, intelligent way.

Chapter 3: The Control Panel - A Novice's Guide to Every Input
This is the most important chapter. Let's break down what these confusing settings actually do in the simplest terms possible.

--- SECTION 1: THE DRIVER'S SEAT (SIGNAL ENGINE & BASE SETTINGS) ---
🧾 Signal Engine (Turning Point):
What it is: These are the rules for the final BUY and SELL signs.
Think of it like this: The SPA engine is the smart robot that tunes your race car. These settings are you, the driver, telling the robot what kind of race you're in.
Enable Reversal Mode: You tell the robot, "I want to race on a curvy track with lots of turns." The robot will tune the car to be agile for catching tops and bottoms.
Enable Breakout Mode: You tell the robot, "I want to race on a long, straight track." The robot will tune the car for pure speed to follow the trend.
Require New Extreme: This is a quality filter. It tells the driver, "Don't look for a turn unless we've just hit a new top speed on the straightaway." It makes sure the reversal is from a real extreme.
Min Bars Between Signals: This is the "pit stop" rule. You're telling the robot, "After you show me a sign, wait at least 10 bars before showing another one, so I don't get confused."
⚡ ATR Bands (Base Inputs):
What they are: These are the starting settings for your car before the robot starts tuning it. These are your factory defaults.
Sensitivity: This is the "Bump Detector." A low number means the car feels every tiny pebble on the road. A high number means it only notices the big speed bumps. You want to set it so it notices the important bumps (real market structure) but ignores the pebbles (noise).
ATR Period & Multiplier: These set the starting size of the "safety lane" (the green and blue bands) around your car. The robot's main job is to constantly adjust the size of this safety lane to perfectly fit the current road conditions.

📊 & 📈 Filter Settings (RSI & Volume):
What they are: These are your co-pilot's confirmation checks.
Enable RSI Filter: Your co-pilot will check the "Engine Temperature" (RSI). He won't let you hit the gas (BUY) if the engine is already overheating (overbought).
RSI Length & Lookbacks: These tune how your co-pilot's temperature gauge works. The defaults are standard.
Require Volume Spike: Your co-pilot will check the "Crowd Noise" (Volume). He won't give you a signal unless he hears the crowd roar, confirming that a lot of people are interested in this move.

🎯 Signal Quality Control:
Enable Major Levels Only: This tells your co-pilot to be extra picky. He will only confirm signals that happen after a huge, powerful move, ignoring all the small stuff.
--- SECTION 2: THE ROBOT'S BRAIN (ENGINE & LEARNING CONTROLS) ---

🎛️ Master Control:
Adaptation Intensity (dialK): THIS IS THE ROBOT'S PERSONALITY DIAL.
Turn it DOWN (1-5): The robot becomes a "Wise Old Professor." It thinks very slowly and carefully, gathers lots of data, and only makes a change when it is 100% sure. Its advice is very reliable but might come a little late.
Turn it UP (15-20): The robot becomes a "Hyper-Reactive Teenager." It has a short attention span, reacts instantly to everything it sees, and changes its mind constantly. It's super-fast to new information but might get faked out a lot.
The Default (10): A "Skilled Professional." The perfect balance of thoughtful and responsive. Start here.

🧠 Adaptive Engine:
Enable Adaptive System: This is the main power button for your robot. Turn it off, and you're driving a normal, non-smart car. Turn it on, and the robot takes over the tuning.
Use Shadow Cycle: This turns on the robot's "practice laps." The robot can't learn without practicing. This must be on for the robot to work.
Lock ATR Bands: This is a visual choice. "Locked" means the safety lanes on your screen stay where your factory defaults put them (the robot still makes changes to the signals in the background). "Unlocked" means you see the safety lanes moving and changing shape in real-time as the robot tunes them.
🎯 Learning (Global + Risk):
What they are: These are the deep-level settings for how your robot's brain processes information.

Rolling Window Size: This is the robot's "Short-Term Memory." How many of the last few practice laps should it remember? A small number means it only cares about what just happened. A big number means it remembers the last hour of practice.
Learn Rate & Smooth Alpha: This is "How big of a change should the robot make?" and "How smoothly should it make the change?" Think of it as turning the steering wheel. A high learn rate is like yanking the wheel; a low one is like a gentle turn. The smoothing makes sure the turn is graceful.
WinRate Thresholds & PnL Cap: These are rules for the robot's learning. They tell it what a "good" or "bad" outcome looks like and tell it to ignore crazy, once-in-a-lifetime events so its memory doesn't get corrupted.

--- SECTION 3: THE GARAGE (RISK, MEMORY & VISUALS) ---

⚠️ Risk Management:
What they are: These are safety rules you can give to your co-pilot for your own awareness. They appear on the dashboard.
The settings: You can set a max number of trades, a max loss for the day, and a "time out" period after a few losses.
Apply Risk to Shadow: This is an important switch. If you turn this ON, your safety rules also apply to the robot's practice laps. If you hit your max loss, the robot stops practicing and learning. It's recommended to leave this OFF so the robot can learn 24/7, even if you have stopped trading.

🗺️ Cognitive Map, STM & Checkpoints:
What it is: The robot's "Long-Term Memory" or its entire library of racing experience.
Use Cognitive Map & STM: These switches turn on the long-term and short-term memory banks. You want these on for the smartest robot.
Map Settings (Grid, Sigma, Half-Life): These are very advanced settings for neuroscientists. They control how the robot's brain is structured and how it forgets old information. The defaults are expertly tuned.
The Checkpoint System: This is the "Save Your Game" button for the robot.
To Save: Check Emit Checkpoint Now. Go to your alert log, and you will see a very long password. Copy this password.
To Load: Paste that password into the Memory Checkpoint box. Then, check Apply Checkpoint On Next Bar. The robot will instantly download all of its saved memories and experience.

🎨 Visuals & 🧩 Display Params:
What they are: These are all about how your screen looks.
You can control everything: The size and shape of the little diamonds (Entry Orbs), whether you see the purple Adapt Pulse, and where the Dashboards appear on your screen. You can change the Theme to Dark, Light, or Neon. These settings don't change how the robot thinks, only how it presents its information to you.

Chapter 4: The Command Center - Decoding the Dashboard

PANEL A (INFLECTION NEXUS): Your high-level mission control, showing the engine's classification of the current Market Context and the performance summary of the Shadow Portfolio.

PANEL B (SHADOW PORTFOLIO ADAPTIVE): Your deep diagnostic screen.

Performance Metrics: View advanced risk-adjusted stats like the Sharpe Ratio to understand the quality of the market movements the engine is learning from.

Adaptive Parameters (Live vs Base): THIS IS THE MOST CRITICAL SECTION. It shows the engine's Live parameters right next to your (Base) inputs. When the Live values deviate, the engine is communicating its learned wisdom to you. For example, a Live ATR Multiplier of 2.5 versus your Base of 1.4 is the engine telling you: "Caution. The market is currently experiencing high fake-outs and requires giving positions more room to breathe." This section is a direct translation of the engine's learning into actionable insight.

Chapter 5: Reading the Canvas - On-Chart Visuals
The Bands (Green/Blue Lines): These are not static Supertrend lines. They are the physical manifestation of the engine's current thinking. As the engine learns and adapts its ATR Period and Multiplier, you will see these bands widen, tighten, and adjust their distance from price. They are alive.

The Labels (BUY/SELL): These are the final output of the "Turning Point" logic, now supercharged and informed by the fully adaptive SPA engine.

The Purple Pulse (Dot and Background Glow): This is your visual cue that the engine is "thinking." Every time you see this pulse, it means the SPA has just completed a learning cycle and updated its parameters. It is actively recalibrating itself to the market.

Chapter 6: A Manifesto on Innovation and Community
I want to conclude with a personal note on why I dedicate countless hours to building systems like this and sharing them openly.

My purpose is to drive innovation, period. I am not in this space to follow the crowd or to re-package old ideas. The world does not need a 100th version of a slightly modified MACD. Real progress, real breakthroughs, come from venturing into the wilderness, from asking "what if?" and from pursuing concepts that lie at the very edge of possibility.

I am not afraid of being wrong. I am not afraid of being bested by my peers. In fact, I welcome it. If another developer takes an idea from this engine, improves it, and builds something even more magnificent, that is a profound win for our entire community. The only failure I recognize is the failure to try. The only trap I fear is the creative complacency of producing sterile, recycled work just to appease the status quo.

I love this community, and I believe with every fiber of my being that we have barely scratched the surface of what can be discovered and created. This script is my contribution to that shared journey. It is a tool, an idea, and a challenge to all of us: let's keep pushing.

DISCLAIMER: This script is an advanced analytical tool provided for educational and research purposes ONLY. It does not constitute financial advice. All trading involves substantial risk of loss. Past performance is not indicative of future results. Please use this tool responsibly and as part of a comprehensive trading plan.

As the great computer scientist Herbert A. Simon, a pioneer of artificial intelligence, famously said:
"Learning is any process by which a system improves performance from experience."

*Tooltips were updated with a comprehensive guide

May this engine enhance your experience.
— Dskyz, for DAFE Trading Systems

כתב ויתור

המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.