OPEN-SOURCE SCRIPT

Converging Triangles [The_lurker]

3 735
🔻 CONVERGING TRIANGLES — المثلثات المتقاربة 🔺

No repaint. Nothing that appears ever moves, shifts, or disappears.


Converging Triangles identifies contracting price structures built from confirmed swing pivots: a falling resistance line and a rising support line that coexist in time and close on each other. It runs three independent scales at once, freezes each structure the moment it is identified, and reports the two boundary prices and the exact bar they were crossed.


🔶 1 — THE STRUCTURE

A converging triangle here is not a shape matched against a template. It is a state: two independently valid trendlines, alive at the same time, closing on each other.

  • Upper boundary — anchored on the two most recent confirmed swing highs, sloping down.
  • Lower boundary — anchored on the two most recent confirmed swing lows, sloping up.


Because the constraint is on the sign of each slope, the detected family covers symmetric triangles and the near-flat ascending and descending variants. Wedges, where both boundaries slope the same way, are excluded by construction and never appear.


🔶 2 — HOW A STRUCTURE IS ADMITTED

Each boundary must pass every test below, and both boundaries must pass simultaneously before a structure is drawn. One failed test drops the whole structure.

🔸 PER BOUNDARY — five conditions

  1. Pivot confirmation — both anchors are swing points confirmed by "length" bars on each side.
  2. Span — at least 3 bars between anchors, at most length × Max span.
  3. Slope direction — the upper boundary must fall, the lower must rise.
  4. Interior containment — no bar between the two anchors violates the line.
  5. Forward containment — no bar from the second anchor to the present violates the line.


🔸 PER STRUCTURE — three conditions

  1. Both sides live — neither boundary has been broken.
  2. Time overlap — the two boundaries share a common bar range, so no line is drawn across a region where it has no anchors.
  3. Convergence horizon — the projected intersection falls inside Min bars to apex … Max bars to apex.


🔒 Once admitted, the geometry is frozen. Anchor points and slopes never change for the life of that structure.



🔶 3 — READING THE DRAWING

Each boundary is drawn in two segments, and the difference is deliberate.

  • Solid segment — spans the boundary's own two anchors. This is measured containment, confirmed by the market.
  • Dotted segment — from the last anchor to the present bar. This is pure extrapolation.


You can always see where the confirmed part ends and the projected part begins.

A single fill binds the two boundaries into one object rather than two unrelated strokes. Its corners are the two starting anchors and the two current endpoints, so the left edge is a slant, not a vertical cut, and the wedge tip is filled.

🔸 COLOUR STATES

  • ⚪ Forming — neutral grey. No directional claim is made before resolution.

    imagen
  • 🟢 Broken up — green. Lines and fill together.

    imagen
  • 🔴 Broken down — red. Lines and fill together.

    imagen


The structure stays neutral for its entire life. Direction is asserted only after a break is confirmed at bar close.



🔶 4 — BREAK DETECTION

On every confirmed bar, the break source is compared against both boundaries at that bar.

  • If one boundary is violated, the structure resolves in that direction.
  • If a single bar violates both boundaries, resolution goes to the side with the larger excursion beyond its line.


The shape is then redrawn in the break colour and frozen at the break bar. It does not extend forward afterward.

🏷️ A break label is placed at the bar, carrying its layer letter and any tags that fired.


🔶 5 — THREE INDEPENDENT SCALES

📏 Large (21) · Mid (14) · Small (5)

Contraction is not a single event. A large structure can be narrowing while a small one narrows inside it, and each can resolve in the opposite direction to the other. That is information worth seeing, not a conflict to hide.

Each layer detects, tracks, and resolves independently. Break labels carry L, M, or S, so the scale is always identifiable. Any layer can be switched off.


🔶 6 — HISTORICAL ARCHIVE

🗂️ Optional, off by default.

When enabled, a resolved structure is not deleted but redrawn at a faded shade. Over time this builds a map of where previous contractions broke on that symbol, under a count cap you control, with oldest-first eviction.

imagen

The fade is a separate control: set it to zero and archived structures render identically to live ones.

  • A structure that expires at the apex without resolving is not archived, since there is no event in it to keep.
  • Archived structures carry no label. Their colour and position already carry the direction.



🔶 7 — INFORMATION PANEL

imagen

📋 Reports the nearest live structure, or the nearest recently resolved one if none is live.

  • Layer — Large / Mid / Small. Coloured by resolution direction once broken.
  • Upper — the exact upper boundary price, ready to place an order against.
  • Lower — the same for the lower boundary.
  • Width (ATR) — current width in ATR units. After a break it becomes "Width at break", measured against the ATR recorded at that same bar, so the number stays fixed for a frozen structure and does not drift as volatility changes.
  • Projected apex — bars until the two boundaries intersect. After a break it becomes "Since break".
  • Status — Active · Break pending at close · Broken up · Broken down.


⚠️ The status row alone reads the live bar. It can move between pending and active within a single bar as price crosses back and forth. That is a live readout, labelled as such, not a repaint. The drawn geometry does not move.



🔶 8 — BREAK TAGS

imagen

Two optional descriptive measurements, shown on the break bar when they occur.

  • 📊 V — break-bar volume exceeded its moving average by the configured multiplier.
  • 📐 E — break-bar true range exceeded ATR by the configured multiplier.


These describe what happened on that bar. They are not quality scores or confidence grades, and they do not filter anything.


🔶 9 — ALERTS

  • 🔔 Pattern formed — a new structure is admitted.
  • 🔔 Break up — upper boundary broken.
  • 🔔 Break down — lower boundary broken.
  • 🔔 Any resolution — either break.


All alerts fire once per bar close, never before.


🔶 10 — SETTINGS REFERENCE

The icons below match the group headers you see inside the indicator's settings window.

🔸 ⚙️ SETUP

  • Language — default English. Switching to Arabic changes the entire interface.
  • Log scale — default Off. Must be matched to your chart's scale manually. See section 12.
  • ATR length — default 14. Feeds the E tag, the demote distance, and the panel width reading.


🔸 📏 LAYERS

  • Large L — default On, length 21.
  • Mid M — default On, length 14.
  • Small S — default On, length 5.


🔸 🔎 DETECTION

  • Close-only pivots — default Off. Off anchors on highs and lows; On anchors on closes.
  • Break source — default Close. One switch governing three things at once: interior containment, forward containment, and break detection.
  • Max span (× length) — default 5. Ceiling on bars between a boundary's two anchors.
  • Min side overlap — default 0. Required shared bar range between the two boundaries.
  • Min bars to apex — default 2.
  • Max bars to apex — default 200.


🔸 🎨 APPEARANCE

  • Fill triangle — default On, transparency 78.
  • Line width 2, line transparency 15.
  • Colours — grey while forming, green for an upward break, red for a downward break.


🔸 🗂️ HISTORY AND LIFETIME

  • Keep as current (bars) — default 30. After this the structure is demoted to the archive, or deleted if the archive is off.
  • Demote beyond (ATR) — default 8.0. Measured against current ATR by design: the question is how far price is now, in today's volatility.
  • Show historical patterns — default Off.
  • Historical kept — default 12, a cap across all three layers combined.
  • Historical fade — default 30, added on top of line and fill transparency.


🔸 🏷️ LABELS

  • Show labels — default On, 2 kept.
  • Volume tag V — default On. MA 20, multiplier 1.5.
  • Range expansion E — default On. Multiplier 1.4.


🔸 📋 PANEL

  • Show panel — default On, positioned top right.



🔶 11 — ON ACCURACY

Two different things get called accuracy. Only one of them is claimed here.

✅ Structural accuracy is exact and independently verifiable. Every anchor is a confirmed pivot, never a guess. Every line satisfies its containment test at the bar it is drawn. Geometry closes at formation and is never recalculated. A break is settled by a single unambiguous test on a closed bar. Nothing is repainted, backfilled, or silently adjusted. Replay any chart and trace any element yourself.

❌ Predictive accuracy is not claimed. You will find no win rate here, no signal grade, and no price target.

The indicator tells you precisely where the boundaries are and precisely when they were crossed. What that is worth in your strategy, on your instrument, at your timeframe, is yours to determine and yours to risk.



🔶 12 — BEHAVIOUR TO UNDERSTAND BEFORE TRUSTING THE CHART

  • ⚠️ Why a structure appears late. A pivot is not a pivot until its full confirmation bars have passed. That delay is the price of the promise in the first line: nothing appears before its time, and nothing that appears is taken back afterward.
  • ⚠️ A wick may cross a line. By default, anchors sit on highs and lows while containment and break detection are tested on the close. A wick can pierce a boundary while the structure remains valid. Set Break source = Wick for a shape no wick ever touches, and expect noticeably fewer structures from that considerably stricter test.
  • ⚠️ Log scale is manual. Pine cannot read your chart's scale setting. If your chart is logarithmic, enable Log scale. When the two disagree, the computed break level diverges from the drawn line: negligible on narrow structures, material on wide ones. The tell is visible on the chart itself, as the left fill edge separates from the boundary at the second anchor.
  • ⚠️ Where anchors come from. Each boundary is built from the two most recent pivots on its own side. A line that would skip an intermediate pivot is outside the detection scope.
  • ⚠️ Density. Three layers with a full archive weighs the chart down. Disable the layers you do not need, and use the archive cap and the fade to control it.



═════════════════════════════════════════════════════════════
⚠️ DISCLAIMER
═════════════════════════════════════════════════════════════

This indicator is for educational and analytical purposes only. It does not constitute financial, investment, or trading advice. Use it alongside your own strategy and risk management. Neither TradingView nor the developer is responsible for any financial decisions or losses.

═════════════════════════════════════════════════════════════


🔻 المثلثات المتقاربة — Converging Triangles 🔺

ما يظهر على الشارت لا يتحرك ولا ينزاح ولا يُسحب لاحقاً. لا إعادة رسم.


يبحث المؤشر عن حالة واحدة لا عن شكل: أن يجتمع خط مقاومة هابط مع خط دعم صاعد في الوقت نفسه، وأن يضيق ما بينهما شمعةً بعد شمعة. فإذا اجتمعا واستوفى كلٌّ منهما شروطه، رُسم النطاق وتجمّدت هندسته في اللحظة نفسها، فلا تتغيّر بعدها مهما فعل السعر.


🔶 أول ما ينبغي أن تعرفه

لأنه لا يبحث عن شكل يطابقه بقالب جاهز، فهو لا يفرض عليك تسمية. هو يعطيك حدّين بسعرين محدّدين، ويخبرك متى عُبر أحدهما بالضبط. أما ما تفعله بذلك فأنت وحدك.

  • الحد العلوي — مرسي على آخر قمتين مؤكَّدتين، هابط.
  • الحد السفلي — مرسي على آخر قاعين مؤكَّدين، صاعد.


ولأن الشرط على إشارة كل ميل، فالعائلة المكتشَفة تشمل المثلث المتماثل والنسخ شبه المستوية من الصاعد والهابط. أما الوتدان، حيث يميل الحدّان في اتجاه واحد، فمستبعدان بالبناء ولا يظهران أبداً.

ويعمل على ثلاثة مقاييس في وقت واحد، لكل مقياس نموذجه المستقل.


🔶 متى يُرسم النطاق؟

لا يُرسم شيء ما لم يستوفِ كل حد شروطه الخمسة، ثم يجتمع الحدّان معاً على ثلاثة شروط أخرى. وأي شرط يسقط يُسقط النموذج كله.

🔸 الحد الواحد — خمسة شروط

  1. أن يقوم على محورين مؤكَّدين. والمحور لا يُعدّ مؤكَّداً إلا بعد أن تمرّ عليه شموع التأكيد كاملة على الجانبين.
  2. أن تكون المسافة بين المحورين ثلاث شموع فأكثر، ولا تتجاوز الطول مضروباً في «أقصى مسافة».
  3. أن يكون العلوي هابطاً والسفلي صاعداً.
  4. ألا تخرق أي شمعة الخط في الفترة الواقعة بين المحورين.
  5. ألا تخرقه أي شمعة من المحور الثاني إلى اللحظة الحالية.


🔸 الحدّان معاً — ثلاثة شروط

  1. أن يكون كلاهما سليماً لم يُكسر.
  2. أن يتعايشا على فترة زمنية مشتركة. وهذا الشرط يمنع أن يُرسم خط في منطقة لا محاور له فيها أصلاً.
  3. أن يقع تقاطعهما المتوقَّع ضمن المدى الذي تحدّده بين «أدنى مسافة للرأس» و«أقصاها».


🔒 وبعد القبول تُغلق الهندسة نهائياً: المحاور ثابتة والميلان ثابتان، ولا شيء يُعاد حسابه.



🔶 كيف تقرأ ما تراه

لكل حد مقطعان، والفرق بينهما مقصود لا زخرفي:

  • المقطع الصلب يمتد بين محوري ذلك الحد، وهو ما تحقّق فعلاً واحتواه السوق.
  • المقطع المنقّط يمتد من المحور الأخير إلى الشمعة الحالية، وهو استقراء لا أكثر.


فأنت ترى في كل لحظة أين ينتهي المؤكَّد ويبدأ المتوقَّع.

وتربط بين الحدّين تعبئة واحدة تجعلهما كياناً واحداً لا خطّين منفصلين. وقد أُخذت أركانها من محورَي البداية الفعليين، ولذلك جاءت الحافة اليسرى مائلة يمتلئ عندها رأس الشكل، لا مقطوعة عمودياً.

🔸 واللون يحمل الحالة وحدها

  • ⚪ رمادي محايد ما دام النطاق حيّاً. فلا اتجاه يُدّعى قبل أن يُحسم.

    imagen
  • 🟢 أخضر إذا حُسم بالخروج من الأعلى. الخطوط والتعبئة معاً.

    imagen
  • 🔴 أحمر إذا حُسم بالخروج من الأسفل. الخطوط والتعبئة معاً.

    imagen


فالنطاق يبقى محايداً طوال حياته، ولا يُعلن الاتجاه إلا بعد أن تُغلق الشمعة خارج أحد الحدّين.



🔶 متى يُعدّ النطاق مكسوراً

عند إغلاق كل شمعة يُقاس السعر على الحدّين معاً.

  • فإن خرج من أحدهما حُسم النطاق في اتجاهه.
  • وقد تأتي شمعة عنيفة تخرج من الحدّين كليهما، وعندها يُحسم للجهة التي ابتعد عنها السعر أكثر.


ثم يُعاد رسم الشكل بلون الخروج ويُثبَّت عند شمعته، فلا يمتد بعدها إلى الأمام.

🏷️ وتوضع عندها تسمية تحمل حرف المقياس (L أو M أو S) ووسوم الشمعة إن تحقّقت.


🔶 لماذا ثلاثة مقاييس

📏 كبير 21 · متوسط 14 · صغير 5

لأن الانضغاط ليس حدثاً واحداً. فقد يضيق نطاق كبير بينما يضيق داخله نطاق صغير، ويخرج كلٌّ منهما في اتجاه مضاد للآخر. وهذا في نفسه معلومة تستحق أن تُرى، لا تعارضاً يجب إخفاؤه.

ولذلك تعمل الطبقات الثلاث باستقلال تام، ويحمل كل خروج حرف مقياسه فلا يختلط عليك من أين جاء. وتستطيع إطفاء أي طبقة لا تحتاجها.


🔶 النماذج السابقة

🗂️ خيار مطفأ افتراضياً.

إن شغّلته، لم يُمحَ النموذج بعد حسمه، بل بقي مرسوماً بدرجة خافتة. وبمرور الوقت تتكوّن لديك خريطة لمواضع الخروج السابقة على الرمز نفسه، بسقف عددي تحدّده أنت، ويُخلى الأقدم فالأقدم.

imagen

ودرجة الخفوت مستقلة بيدك: إن أنزلتها إلى الصفر صارت النماذج القديمة كالحيّة تماماً.

  • والنموذج الذي انتهى عمره دون خروج لا يدخل الأرشيف، إذ لا حدث فيه يُحفظ.
  • والنماذج المؤرشفة بلا تسميات، فلونها وموضعها يكفيان.



🔶 لوحة المعلومات

imagen

📋 تعرض اللوحة أقرب نطاق حيّ إليك، فإن لم يوجد عرضت أقرب نطاق حُسم حديثاً.

  • الطبقة — كبير أو متوسط أو صغير، وتُلوَّن باتجاه الخروج بعد حسمه.
  • الحد العلوي — سعره بالضبط، جاهزاً لوضع أمر عليه.
  • الحد السفلي — كذلك.
  • العرض بوحدات ATR — وبعد الخروج يصير «العرض عند الكسر»، محسوباً بـ ATR المسجّل في تلك الشمعة نفسها. فالرقم يبقى ثابتاً لنموذج مجمّد ولا ينزاح بتغيّر التقلّب.
  • الرأس المتوقَّع — كم شمعة تفصل عن تقاطع الحدّين. وبعد الخروج يصير «منذ الكسر».
  • الحالة — نشط، أو كسر معلّق يثبت بالإغلاق، أو كُسر لأعلى، أو كُسر لأسفل.


⚠️ وسطر الحالة وحده يقرأ الشمعة الجارية، فقد ينتقل داخلها بين «معلّق» و«نشط» كلما دخل السعر وخرج. وهذه قراءة لحظية مكتوب فيها صراحة أنها تثبت بالإغلاق، وليست إعادة رسم: الشكل المرسوم لا يتحرك.



🔶 الوسمان V و E

imagen

يظهران على شمعة الخروج إن تحقّقا:

  • 📊 V — تجاوز حجم الشمعة متوسطه بالمضاعف الذي ضبطته.
  • 📐 E — تجاوز مداها الحقيقي مؤشر ATR بالمضاعف الذي ضبطته.


وهما وصفٌ لما جرى في تلك الشمعة، لا حكم على جودة الخروج ولا درجة ثقة فيه. ولا يمنعان ظهور أي نموذج.


🔶 التنبيهات

  • 🔔 تكوّن نموذج
  • 🔔 كسر لأعلى
  • 🔔 كسر لأسفل
  • 🔔 أي حل — يجمع الاثنين


وجميعها تشتعل مرة واحدة عند إغلاق الشمعة لا قبله.


🔶 الإعدادات

الرموز أدناه هي نفسها التي تراها على رؤوس المجموعات داخل نافذة إعدادات المؤشر.

🔸 ⚙️ الإعداد

  • اللغة — إنجليزي افتراضاً، وتبديلها إلى العربية يغيّر الواجهة كلها.
  • المقياس اللوغاريتمي — مطفأ افتراضاً. اضبطه ليطابق شارتك، وانظر آخر قسم.
  • طول ATR — 14. يخدم وسم E ومسافة إخلاء النماذج وقراءة العرض في اللوحة.


🔸 📏 الطبقات

  • كبير L — مفعّل، بطول 21.
  • متوسط M — مفعّل، بطول 14.
  • صغير S — مفعّل، بطول 5.


🔸 🔎 الكشف

  • محاور على الإغلاق فقط — مطفأ. فتُؤخذ المحاور من القمم والقيعان. وبتشغيله تُؤخذ من الإغلاقات وحدها.
  • مصدر الكسر — Close. وهو مفتاح واحد يحكم ثلاثة أشياء دفعة واحدة: الاحتواء بين المحورين، والاحتواء بعدهما، وكشف الخروج.
  • أقصى مسافة مضروبة في الطول — 5. سقف ما بين محورَي الحد الواحد.
  • أدنى تداخل بين الضلعين — 0. الفترة المشتركة المطلوبة بين الحدّين.
  • أدنى مسافة للرأس — 2.
  • أقصى مسافة للرأس — 200.


🔸 🎨 المظهر

  • تعبئة المثلث — مفعّلة، بشفافية 78.
  • عرض الخط 2، وشفافيته 15.
  • الألوان — رمادي للتكوّن، أخضر للخروج علواً، أحمر للخروج هبوطاً.


🔸 🗂️ التاريخ والعمر

  • إبقاؤه كالحالي — 30 شمعة، ثم يُنزَّل إلى الأرشيف أو يُحذف إن كان الأرشيف مطفأً.
  • التنزيل عند البُعد — 8 من ATR. ويُقاس بـ ATR الحالي عن قصد، لأن السؤال هنا عن بُعد السعر الآن بمقياس تقلّب اليوم لا تقلّب الأمس.
  • إظهار النماذج السابقة — مطفأ.
  • عدد النماذج المحفوظة — 12، وهو سقف على الطبقات الثلاث مجتمعة.
  • خفوت التاريخية — 30، تُضاف فوق شفافية الخط والتعبئة.


🔸 🏷️ التسميات

  • إظهار التسميات — مفعّل، ويُحفظ منها 2.
  • وسم الحجم V — مفعّل، بمتوسط 20 ومضاعف 1.5.
  • وسم التمدد E — مفعّل، بمضاعف 1.4.


🔸 📋 اللوحة

  • مفعّلة، وموضعها أعلى اليمين.



🔶 الدقة: أي دقة؟

تُطلق كلمة «الدقة» على معنيين مختلفين، ولا يُدّعى هنا إلا واحد منهما.

✅ فأما دقة البناء فمضبوطة، وتستطيع التحقق منها بنفسك دون أن تصدّقني: كل محور مؤكَّد لا مظنون، وكل خط يستوفي شرط احتوائه عند الشمعة التي رُسم فيها، والهندسة تُغلق عند التكوّن فلا يُعاد حسابها، والخروج يُحسم باختبار واحد على شمعة مغلقة. لا شيء يُعاد رسمه، ولا يُملأ بأثر رجعي، ولا يُعدَّل في الخفاء. أعد تشغيل أي شارت وتتبّع أي عنصر.

❌ وأما الدقة التنبؤية فغير مُدّعاة، ولن تجد هنا نسبة نجاح ولا درجة إشارة ولا هدفاً سعرياً.

المؤشر يخبرك أين الحدّان ومتى عُبرا، بدقة. أما قيمة ذلك في استراتيجيتك أنت، على أداتك أنت، وفي إطارك الزمني أنت، فتقديرك ومسؤوليتك.



🔶 أمور تعرفها قبل أن تعتمد عليه

  • ⚠️ لماذا يظهر النموذج متأخراً. لأن المحور لا يُعدّ محوراً حتى تمرّ شموع تأكيده كاملة. وهذا التأخّر هو ثمن ما وعدناك به في السطر الأول: لا شيء يظهر قبل أوانه، ولا شيء ظهر يُسحب منك بعد ذلك.
  • ⚠️ قد تجد ذيلاً عابراً للخط. فالمحاور افتراضياً على القمم والقيعان، بينما يُقاس الاحتواء والخروج على الإغلاق. فيجوز أن يخترق ذيلٌ حداً والنموذج ما زال سليماً. وإن أردت شكلاً لا يمسّه ذيل فاضبط مصدر الكسر على Wick، واعلم أنه اختبار أصرم بكثير وأن النماذج ستقلّ بوضوح.
  • ⚠️ المقياس اللوغاريتمي يدوي. فـ Pine لا يستطيع قراءة إعداد شارتك. وإذا كان شارتك لوغاريتمياً فشغّل الخيار. وعند اختلاف الاثنين ينحرف مستوى الخروج المحسوب عن الخط الذي تراه: انحرافاً مهملاً على النماذج الضيّقة، ومادّياً على الواسعة. وعلامته أمام عينك مباشرة، إذ تنفصل حافة التعبئة اليسرى عن الحد عند المحور الثاني.
  • ⚠️ من أين تُؤخذ المحاور. كل حد يُبنى من آخر محورين على جهته. فالخط الذي يتجاوز محوراً وسيطاً خارج عن نطاق الكشف.
  • ⚠️ الكثافة. ثلاث طبقات مع أرشيف ممتلئ تُثقل الشارت. أطفئ ما لا تحتاجه، واستعن بسقف الأرشيف ودرجة الخفوت.



═════════════════════════════════════════════════════════════
⚠️ إخلاء المسؤولية
═════════════════════════════════════════════════════════════

هذا المؤشر لأغراض تعليمية وتحليلية فقط. لا يُمثل نصيحة مالية أو استثمارية أو تداولية. استخدمه بالتزامن مع استراتيجيتك الخاصة وإدارة المخاطر. لا يتحمل TradingView ولا المطور مسؤولية أي قرارات مالية أو خسائر.

═════════════════════════════════════════════════════════════

Exención de responsabilidad

La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.