OPEN-SOURCE SCRIPT

Ichimoku Average with Margin

1 176
█ OVERVIEW
“Ichimoku Average with Margin” is a technical analysis indicator based on an average of selected Ichimoku system lines, enhanced with a dynamic safety margin (tolerance). Designed for traders seeking a simple yet effective tool for trend identification with breakout confirmation. The indicator offers flexible settings, line and label coloring, visual fills, and alerts for trend changes.

█ CONCEPT
The Ichimoku Cloud (Ichimoku Kinko Hyo) is an excellent, comprehensive technical analysis system, but for many traders—especially beginners—it remains difficult to interpret due to multiple overlapping lines and time displacements.
Experimentally, I decided to create a simplified version based on its foundations: combining selected lines into a single readable average (avgLine) and introducing a dynamic safety margin that acts as a buffer against market noise.
This is not the full Ichimoku system—it’s merely a clear method for determining trend, accessible even to beginners. The trend changes only after the price closes beyond the margin, eliminating false signals.

█ FEATURES
Ichimoku Lines:
- Tenkan-sen (Conversion Line) – Donchian average over 9 periods
- Kijun-sen (Base Line) – Donchian average over 26 periods
- Senkou Span A – average of Tenkan and Kijun
- Senkou Span B – Donchian average over 52 periods
- Chikou Span – close price (no offset)

Dynamic Average (avgLine):
- Arithmetic mean of only the enabled Ichimoku lines – full component selection flexibility.
Safety Margin (tolerance):

Calculated as:
- tolerance = multiplier × SMA(|open - close|, periods)
- Default: multiplier 1.8, period 100.

Trend Detection:
- Uptrend → when price > avgLine + tolerance
- Downtrend → when price < avgLine - tolerance
- Trend changes only after full margin breakout.
- Margin can be set to 0 – then signals trigger on avgLine crossover.

Signal Labels:
- “Buy” (green, upward arrow) – on shift to uptrend
- “Sell” (red, downward arrow) – on shift to downtrend

Visual Fills:
- Between avgLine and marginLine
- Between avgLine and price (with transparency)
- Colors: green (uptrend), red (downtrend)

Alerts:
- Trend Change Up – price crosses above margin
- Trend Change Down – price crosses below margin

█ HOW TO USE
Add to Chart: Paste code in Pine Editor or find in the indicator library.
Settings:

Ichimoku Parameters:
- Conversion Line Length → default 9
- Base Line Length → default 26
- Leading Span B Length → default 52
- Average Body Periods → default 100
- Tolerance Multiplier → default 1.8

Line Selection:
- Enable/disable: Tenkan, Kijun, Span A, Span B, Chikou

Visual Settings:
- Uptrend Color → default green
- Downtrend Color → default red
- Fill Between Price & Avg → enables shadow fill

Signal Interpretation:
- Average Line (avgLine): Primary trend reference level.
- Margin (marginLine): Buffer – price must break it to change trend. Set to 0 for signals on avgLine crossover.
- Buy/Sell Labels: Appear only on confirmed trend change.
- Fills: Visualize distance between price, average, and margin.
- Alerts: Set in TradingView → notifications on trend change.

█ APPLICATIONS
The indicator works well in:
- Trend-following: Enter on Buy/Sell, exit on reversal.
- Breakout confirmation: Ideal for breakout strategies with false signal protection.
- Noise filtering: Margin eliminates consolidation fluctuations.

Adjusting margin to trading style:
- Short-term trading (scalping, daytrading): Reduce or set margin to 0 → more and faster signals (but more false ones).
- Long-term strategies (swing, position): Increase margin (e.g. 2.0–3.0) → fewer signals, higher quality.

Entry signals are not limited to Buy/Sell labels – use like moving averages:
- Test and bounce off avgLine as support/resistance
- avgLine breakout as momentum signal
- Pullback to margin as trend continuation entry

Combine with:
- Support/resistance levels
- Fair Value Gaps (FVG)
- Volume or other momentum indicators

█ NOTES
- Works on all markets and timeframes.
- Adjust multiplier and periods to instrument volatility.
- Higher multiplier → fewer signals, higher quality.
- Disable unused Ichimoku lines to simplify the average.

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.