OPEN-SOURCE SCRIPT
更新済 Adaptive Trend Structure Engine v2

Adaptive Market Structure Engine (ATSE) is a technical analysis tool designed to help visualize and interpret evolving market structure in real time. It focuses on detecting shifts in price behavior by constructing a synthetic structure model that reacts dynamically to volatility and directional movement.
Unlike traditional indicators that rely solely on fixed moving averages or standard oscillators, this script builds a behavior-based price structure that adapts to changing market conditions. It does this by generating dynamic upper and lower structure thresholds, which act as reference boundaries for price movement.
📊 How It Works
The core of the indicator is a synthetic price model that simulates structural movement based on a configurable sensitivity parameter. Price action is continuously evaluated against adaptive upper and lower levels, which are recalculated according to selected structure logic (ATR-based, fixed sensitivity, or price fraction methods).
When price breaks beyond these adaptive boundaries, the system interprets this as a potential structural shift in market direction. These shifts are then classified as trend transitions.
🔄 Trend Detection Logic
The indicator tracks directional changes in the synthetic structure and identifies when a transition occurs from upward to downward structure (or vice versa). These transitions are visually marked on the chart to highlight potential changes in market behavior.
To improve readability, only the first bar of each structural shift is marked, reducing noise and repetitive signals.
📐 Fibonacci Structure Visualization
After each confirmed trend shift, the indicator generates a set of Fibonacci-based dynamic zones starting from the current reference price. These levels are not predictive targets but are instead used as visual framework zones, helping to understand possible areas of price interaction during a trend phase.
Each zone is spaced proportionally based on user-defined sensitivity settings, allowing the structure to expand or contract depending on volatility conditions.
📉 Momentum Context (Optional)
The script also includes an internal momentum calculation based on deviation from a dynamic center line. This helps provide additional context to structural movements without acting as a standalone signal generator.
A normalization option is available to smooth momentum behavior across extended trend phases.
⚙️ Customization Options
Users can adjust:
Structure sensitivity (brick size behavior)
Calculation method (ATR / price-based / classic)
Price source model (close-based or OHLC hybrid)
Fibonacci spacing intensity
Momentum normalization and oscillation behavior
This allows the indicator to be adapted across different assets and timeframes.
🎯 Purpose
The main goal of this tool is to:
Visualize market structure transitions
Provide a clearer view of trend shifts
Offer adaptive structural zones for context
Reduce noise from traditional indicator-based signals
It is intended for educational and analytical use to assist in understanding price behavior rather than to generate direct trading signals.
⚠️ Disclaimer
This script does not provide financial advice. All signals and visual elements are based on mathematical transformations of price data and should be used as part of a broader analysis framework.
Unlike traditional indicators that rely solely on fixed moving averages or standard oscillators, this script builds a behavior-based price structure that adapts to changing market conditions. It does this by generating dynamic upper and lower structure thresholds, which act as reference boundaries for price movement.
📊 How It Works
The core of the indicator is a synthetic price model that simulates structural movement based on a configurable sensitivity parameter. Price action is continuously evaluated against adaptive upper and lower levels, which are recalculated according to selected structure logic (ATR-based, fixed sensitivity, or price fraction methods).
When price breaks beyond these adaptive boundaries, the system interprets this as a potential structural shift in market direction. These shifts are then classified as trend transitions.
🔄 Trend Detection Logic
The indicator tracks directional changes in the synthetic structure and identifies when a transition occurs from upward to downward structure (or vice versa). These transitions are visually marked on the chart to highlight potential changes in market behavior.
To improve readability, only the first bar of each structural shift is marked, reducing noise and repetitive signals.
📐 Fibonacci Structure Visualization
After each confirmed trend shift, the indicator generates a set of Fibonacci-based dynamic zones starting from the current reference price. These levels are not predictive targets but are instead used as visual framework zones, helping to understand possible areas of price interaction during a trend phase.
Each zone is spaced proportionally based on user-defined sensitivity settings, allowing the structure to expand or contract depending on volatility conditions.
📉 Momentum Context (Optional)
The script also includes an internal momentum calculation based on deviation from a dynamic center line. This helps provide additional context to structural movements without acting as a standalone signal generator.
A normalization option is available to smooth momentum behavior across extended trend phases.
⚙️ Customization Options
Users can adjust:
Structure sensitivity (brick size behavior)
Calculation method (ATR / price-based / classic)
Price source model (close-based or OHLC hybrid)
Fibonacci spacing intensity
Momentum normalization and oscillation behavior
This allows the indicator to be adapted across different assets and timeframes.
🎯 Purpose
The main goal of this tool is to:
Visualize market structure transitions
Provide a clearer view of trend shifts
Offer adaptive structural zones for context
Reduce noise from traditional indicator-based signals
It is intended for educational and analytical use to assist in understanding price behavior rather than to generate direct trading signals.
⚠️ Disclaimer
This script does not provide financial advice. All signals and visual elements are based on mathematical transformations of price data and should be used as part of a broader analysis framework.
リリースノート
### How It Works — Technical Details**Synthetic Structure Model**
The core of the indicator is a brick-based synthetic price model
inspired by noise-filtering chart types. Rather than plotting price
directly, the script maintains a synthetic close value that only
updates when price moves a full brick size in either direction:
— upperLevel = prevSynthetic + brickSize
— lowerLevel = prevSynthetic − brickSize
If srcHigh exceeds upperLevel, syntheticClose advances to upperLevel.
If srcLow falls below lowerLevel, syntheticClose drops to lowerLevel.
Otherwise syntheticClose remains unchanged.
This filtering mechanism eliminates sub-threshold price fluctuations
and only registers movement when price commits to a directional move
larger than the defined sensitivity unit. Trend direction is then
derived purely from whether syntheticClose moved up or down on the
most recent update.
**Brick Size Calculation — Three Methods**
The sensitivity unit (brickSize) adapts based on the selected method:
— ATR: brickSize = ta.atr(N) where N = brickInput rounded to integer.
The brick adapts to recent volatility — wider in volatile markets,
narrower in calm markets.
— Price Fraction: brickSize = close / brickInput. The brick scales
proportionally to current price, keeping sensitivity consistent
across different price levels and asset classes.
— Classic: brickSize = brickInput as a fixed absolute value.
Suitable when a known price unit is appropriate for the asset.
**Timeframe-Adaptive Length Scaling**
The lookback length (scaledLen) is not a fixed user input. Instead
it is computed dynamically from the Base Timeframe Factor and the
current chart timeframe multiplier:
— Intraday charts with multiplier ≥ 1:
lenRaw = baseTF / multiplier × 7
— Intraday charts with multiplier < 60:
lenRaw = (60 / multiplier) × 24 × 7
— All other timeframes: lenRaw = 7
scaledLen is then clamped to a minimum of 5 using math.max(). This
ensures the center line and momentum calculations always use a
contextually appropriate number of bars regardless of which
timeframe the indicator is applied to.
**Center Line and Momentum**
The dynamic center line is the midpoint between the highest high and
lowest low over scaledLen bars:
centerLine = (ta.highest(high, scaledLen) + ta.lowest(low, scaledLen)) / 2
Momentum is calculated as a linear regression of (close − centerLine)
over scaledLen bars using ta.linreg(). This measures how far and in
what direction price is deviating from its midrange, and how that
deviation is trending. When oscillation mode is enabled, momentum
is inverted during downtrends to maintain a consistent visual
orientation relative to trend direction.
The optional normalization divides cumulative momentum by the number
of bars elapsed since the last trend flip, preventing momentum from
growing unbounded during extended trend phases.
**Fibonacci Zone Generation**
When a trend flip is detected, the previous Fibonacci objects are
fully deleted via deleteFibs() which iterates through all stored
line, label, and box arrays and calls the respective delete
functions before clearing each array.
New zones are drawn from the opening price of the signal bar,
projected in the trend direction using:
priceLevel = basePrice + direction × (brickSize × 5 × fibSpacing) × fibRatio
Seven standard ratios are applied: 0, 0.236, 0.382, 0.5, 0.618,
0.786, 1.0. Background zone boxes are drawn between consecutive
ratio pairs. Line and label colors are generated using
color.from_gradient() mapping the ratio range 0→1 to blue→red,
so lower zones appear cooler and upper zones appear warmer.
**Price Source Mode**
Three modes control which price values are used for synthetic
structure evaluation:
— Close: both srcHigh and srcLow equal close; structure updates
only on close-to-close movement
— Open / Close: srcHigh = max(open, close), srcLow = min(open, close);
structure responds to candle body range
— High / Low: srcHigh = high, srcLow = low; structure responds to
full candle wick range, most sensitive mode
### How To Use
1. Structure Calculation Method:
— Use ATR for volatile assets (crypto, small caps) where
sensitivity should adapt to market conditions
— Use Price Fraction for cross-asset consistency; set
brickInput to 100–500 (higher = less sensitive)
— Use Classic for fixed-pip or fixed-point instruments
2. Base Timeframe Factor controls the adaptive length scaling —
set it to match your primary analysis timeframe in minutes
(e.g. 60 for 1H analysis, 240 for 4H analysis)
3. Price Source Mode:
— Close: slowest, fewest flips, suits trend-following
— Open / Close: balanced sensitivity, default recommended
— High / Low: fastest, most responsive, suits volatile markets
4. Fibonacci Spacing multiplies the projected zone width —
increase for wider visual spread, decrease for tighter zones
5. Trend flip signals (🔼 🔽) appear only on the first bar of
each structural shift — these are the primary signal events
6. Fibonacci zones redraw on every trend flip and extend to the
right — use them as contextual reference areas, not price targets
7. Enable Normalization to flatten momentum behavior during long
uninterrupted trend phases
### Originality
This script is an original work combining a noise-filtering
synthetic price structure model with timeframe-adaptive length
scaling and signal-triggered Fibonacci zone generation. The core
innovation is the synthetic close mechanism: by advancing price
only in full brick-size increments, the indicator filters out
sub-threshold volatility and produces trend direction signals
based on committed directional movement rather than raw price
fluctuation. The three-method brick size system (ATR, Price
Fraction, Classic), combined with dynamic length scaling from
timeframe metadata and momentum normalized by bars-since-flip,
represents the author's own original engine design. The
Fibonacci zone module, which redraws from the signal bar's
open price on every structural flip using gradient-colored
objects, is integrated directly into the trend detection
system rather than being a standalone drawing tool. This
complete implementation is not derived from any existing
published script.
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。