ที่อัปเดต:
[blackcat] L2 Ehlers Adaptive Relative Strength Index

Level: 2
Background
John F. Ehlers introuced Adaptive Relative Strength Index in his "Rocket Science for Traders" chapter 21 on 2001.
Function
The concept of taking a difference of lagging line from the original function to produce a leading function suggests extending the concept to moving averages. There is no direct theory for this, but it seems to work pretty well. If taking a 7-bar WMA of prices, that average lags the prices by 2 bars. If taking a 7-bar WMA of the first average, this second average is delayed another 2 bars. If taking the difference between the two averages and add that difference to the first average, the result should be a smoothed line of the original price function with no lag. Sure, Dr. Ehlers tried to use more lag for the second moving average, which
should produce a better predictive curve. However, remember the lesson of Chapter 3 of the book. An analysis curve cannot precede an event. You cannot predict an event before it occurs. If then taking a 4-bar WMA of the smoothed line to create a 1-bar lag, this lagging line becomes a signal when the lines cross. This is as close to an ideal indicator as we can get.
Key Signal
Predict ---> moving average fast line
Trigger ---> moving average slow line
Pros and Cons
100% John F. Ehlers definition translation of original work, even variable names are the same. This help readers who would like to use pine to read his book. If you had read his works, then you will be quite familiar with my code style.
Remarks
The 17th 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.
Background
John F. Ehlers introuced Adaptive Relative Strength Index in his "Rocket Science for Traders" chapter 21 on 2001.
Function
The concept of taking a difference of lagging line from the original function to produce a leading function suggests extending the concept to moving averages. There is no direct theory for this, but it seems to work pretty well. If taking a 7-bar WMA of prices, that average lags the prices by 2 bars. If taking a 7-bar WMA of the first average, this second average is delayed another 2 bars. If taking the difference between the two averages and add that difference to the first average, the result should be a smoothed line of the original price function with no lag. Sure, Dr. Ehlers tried to use more lag for the second moving average, which
should produce a better predictive curve. However, remember the lesson of Chapter 3 of the book. An analysis curve cannot precede an event. You cannot predict an event before it occurs. If then taking a 4-bar WMA of the smoothed line to create a 1-bar lag, this lagging line becomes a signal when the lines cross. This is as close to an ideal indicator as we can get.
Key Signal
Predict ---> moving average fast line
Trigger ---> moving average slow line
Pros and Cons
100% John F. Ehlers definition translation of original work, even variable names are the same. This help readers who would like to use pine to read his book. If you had read his works, then you will be quite familiar with my code style.
Remarks
The 17th 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.
Release Note
Correct label bar_index issueRelease Note
OVERVIEW An adaptive Relative Strength Index (RSI) indicator that dynamically adjusts its calculation based on market cycles. The script combines Ehlers' cycle detection with a modified RSI formula to provide more responsive signals during trending markets.
FEATURES
• Dynamic cycle detection using Hilbert transform
• Adaptive smoothing based on detected market cycles
• Dual RSI plotting with lag comparison
• Visual cycle period display
• Automatic buy/sell signal labeling
HOW TO USE
Select the source price input:
• HL2 (default): Midpoint between high and low prices
• Close: Closing price
• Open: Opening price
Adjust the CycPart parameter (0.5 default):
• Lower values increase sensitivity to short-term cycles
• Higher values prioritize longer-term trends
INDICATOR COMPONENTS
• Primary RSI Line: Yellow line showing current RSI value
• Lag RSI Line: Fuchsia line showing previous RSI value
• Cycle Period: Blue columns indicating detected market cycles
• Signal Labels: Green "BUY" and red "SELL" labels at crossover points
LIMITATIONS
• Requires minimum 6 bars for accurate calculations
• Performance may vary in highly volatile markets
• Cycle detection accuracy depends on market conditions
NOTES
• Indicator uses Ehlers' advanced cycle detection methods
• Parameters can be adjusted for different market conditions
• Best used in conjunction with other technical indicators
Release Note
█ OVERVIEWEhlers Adaptive RSI V2 is a cycle-adaptive momentum oscillator: it re-measures the dominant cycle on every bar and rescales its RSI lookback to it, so momentum stays aligned with the market's own rhythm. V2 turns the original open-source release into a full signal suite with a position state machine, ATR stop-loss / take-profit references, a live dashboard and a complete alert package.
█ CONCEPTS
A classic RSI uses a fixed lookback, so it acts differently in slow and fast markets. This script measures the dominant cycle first, then accumulates RSI over a fraction of it. A lagged copy of the oscillator is the trigger: when the live reading crosses its delayed twin, short-term momentum has turned.
• Cycle-adaptive momentum: the RSI window follows the measured dominant cycle
• Differential trigger: entries fire when the oscillator crosses its lagged value
• Signal governance: a state machine enforces same-bar entry / exit exclusivity plus an optional cooldown
• Layered exits: reverse signal, OB / OS thresholds and ATR risk levels can each close a position
█ HOW TO USE
1 — Add to a candlestick chart; it opens in its own pane
2 — Keep the defaults first: cycle source hl2, CycPart 0.5, lag 2
3 — Read the labels: BUY / SELL = entries, XL / XS = exits, SL / TP = risk exits
4 — Create an alert from the dropdown (8 channels); use "Once Per Bar Close" live
Inputs
• Sources: cycle source (hl2), RSI accumulation source (close)
• Cycle: CycPart 0.5, lag 2, min / max period 6 / 50, Hilbert warm-up 5
• Signals: shorts on, confirm on bar close, exclusivity, reversal, cooldown 0
• Exits: reverse-signal exit on, OB / OS exit off (70 / 30), re-entry RL / RS off (window 1)
• Risk: ATR stop / target on, length 14, stop 2.0, target 3.0
• Filter: HTF direction gate off (240 / EMA 50 / strict off)
• Visuals: OB-OS levels, dominant cycle, labels, background tint, table, offset 1.0
• Alerts: dynamic alert() pushes on
█ FEATURES
• Adaptive RSI with exposed cycle clamp and cycle fraction
• Dual-direction entries with state-machine governance, exclusivity and cooldown
• Three exit sources: reverse signal, OB / OS levels and ATR risk levels
• ATR stop / target references for every open position
• Optional re-entry and HTF direction gate, both off by default
• Position tinting plus a live dashboard (cycle, ATR, risk readings)
• 8 alertcondition channels with matching dynamic alert() messages
█ SIGNALS
• Yellow line: adaptive RSI; purple line: the same oscillator lagged
• Band between them: yellow while momentum rises, purple while it falls
• Blue columns / orange steps: measured dominant cycle period
• Red / green dashed lines: overbought and oversold thresholds
• BUY / SELL: validated long / short entry; XL / XS: exit by signal or threshold
• SL / TP: stop or target hit; RL / RS: re-entry once the anchor breaks
• Green / red pane background: position state; no tint = flat
• Dashboard: position, oscillator, lagged value, cycle, ATR, entry, stop, target, HTF gate, cooldown
• Data window: Position State, Stop Loss, Take Profit, ATR, HTF Direction
█ IMPLEMENTATION NOTES
Open-source single-file Pine Script v6. The dominant cycle comes from a smoothed, detrended series through a Hilbert-style in-phase / quadrature decomposition and a homodyne discriminator; it is clamped, smoothed, then used to size the RSI window. Triggers use ta.crossover / ta.crossunder between the oscillator and its lagged copy, so every signal is edge-triggered; ta.atr drives the risk references. The HTF gate reads closed HTF data with the [1] offset and lookahead — no repaint. Alerts resolve on confirmed bars (global alertcondition + alert.freq_once_per_bar_close). na / division guards protect the math; labels are capped at 500.
█ LIMITATIONS
• Cycle measurement needs warm-up; no signal before warm-up + max-cycle window
• Differential triggers turn often in chop; raise the cooldown or enable the HTF gate
• Risk levels are references only — an indicator, not an order manager
• The pane is scaled 0–100, so stop / target prices live in the data window
• Re-entry can whipsaw in ranges; keep it off unless the cooldown is raised
█ NOTES
• Based on blackcat's L2 Ehlers Adaptive RSI (V1) and John F. Ehlers' cycle work
• Core cycle math preserved from V1; every new module has its own on-off input
• Free to study and modify; attribution appreciated
═════════════════════════════════════════════════════════════════════════
For questions or feedback, use the comments section below.
Don't miss out! The first and most important thing to do is to join my Discord chat now! Click here to start your adventure: discord.com/invite/ZTGpQJq My new github for more pine development soon: github.com/wxt-coder
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
Don't miss out! The first and most important thing to do is to join my Discord chat now! Click here to start your adventure: discord.com/invite/ZTGpQJq My new github for more pine development soon: github.com/wxt-coder
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน