OPEN-SOURCE SCRIPT
מעודכן

TTP IFVG Signals With EMA /ICT Gold scalping

1 195
This script uses original logic and alerting rules. in Japan
finding ICT IFVG and EMA conditions.

#IFVG, Forex, ICT, EMA, Scalping, Indicator

This indicator automatically finds IFVG (Imbalance / Fair Value Gap) zones and gives you a buy or sell signal when price comes back and breaks out through that gap.
It also draws a colored box over the gap so you can see the zone visually, and it raises alerts when a new signal appears.

High-level logic:
On every bar, the script looks back up to “IFVG_GapBars” bars.
For each offset i it checks a 3-candle pattern:
– If the low of the newer candle is above the high of the older candle: bullish FVG (price jumped up, leaving a gap).
– If the high of the newer candle is below the low of the older candle: bearish FVG (price jumped down, leaving a gap).

When a valid FVG is found:
– For a bullish FVG it looks for a later close that breaks down through that gap (sell signal).
– For a bearish FVG it looks for a later close that breaks up through that gap (buy signal).
– A moving-average trend filter must agree (downtrend for sells, uptrend for buys).
– It checks that price has not already “filled” the gap before the breakout.

If all conditions are satisfied, it:
– Sets signal_dir = 1 for a buy, or -1 for a sell.
– Draws a box from the original FVG bar to the bar just before the breakout (extended a bit to the right), between the gap high and gap low.
– Plots an ▲ label for buys or ▼ label for sells.
– Triggers the corresponding alert conditions.

Now the parameters:

PipSizeMultilier (PipSizeManual)
Multiplies the symbol’s minimum tick size (syminfo.mintick).
It is used when converting “MinFVG_Pips” into an actual price distance.
If you feel the indicator is too sensitive (too many small gaps), you can increase this multiplier to effectively require a larger price difference.

TickSize
Internal value = syminfo.mintick * PipSizeMultiplier.
This is the actual price step the script uses as a “pip” when checking minimum gap size.

FVG Search Lookback (IFVG_GapBars)
How many bars back from the current bar the script will scan for a 3-candle FVG pattern.
Larger value = it can find older FVGs, but loop cost is higher.

Min FVG Size (Pips/Points) (MinFVG_Pips)
Minimum allowed size of the gap, measured in “pips/points” using TickSize.
If the vertical distance between the gap high and gap low is smaller than this, the gap is ignored.
0.0 means “no size filter” (every FVG is allowed).

FVG Epsilon (Price Units) (FVG_EpsPoints)
Tolerance for the FVG detection.
It is subtracted/added in the condition that checks “low > old high” or “high < old low”.
0.0 means strict gap (no overlap at all). A small positive epsilon allows tiny overlaps to still count as a gap.

Show IFVG Zones (ShowZones)
If true, the script draws a box over the IFVG zone when a signal is confirmed.
If false, no boxes are drawn; you only see the ▲ / ▼ markers and alerts.

Buy Zone Color (ZoneColorBuy)
Fill color and border color for boxes created from bearish FVGs that later produce a buy signal.

Sell Zone Color (ZoneColorSell)
Fill color and border color for boxes created from bullish FVGs that later produce a sell signal.

Box Extension (Bars) (BoxExtension)
How many extra bars to extend the right side of the box beyond the breakout bar.
The internal right coordinate is “bar_index - 1 + BoxExtension”.
Increase this if you want the zone to visually extend further into the future.

MA Period (MA_Period)
Lookback length of the moving average used as a trend filter.

MA Type (MA_Kind)
Type of moving average: “SMA” or “EMA”.
If SMA is chosen, the script uses ta.sma; if EMA, it uses ta.ema.

Moving-average filter behavior:
For sell signals (from bullish FVG): MA must be sloping down (MA < MA[1]) and price must be below MA.
For buy signals (from bearish FVG): MA must be sloping up (MA > MA[1]) and price must be above MA.
If these conditions are not satisfied, the FVG is ignored even if the gap and breakout conditions are met.

Signals and alerts:
signal_dir = 1 → buy signal, ▲ label below the bar, “IFVG Buy Alert” / “IFVG Buy/Sell Alert” can fire.
signal_dir = -1 → sell signal, ▼ label above the bar, “IFVG Sell Alert” / “IFVG Buy/Sell Alert” can fire.
signal_dir = 0 → no new signal on this bar.

In short:
This indicator finds 3-candle IFVG gaps, filters them by size and trend, waits for a clean breakout through the gap, draws a box on the original gap zone, and gives you a clear buy or sell signal plus alerts.


הערות שחרור
スクリプトの仕組みの解説(日本語)と、TradingViewで公開する際の英語の説明文を作成しました。

このコードは「確定待ち」をせず、リアルタイムで条件を満たした瞬間に反応する仕様になっています。

1. コード解説(仕組みの理解)
このスクリプトは大きく分けて4つのステップで処理を行っています。

① 設定とMA(移動平均線)の計算
MAフィルター: トレンド方向を判定するために、指定期間(デフォルト21)のEMAまたはSMAを使用します。

リアルタイム計算: ta.ema(close, ...) は、現在形成中の足(確定前)の価格変動に合わせて常に再計算されます。これにより、価格が急激に動いてMAの傾きが変わった瞬間も捉えられます。

② FVG(フェアバリューギャップ)の検知 (detect_fvg 関数)
指定された期間(IFVG_GapBars)を遡り、FVG(ローソク足3本構成での隙間)を探します。

Bull FVG: 1本目の高値と3本目の安値の間に隙間がある。

Bear FVG: 1本目の安値と3本目の高値の間に隙間がある。

③ シグナル判定ロジック(メインループ)
過去のFVGを一つずつチェックし、以下の手順で「反転(Inversion)」が起きているかを確認します。

有効性のチェック (already_broken):

見つけたFVGが、**「過去の足ですでにブレイク(消化)されていないか」**を確認します。

もし過去に実体で完全に埋められていた場合、そのFVGは無効としてスキップします。これにより、古いFVGによる遅れたサインを防ぎます。

リアルタイム・ブレイク判定:

close < gapLow (売り判定): 現在の価格(形成中)が、Bull FVGの下限ラインを割った瞬間。

close > gapHigh (買い判定): 現在の価格(形成中)が、Bear FVGの上限ラインを超えた瞬間。

ここが「確定待ちなし」の肝です。足が閉じるのを待たず、価格がラインを超えたら即座に条件成立となります。

MAフィルター:

ブレイクした瞬間のMAの向きと価格の位置関係が、エントリー方向と一致しているか確認します。

④ 描画とアラート
リペイントあり: リアルタイム判定のため、価格がラインを超えれば「▲/▼」と「ボックス」が出ますが、ヒゲをつけて戻ると消えます。これは「最速で反応する」ための仕様です。

ボックス描画: 条件成立時、FVGの発生元から現在の足までゾーンを描画します。

2. TradingView 公開用説明文(英語)
TradingViewの「Scripts」投稿画面の Description 欄に貼り付けて使用してください。 プロフェッショナルで、かつ「リペイント(リアルタイム動作)あり」の仕様を正しく理解してもらうための構成にしています。

Title: IFVG Signals [Realtime + EMA Filter]

Description:

This indicator detects Inversion Fair Value Gaps (IFVG) and generates trading signals in real-time without waiting for the candle close. It is designed to capture breakout moves as early as possible, specifically optimized for volatile assets like Gold (XAUUSD), but works on any pair.

The logic combines IFVG mechanics with an EMA trend filter to reduce false positives.

🚀 Key Features
No Lag (Real-time Execution): Signals appear the moment price breaks the IFVG level. You do not need to wait for the bar to close.

Smart Invalidation: automatically ignores FVGs that have already been filled/broken by previous price action, preventing delayed signals from old zones.

Trend Filter: Integrated EMA/SMA filter ensures you only trade in the direction of the immediate trend.

Visual Zones: Draws the IFVG box extending to the breakout point for clear visualization.

🛠 How it Works
FVG Detection: The script scans past bars (lookback configurable) to find valid Fair Value Gaps.

Inversion Logic:

Buy Signal: Price breaks ABOVE a Bearish FVG High.

Sell Signal: Price breaks BELOW a Bullish FVG Low.

Filtering:

The breakdown must happen on a "fresh" FVG (not previously broken).

MA Filter: For a Buy, Price > MA and MA is rising. For a Sell, Price < MA and MA is falling.

⚠️ Important Notes
Repainting Behavior: Because this script is designed for the fastest possible entry, signals appear during the formation of the bar. If the price retraces before the candle closes, the signal will disappear. This allows you to react instantly but requires discipline to handle wicks.

Alerts: When setting alerts, choose "Once Per Bar" or "Once Per Bar Close" depending on your strategy.

Once Per Bar: Triggers immediately when the price touches the level (Recommended for this logic).

Once Per Bar Close: Triggers only if the breakout is confirmed at the close.

Settings
Pip Size Multiplier: Adjusts sensitivity for different assets.

FVG Search Lookback: How far back to look for gaps.

Min FVG Size: Filters out tiny, insignificant gaps.

MA Period/Type: Customize the trend filter (EMA/SMA).

כתב ויתור

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