OPEN-SOURCE SCRIPT

High Tight Flag [DJYYLAB]

154
OVERVIEW
Finds high tight flags: a stock doubles within a few weeks, then pauses in a tight range just under the high. The indicator draws the pole and the flag and keeps track of what happens after each one forms: a breakout, a quick drop back under the top, invalidation, or no breakout in time. All thresholds are listed below, so every result can be checked by hand.

Everything is calculated on closed bars. A flag shows up on the bar where it is first confirmed, and its box then grows with each new bar until the flag ends.

HOW IT WORKS
1. Pole
- The pole top is the highest point of the whole pattern: no bar from the pole low up to it reaches it, and nothing after it trades above it until the breakout.
- The pole low is the lowest low of the 40 bars before the pole top.
- From the pole low to the pole top: a gain of at least 100%, taking 3 to 40 bars (40 bars is 8 weeks on a daily chart). The 3-bar minimum keeps out jumps of a day or two.
- Volume surges in the pole: the biggest pole bar has at least 1.3x the average volume of the 5 bars before the pole (skipped when the chart has fewer than 5 bars before it).

2. Flag
- Every bar after the pole top. The flag is 10 to 25 bars long.
- The flag low stays within 25% of the pole top.
- Volume dries up: the flag's average volume is at most 0.75x the pole's.
- No rule on the flag's shape. It can drift down, move sideways or narrow.
The flag forms on the first bar where all of the above is true, at the earliest 10 bars after the pole top.

3. After it forms (breakout level = pole top)
- Breakout: the first bar that trades above the pole top. The breakout price is the pole top, or the open if the bar opened above it.
- Back below in 5 bars: after a breakout, a close at or under the pole top within 5 bars.
- Invalidated: trading more than 25% under the pole top before a breakout.
- Expired: more than 25 flag bars without a breakout.
- A bar that trades both above the top and more than 25% under it counts on the side nearer to its open.

ON THE CHART
- The pole: a line from the pole low to the pole top.
- The flag: a box from the pole top level down to the flag low, from the pole top to the latest bar. It ends on the breakout bar. The bottom of the box moves down when the flag makes a new low, so the flag's candles always stay inside it.
- Purple = waiting, green label = broke out, orange label = back below in 5 bars, grey = invalidated or expired (the box is cut on that bar).
- On a breakout: a triangle under the bar and a dotted measured move. The measured move is half the pole height added to the flag low.
- Hover the "High Tight Flag" label for the pole dates, prices, length and gain, the flag length, depth and volume, the result, the breakout price and its volume against the 50-bar average, the measured move, and the move 5, 10 and 20 bars after the breakout.
- Alerts: "High tight flag formed", "Near the top" (close within 3% under the pole top), "High tight flag breakout" (price trades above the pole top).

SETTINGS AND TIMEFRAMES
- Pole length, pole gain, pole volume, flag length, flag depth, flag volume, the failure window and the number of flags kept on the chart (6 by default, up to 20) can all be changed.
- Works on any timeframe. Lengths are in bars, so on a weekly chart the pole can take up to 40 weeks.
- Volume rules are skipped on symbols without volume.
- On stocks, keep dividend adjustment (ADJ) on so ex-dividend gaps don't look like price moves.

ORIGINALITY
Written from scratch, no code taken from other scripts. The breakout level is the highest point of the pattern, not a sloping line over the flag, and the flag has to hold within 25% of that high for 10 to 25 bars. Every flag is followed after it forms, and the box always holds the flag's candles.

------------------------------------------------------------
日本語

概要
ハイ・タイト・フラッグ(数週間で株価がおよそ2倍になり、その高値のすぐ下で狭い範囲の横ばいになる形)を検出するインジケーターです。ポールとフラッグを描き、形成後にどうなったか(ブレイク、すぐにポールの頂上の下へ戻った、失効、期限切れ)まで追いかけます。しきい値はすべて下に書いてあるので、結果を自分で確かめられます。

計算はすべて確定足で行います。フラッグは初めて確定した足に表示され、その後はフラッグが終わるまで新しい足ごとに箱が伸びていきます。

判定ルール
1. ポール
- ポールの頂上はパターン全体の最高値です。ポールの安値から頂上までの間にこれに届く足はなく、頂上のあとブレイクまでこれを上回る足もありません。
- ポールの安値は、頂上より前の40本の中の最安値です。
- ポールの安値から頂上まで100%以上の上昇で、かかる本数は3〜40本(日足なら40本で8週間)。3本以上とするのは、1〜2日の急騰を除くためです。
- ポールで出来高が増えること:ポール内で最大の出来高が、ポールが始まる前の5本の平均の1.3倍以上(その前に5本ない場合はこの条件を使いません)。

2. フラッグ
- ポールの頂上のあとのすべての足。長さは10〜25本。
- フラッグの安値はポールの頂上から25%以内。
- 出来高が細ること:フラッグの平均出来高がポールの平均の0.75倍以下。
- 形の条件はありません。下向き、横ばい、収束のどれでもかまいません。
すべてを満たした最初の足でフラッグが形成されます(早くてもポールの頂上の10本後)。

3. 形成後(ブレイクの水準=ポールの頂上)
- ブレイク:ポールの頂上を初めて上回った足。ブレイク価格はポールの頂上(その足が頂上より上で寄り付いた場合は始値)。
- 5本以内に戻る:ブレイク後5本以内に終値がポールの頂上以下になる。
- 失効:ブレイク前にポールの頂上から25%を超えて下げる。
- 期限切れ:フラッグが25本を超えてもブレイクしない。
- 1本の足が頂上の上と25%下の両方に届いた場合は、始値に近い側として数えます。

チャート表示
- ポール:安値から頂上までの1本の線。
- フラッグ:ポールの頂上の水準からフラッグの安値までの箱。頂上から最新の足まで伸び、ブレイクした足で終わります。フラッグが安値を更新すると箱の下辺も下がるので、フラッグのローソク足は常に箱の中に収まります。
- 紫=ブレイク待ち、緑のラベル=ブレイク、オレンジのラベル=5本以内に戻る、グレー=失効または期限切れ(箱はその足で切れます)。
- ブレイク時:足の下に三角と、点線の値幅目標。値幅目標はポールの高さの半分をフラッグの安値に足したものです。
- 「High Tight Flag」ラベルにカーソルを合わせると、ポールの日付・価格・本数・上昇率、フラッグの本数・深さ・出来高、結果、ブレイク価格とその出来高(直前50本の平均との比)、値幅目標、ブレイク後5・10・20本の値動きが表示されます。
- アラート:「High tight flag formed」「Near the top」(終値がポールの頂上の下3%以内)「High tight flag breakout」(ポールの頂上を上回る)。

設定と時間足
- ポールの本数・上昇率・出来高、フラッグの本数・深さ・出来高、「5本以内に戻る」の本数、チャートに残すフラッグの数(初期値6、最大20)は変更できます。
- どの時間足でも使えます。長さは本数なので、週足ならポールは最大40週になります。
- 出来高のない銘柄では出来高のルールは使いません。
- 株式では配当調整(ADJ)をオンにしてください。権利落ちの窓が値動きに見えるのを防げます。

独自性
他のスクリプトのコードは使わず、一から書いています。ブレイクの水準はフラッグの上の斜めの線ではなくパターンの最高値で、フラッグはその高値から25%以内で10〜25本持ちこたえる必要があります。形成後の経過まで追いかけ、箱は常にフラッグのローソク足を収めます。

כתב ויתור

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