OPEN-SOURCE SCRIPT
Güncellendi

[blackcat] L2 Ehlers FRAMA

3 357
Level: 2

Background

John F. Ehlers introuced Fractal Adaptive Moving Average (FRAMA) in 2004.

Function

The objective of using filters is to separate the desired signals from the undesired signals (or noise). The practical application of moving averages often involves a tradeoff between the amount of smoothness required and the amount of lag that can be tolerated. Moving averages have this problem because the price data is not stationary, and may have different bandwidths over different time intervals. Various momentum-adaptive filtering techniques have been developed to take advantage of the nonstationary structure of prices. Adaptive filters have also been developed based on price statistics and the cyclic content of the price data . Dr. Ehlers described a different class of filters that monitor a different measure of temporal nonstationarity and alters their bandwidth in response to this measure.

There is no argument that market prices are fractal. Fractal shapes are self-similar because they tend to have the same roughness and sparseness regardless of the magnification used to view them. If you remove the labels from a 5 minute chart, a daily chart, and a weekly chart you would have difficulty telling them apart. This is the characteristic that makes them fractal. The self-similarity can be defined by the fractal dimension that describes the sparseness at all magnification levels.

To determine the fractal dimension of a generalized pattern, Dr. Ehlers cover the pattern with a number “N” of small objects of several various sizes “s”. As with any moving average, we are forced to compromise between responsiveness and smoothness. FRAMA can be a valuable weapon in your arsenal of technical indicators. It rapidly follows significant changes in price but becomes very flat in congestion zones so that bad whipsaw trades can be eliminated.


Key Signal

Filt --> FRAMA fast line
Trigger --> FRAMA slow line


Pros and Cons

100% John F. Ehlers definition translation, even variable names are the same. This help readers who would like to use pine to read his book.

Remarks

The 63th script for Blackcat1402 John F. Ehlers Week publication.

Readme

In real life, I am a prolific inventor. I have successfully applied for more than 60 international and regional patents in the past 12 years. But in the past two years or so, I have tried to transfer my creativity to the development of trading strategies. Tradingview is the ideal platform for me. I am selecting and contributing some of the hundreds of scripts to publish in Tradingview community. Welcome everyone to interact with me to discuss these interesting pine scripts.

The scripts posted are categorized into 5 levels according to my efforts or manhours put into these works.

Level 1 : interesting script snippets or distinctive improvement from classic indicators or strategy. Level 1 scripts can usually appear in more complex indicators as a function module or element.

Level 2 : composite indicator/strategy. By selecting or combining several independent or dependent functions or sub indicators in proper way, the composite script exhibits a resonance phenomenon which can filter out noise or fake trading signal to enhance trading confidence level.

Level 3 : comprehensive indicator/strategy. They are simple trading systems based on my strategies. They are commonly containing several or all of entry signal, close signal, stop loss, take profit, re-entry, risk management, and position sizing techniques. Even some interesting fundamental and mass psychological aspects are incorporated.

Level 4 : script snippets or functions that do not disclose source code. Interesting element that can reveal market laws and work as raw material for indicators and strategies. If you find Level 1~2 scripts are helpful, Level 4 is a private version that took me far more efforts to develop.

Level 5 : indicator/strategy that do not disclose source code. private version of Level 3 script with my accumulated script processing skills or a large number of custom functions. I had a private function library built in past two years. Level 5 scripts use many of them to achieve private trading strategy.
Sürüm Notları
OVERVIEW
The [blackcat] L2 Ehlers FRAMA indicator implements Ehlers' Fractal Adaptive Moving Average (FRAMA), which dynamically adjusts its smoothing factor based on market volatility to provide adaptive trend following.

FEATURES

• Implements Ehlers' FRAMA algorithm
• Adapts to market volatility automatically
• Provides visual buy/sell signals
• Adjustable N parameter for customization
• Supports custom price inputs

HOW TO USE

Add the indicator to your chart
Configure inputs: • Price: Default is HL2 (High-Low midpoint) • N: Default value is 16 (range: 1-100)
Interpret signals: • Yellow line represents FRAMA • Fuchsia line shows trigger level • Green labels indicate buy signals • Red labels indicate sell signals
LIMITATIONS

• Performance depends on market conditions
• Requires sufficient historical data
• Best suited for longer timeframes

NOTES

• Maximum of 500 labels displayed at once
• Labels are plotted with 1-point offset for visibility
• Alpha values are constrained between 0.01 and 1
• Uses three volatility measurements (N1, N2, N3) for adaptation
Sürüm Notları
█ OVERVIEW

L2 Ehlers FRAMA by blackcat is a faithful Ehlers Fractional Adaptive Moving Average (FRAMA) with a built-in cross-signal engine, ATR-based take-profit / stop-loss levels, alerts and a live position dashboard. The filter adapts its speed to market fractality: fast in trends, slow in ranges.

█ CONCEPTS

FRAMA, introduced by John Ehlers, is an exponential filter whose smoothing factor is derived from the fractal dimension of price over a lookback window:

• High fractality (ranging market) — dimension near 2 — alpha shrinks, the line flattens and ignores noise
• Low fractality (trending market) — dimension near 1 — alpha grows, the line tracks price closely

The script pairs the FRAMA line (Filt) with a delayed copy (Trigger). Crosses between the two define the trading signal, and a position state machine turns those crosses into a complete long / short cycle with exits.

█ HOW TO USE

1 — Add the indicator to any chart. Defaults (N = 16, price = hl2) follow the Ehlers original.
2 — Read entries: green "E" label marks a long entry, red "S" label marks a short entry. The fill between the two lines turns yellow in a long state and fuchsia in a short state.
3 — Read exits: orange "XL / XS" marks appear when price reaches the ATR take-profit or stop-loss of the open position.
4 — Optional: raise Cooldown Bars to suppress back-to-back whipsaw entries; switch off TP/SL if you only want the raw cross signals.

Input Parameters
• Price — source series (default hl2)
• N — FRAMA lookback / cycle length, 4-200 (default 16)
• Alpha Factor — Ehlers decay constant (default 4.6)
• Cooldown Bars — minimum bars between consecutive entries, 0 = off (default 0)
• Same-bar Entry/Exit Exclusivity — blocks TP/SL exits on a signal bar (default on)
• Show TP/SL Levels, ATR Length, Stop Loss (xATR), Take Profit (xATR) — risk engine, defaults on / 14 / 2.0 / 3.0
• Fill Between Lines, Position Background, Show Dashboard — visual toggles

█ FEATURES

• Bidirectional signals governed by a position state machine — no duplicate or contradictory signals, at most one state change per bar
• ATR-adaptive TP/SL reference lines with automatic exit marks (XL-TP / XL-SL / XS-TP / XS-SL)
• Four alertconditions: long entry, short entry, long TP/SL exit, short TP/SL exit
• Background tint and dashboard showing Position, Filt / Trigger, ATR, Entry price and TP / SL
• Fully switchable governance — set Cooldown = 0 and hide the risk tools to recover the classic FRAMA cross behavior

█ SIGNALS

• E (green, below bar) — long entry on Filt crossing above Trigger
• S (red, above bar) — short entry on Filt crossing below Trigger
• XL-TP / XL-SL (orange cross) — long position closed at take-profit / stop-loss
• XS-TP / XS-SL (orange cross) — short position closed at take-profit / stop-loss
• Yellow / fuchsia fill and background — current long / short state
• "Position State" in the data window — +1 long, -1 short, 0 flat

█ IMPLEMENTATION NOTES

Open-source Pine v6. The fractal dimension is computed from N1 / N2 / N3 channel ratios with math.log; signals use ta.crossover / ta.crossunder; risk levels use ta.atr. There are no request.security calls, so nothing repaints across bars; cross signals are still provisional until the bar closes — treat a label as confirmed at bar close.

█ LIMITATIONS

• FRAMA is a trend tool: expect whipsaws in tight ranges despite the adaptive alpha
• TP/SL levels are reference levels for manual trading, not auto-executed orders
• Small N makes the filter nervous, large N adds lag — tune per market and timeframe
• This is an indicator, not a strategy: no backtest statistics are included

█ NOTES

• FRAMA concept by John Ehlers; trigger-line variant and the signal / risk layer by blackcat1402
• MPL 2.0 — free to use and modify, attribution appreciated

═════════════════════════════════════════════════════════════════════════
For questions or feedback, use comments section below.
Feel free to use and modify — attribution appreciated.

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.