OPEN-SOURCE SCRIPT
Adaptive Alligator - Asymmetric MH (Entry Only)

Adaptive Alligator – Asymmetric Mexican Hat (Entry Only)
This strategy combines adaptive cycle detection (wavelet + autocorrelation), directional entropy, and a Mexican Hat filter to generate highly selective LONG entry signals. Exits are based solely on the Alligator structure. The system is designed to detect asymmetric, strong, and accelerating bullish phases while filtering out market noise.
1. Adaptive Cycle Detection: The strategy analyzes the median price using wavelet decomposition (Haar, Daubechies D4/D6, Symlet 4), wavelet detail energy, and autocorrelation. It also incorporates the ratio of short-term to long-term ATR volatility. Based on these components, it computes a dominant_cycle value, which dynamically controls the lengths of the Alligator lines (Jaw, Teeth, Lips). This adaptive behavior allows the Alligator to speed up during trending phases and slow down during noise or consolidation.
2. Directional Entropy: Entropy is measured separately for upward and downward movements within the selected lookback window. The entropy difference: e_diff = entropy_down - entropy_up represents the directional bias of the market. When e_diff > 0, the market shows an organized bullish pressure; when < 0, bearish dominance.
3. Mexican Hat Filter: The Mexican Hat (Ricker Wavelet) acts as a second-derivative filter, detecting local maxima in the acceleration of directional entropy. The filtered output (mh_out) is compared against an adaptive noise level computed as SMA(|mh_out|). A signal is considered strong only when: – mh_out exceeds the adaptive noise level, – mh_out is rising relative to the previous bar. This step is critical for eliminating false signals produced by random fluctuations.
4. Entry Logic: A LONG entry requires all three layers: (1) Alligator structure: Lips > Teeth > Jaw. (2) Directional entropy bias: e_diff > 0. (3) A strong, accelerating Mexican Hat signal confirmed by a user-defined number of bars. Once all conditions are satisfied, a buy_final entry is triggered.
5. Exit Logic: Exits are intentionally simple and rely solely on the Alligator: crossunder(lips, teeth) This clean separation ensures precise, adaptive entries and stable, consistent exits.
6. Visual Components: – Alligator lines: Jaw (blue), Teeth (red), Lips (green), plotted with their characteristic offsets. – Background coloring reflects signal strength: dark green (STRONG BUY), lime (acceleration), yellow (weak bias), transparent otherwise. – A dedicated panel displays e_diff (entropy difference), mh_out (Mexican Hat output), and the adaptive noise band.
7. Diagnostic Table: A compact diagnostic dashboard shows: – MH Value, – Noise Level, – MH Acceleration (YES/NO), – Signal Status (STRONG BUY / ACCELERATING / WEAK / BEARISH). It updates on the last bar, making it suitable for live monitoring.
8. Use Case: This strategy is highly selective and ideal as an entry module within trend-following systems. By combining wavelets, entropy, and adaptive noise modeling, it effectively filters out consolidation periods and focuses only on statistically significant bullish transitions. It can be integrated with various exit frameworks such as ATR stops, channel-based exits, range boxes, or trailing logic.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.