# Heikin-Ashi Alert v7 – Complete Trader’s Guide
This document provides a comprehensive description of the **Heikin-Ashi Alert v7** script, including its features, installation, usage, and detailed explanations tailored for traders who want to monitor **DOTUSDT** on Binance with advanced statistical alerts.
> **Upgrade from v6:**
> - ✅ Fixed Ctrl+C handling using `signal.SIGINT` – clean exit with no forced reconnections
> - ✅ Automatic recreation of WebSocket after disconnects (graceful reconnect loop)
> - ✅ All v6 features preserved (EMA50/200, 3σ/5σ body, 3σ volume, sound alerts)
> - ✅ Improved visual output: green/red **coloured blocks** instead of plain letters
---
## Table of Contents
1. [Overview](#overview)
2. [Features](#features)
3. [Output Format Explained](#output-format-explained)
4. [Installation](#installation)
5. [Usage](#usage)
6. [How It Works – Deep Dive](#how-it-works--deep-dive)
- Heikin‑Ashi Candles
- EMA 50/200 Crossover
- 3σ / 5σ Body Detection
- 3σ Volume Detection
- Hybrid Data Feed
7. [Customisation for Advanced Users](#customisation-for-advanced-users)
8. [Troubleshooting](#troubleshooting)
9. [Requirements & Dependencies](#requirements--dependencies)
10. [License](#license)
---
## Overview
**Heikin-Ashi Alert v7** is a real‑time terminal‑based monitoring tool for **Binance Spot DOTUSDT** on the **1‑minute timeframe**.
It combines:
- Heikin‑Ashi smoothed trend tracking (displayed as **coloured blocks**)
- Exponential Moving Average (EMA 50/200) cross detection
- Statistical anomaly detection for candle bodies (3σ / 5σ)
- Statistical anomaly detection for volume spikes (3σ)
All output is timestamped and colour‑coded, with optional sound alerts for key events. The script is ideal for traders who want to **visually and audibly** catch trend changes, momentum shifts, and unusual market activity without staring at a chart.
---
## Features
| Feature | Description |
|---------|-------------|
| **Binance Spot DOTUSDT** | Monitors DOT/USDT on the 1‑minute timeframe (can be changed). |
| **Heikin‑Ashi trend tracking** | Smoothed price action; each minute prints a **green** or **red block** (background colour). |
| **EMA 50 / 200 crossover** | Detects when the fast EMA crosses above or below the slow EMA – a classic trend‑change signal. |
| **3σ candle‑body detection (⚡)** | A candle body larger than **mean + 3 standard deviations** – unusual but not extreme. |
| **5σ candle‑body detection (💥)** | A candle body larger than **mean + 5 standard deviations** – extremely rare (about 1 in 1.7 million candles under normal distribution). |
| **3σ volume detection (🔊)** | Volume spike exceeding mean + 3 standard deviations – indicates strong participation. |
| **Timestamped lines** | Every output line begins with `YYYY-MM-DD HH:MM:SS` for precise logging. |
| **ANSI terminal output** | Green blocks for bullish HA, red blocks for bearish HA – instant visual recognition. |
| **Sound alerts** | Plays different sounds for trend changes, EMA crosses, and sigma events (requires PulseAudio on Linux). |
| **Hybrid data feed** | Preloads 500 candles via REST, then streams live via WebSocket – no gaps. |
| **Robust shutdown** | `Ctrl+C` triggers a clean exit without reconnect attempts (signal‑based). |
| **Auto‑reconnect** | If the WebSocket disconnects, the script automatically reconnects (unless shutdown was requested). |
---
## Output Format Explained
When you run the script, you will see something like this:
2026-06-15 15:18:01 Preloaded 500 candles, EMA50=1.0279, EMA200=1.0196 2026-06-15 15:18:02 Connected to DOTUSDT 1m 2026-06-15 15:19:01 ████████⚡█ 2026-06-15 15:28:01 ▼█ 2026-06-15 15:29:01 ▲█ 2026-06-15 15:30:01 ▼█⚡🔊
> **Note:** The coloured blocks (`█`) appear as **green** (bullish) or **red** (bearish) in a terminal that supports ANSI colours. The actual character is a space with background colour – it looks like a solid coloured square.
### Breaking down each element
| Element | Meaning |
|---------|---------|
| `2026-06-15 15:19:01` | Timestamp of the line – corresponds to the **minute** when the first block of that run was printed. |
| `████████⚡█` | A run of **green** Heikin‑Ashi candles (uptrend). After 8 consecutive green blocks, an **unusual candle body** (⚡) occurred, then the run continued with another green block. |
| `▼█` | **Trend change** from green to red (bearish). The `▼` marks the exact minute of change, followed by the first red block of the new run. |
| `▲█` | Bullish trend change from red to green. |
| `█⚡🔊` | A red run where an unusual candle body (`⚡`) and a volume spike (`🔊`) happened in the same minute (both alerts appear inline). |
**Important:**
- Each coloured block represents **one completed 1‑minute candle** after Heikin‑Ashi smoothing.
- Inline alerts (`⚡`, `💥`, `🔊`) appear **immediately after** the block of that minute.
- EMA crossover alerts appear on **their own dedicated line** (with `🔼` or `🔽`) and do not interrupt the Heikin‑Ashi colour run (they are printed separately, but the colour run continues on the next line).
---
## Installation
### 1. Install Python dependencies
```bash
pip install websocket-client requests
Requirements: Python 3.6 or higher.
The script uses paplay (PulseAudio) to play sounds. On most Linux distributions (Ubuntu, Debian, Fedora, etc.) this works out of the box.
If you are on macOS or Windows, you can modify the play() function in the script to use a different audio player (e.g., afplay on macOS, or a Windows API call).
Save the file as Heikin-Ashi-alert-v7.py.
Run the script from the terminal:
python3 Heikin-Ashi-alert-v7.pyThe script will:
- Preload 500 historical candles from Binance REST API.
- Connect to the Binance WebSocket stream.
- Begin printing timestamped lines as described above.
Stop the script: Press Ctrl+C. The script will shut down cleanly (no reconnect attempts, no error messages).
Heikin‑Ashi (“average bar”) is a smoothing technique that filters out minor price noise. Unlike standard candlesticks, Heikin‑Ashi uses modified formulas:
- HA‑Close = (Open + High + Low + Close) / 4
- HA‑Open = (Previous HA‑Open + Previous HA‑Close) / 2
- HA‑High = max(High, HA‑Open, HA‑Close)
- HA‑Low = min(Low, HA‑Open, HA‑Close)
The script only tracks the colour of the HA candle:
- Green block when HA‑Close ≥ HA‑Open (bullish)
- Red block when HA‑Close < HA‑Open (bearish)
A sequence of same‑coloured HA blocks indicates a persistent trend. Colour changes often signal trend reversals.
The script calculates two Exponential Moving Averages on real closing prices (not Heikin‑Ashi):
- EMA50 (fast)
- EMA200 (slow)
When EMA50 crosses above EMA200, it generates a bullish crossover (🔼).
When EMA50 crosses below EMA200, it generates a bearish crossover (🔽).
On a 1‑minute chart, these crosses can indicate shorter‑term momentum shifts. Note that EMA200 on 1m corresponds to roughly 3.3 hours of data – useful for intraday trends.
The script maintains a rolling window of the last 200 real candle bodies (|Close – Open|). For each new completed candle, it computes:
- Mean (μ) of the last 200 bodies
- Standard deviation (σ) of the last 200 bodies
If the new body exceeds μ + 3σ, you get ⚡ (unusual).
If it exceeds μ + 5σ, you get 💥 (extreme).
Under a normal distribution, a 5σ event occurs with probability ~1 in 1.7 million – extremely rare. In financial markets, such events may indicate news, large orders, or liquidations.
Similarly, the script keeps the last 200 real volumes. When a new candle’s volume exceeds μ_volume + 3σ_volume, a volume spike is detected (🔊). This often confirms the strength of a price move.
- Preload (REST): 500 candles are fetched at startup to initialise EMAs, Heikin‑Ashi state, and the sigma history buffers.
- Live (WebSocket): The script then subscribes to
dotusdt@kline_1m. It receives real‑time updates every second, but only acts on finalised candles (k['x'] == True) – i.e., when the minute has closed. Inline sigma alerts are checked on every tick (for early warning), but only printed when the candle closes.
This approach avoids missing candles and ensures accurate EMA calculations.
Ctrl+CsendsSIGINT, which sets a global shutdown flag and closes the WebSocket cleanly. The script exits without trying to reconnect.- If the WebSocket connection drops unexpectedly (network issue, server restart), the script enters a reconnect loop – waiting 5 seconds and creating a fresh
WebSocketApp. This continues indefinitely until you pressCtrl+C.
You can easily adapt the script to your needs. All configurable parameters are at the top of the file.
| Variable | Default | Description |
|---|---|---|
SYMBOL |
"DOTUSDT" |
Binance symbol (e.g., "BTCUSDT", "ETHUSDT"). |
INTERVAL |
"1m" |
Candle interval (e.g., "5m", "15m", "1h"). Note: EMA periods are fixed to 50/200 – you may want to adjust them if changing interval. |
PRELOAD |
500 |
Number of historical candles to preload. Increase if you need longer EMA history (e.g., 2000 for EMA200 on 5m). |
EMA_FAST / EMA_SLOW |
50 / 200 | The two EMA periods. |
| Sound file paths | /usr/share/sounds/freedesktop/stereo/... |
Replace with your own .oga or .wav files. |
Simply change SYMBOL = "BTCUSDT" (or any Binance spot pair). The script automatically adjusts the WebSocket URL.
Change INTERVAL = "5m". However, the EMA periods (50/200) may not be meaningful for longer intervals. For a 5m chart, EMA50 = 250 minutes (~4 hours), EMA200 = 1000 minutes (~16.7 hours). That’s fine, but you might prefer faster EMAs (e.g., 20/50).
If you don’t want sounds, comment out the play() calls inside each alert function, or replace them with pass.
You can redirect the output to a file for later analysis:
python3 Heikin-Ashi-alert-v7.py > dotusdt_alert.logThe timestamped format makes it easy to parse.
| Problem | Likely Solution |
|---|---|
ModuleNotFoundError: No module named 'websocket' |
Install dependencies: pip install websocket-client requests |
| No sound alerts | Ensure paplay is installed (PulseAudio). On Ubuntu: sudo apt install pulseaudio-utils. On macOS, modify play() to use afplay. |
| Script stops after “Connected” with no output | Binance WebSocket may be blocked. Check firewall. Try using wss://stream.binance.com:9443/ws (default) – if that fails, switch to wss://stream.binance.com:443/ws by editing the socket_url. |
ERROR: [Errno 104] Connection reset by peer |
Temporary network issue; the script auto‑reconnects every 5 seconds. |
| EMA crossover shows immediately after start | That’s normal – the preload computes the initial relationship. If it prints a cross at startup, it means the crossover occurred during the preloaded history. |
Too many ⚡ or 🔊 alerts |
The sigma thresholds are based on historical volatility. If the market becomes extremely volatile, you will see frequent alerts – that’s expected. You can increase thresholds (e.g., 4σ instead of 3σ) by editing the condition. |
| Coloured blocks not showing | Your terminal must support ANSI escape codes. Most modern terminals (GNOME Terminal, iTerm2, Windows Terminal) do. If colours appear as raw codes, set TERM=xterm-256color. |
- Python 3.6+
- Internet connection to reach Binance API (api.binance.com and stream.binance.com)
- Libraries:
requests,websocket-client - Optional: PulseAudio for sound (Linux)
No API key is required – Binance public endpoints are used.
This software is provided free to use, modify, and distribute under the MIT License. The author assumes no liability for trading losses incurred while using this tool.
Happy trading!
Use the alerts as part of a broader strategy – never rely on a single signal.