# Apex Trendlines — User Guide

**Apex Trendlines** (indicator v4.00) draws automatic support and resistance trendlines on your chart, ranks them by strength, tracks breakouts and retests, and prints BUY / SELL arrows only after the broken line has been retested. A built-in dashboard shows the market state, multi-timeframe bias and the current setup, and gives you one-click trade buttons.

**Apex Trade Panel Executor** (EA v2.00) is the small companion Expert Advisor that executes those buttons. MetaTrader 5 does not let indicators send orders, so the dashboard asks the EA to do it. The EA is semi-automatic: it never opens a trade by itself. It only acts when you click a button.

> **Risk warning.** Trading leveraged products involves a high risk of loss. Scores, grades and signals are confidence measures based on past price behaviour, not probabilities or guarantees. Test on a demo account first. The trade buttons send market orders **without a stop loss or take profit**; you are responsible for managing risk.

---

## 1. What is in the package

| File | Type | Purpose |
|---|---|---|
| `ApexTrendlines.mq5` | Indicator | Trendlines, signals, dashboard, alerts |
| `ApexTradePanelExecutor.mq5` | Expert Advisor | Executes BUY / SELL / FLIP / PARTIAL / CLOSE from the dashboard |

Requirements: MetaTrader 5 (any broker, hedging or netting account) and enough chart history. The indicator analyses the last 5,000 bars by default.

---

## 2. Installation

1. In MetaTrader 5 choose **File → Open Data Folder**.
2. Copy `ApexTrendlines.mq5` into `MQL5\Indicators\` and `ApexTradePanelExecutor.mq5` into `MQL5\Experts\`.
3. Open each file in MetaEditor and press **F7** to compile (or restart MT5 if you received `.ex5` files).
4. Back in MT5, open the **Navigator** (Ctrl+N) and refresh it.
5. Drag **Apex Trendlines** from *Indicators* onto a chart. The lines and dashboard appear.
6. For trading buttons, drag **Apex Trade Panel Executor** from *Expert Advisors* onto the **same chart** (same symbol and timeframe window).
7. Make sure the **Algo Trading** button in the top toolbar is green and that *Allow Algo Trading* is ticked in the EA's Common tab.

When the EA connects, the dashboard's bottom line shows **"Trade EA connected (magic …)"**.

**Tip — multi-timeframe data:** the MTF section reads D1, H4, H1, M30 and M15 by default. If a column shows `NO DATA`, open those timeframes once (or scroll them back) so MT5 downloads the history.

---

## 3. Quick start

1. Attach the indicator to the chart you trade.
2. Read the dashboard top to bottom: market state, nearest resistance and support, breakout status, liquidity, MTF bias, then the **SIGNAL** section.
3. Wait for an arrow: a green **BUY** arrow below a candle or a red **SELL** arrow above one, with a grade label (A+ / A / B / C).
4. If you want to trade it, choose a lot size and click **BUY** or **SELL**.
5. Manage the position yourself (stop loss and take profit are set in MT5, not by this tool), or use **PARTIAL BOOKING**, **FLIP** and **CLOSE TRADE**.

---

## 4. What you see on the chart

### Trendlines
- **Resistance lines** (default tomato red) are built from swing highs. **Support lines** (default dodger blue) are built from swing lows.
- **Large lines** use 25/25 Zig Zag pivots with a swing of at least 5 × ATR. **Small lines** use 5/5 pivots with a swing of at least 2 × ATR. Show either or both with *Line Size*.
- Only the best non-overlapping lines are kept. Lines are ranked by strength score first.
- **Touch dots** mark candles that touched the line. Hover over a line to see a tooltip with its strength breakdown, breakout, retest and sweep state.
- A small label such as `R 78` or `S 64` shows the line's **strength score** (0–100). Colour: green 80+, yellow 60–79, orange 50–59, grey below 50.

### Strength score (0–100)
A weighted blend of seven parts. The weights can be changed in *Strength Score Settings*; they are normalised if they do not add up to 100.

| Component | Default weight |
|---|---|
| Touch quality (number and spacing of touches) | 25 % |
| Pivot strength (size of the second anchor pivot) | 15 % |
| Length (base length and age of the line) | 15 % |
| Price rejection (wicks away from the line) | 15 % |
| Volume confirmation (tick volume at touches) | 10 % |
| Momentum (line slope quality) | 10 % |
| Cleanliness (how rarely price pierced the line) | 10 % |

Rating: 90+ Exceptional, 80+ Very Strong, 70+ Strong, 60+ Moderate, 50+ Weak, below 50 Poor.

### Event labels
| Label | Meaning |
|---|---|
| `BREAKOUT` / `BREAKDOWN` | Confirmed break: *Bars to Breakout* (default 3) consecutive **closes** beyond the line. Wicks do not count. |
| `FALSE BREAK` | Price closed back on the old side within the false-breakout window (default 10 bars). |
| `RETEST` / `RETEST FAIL` | Price returned to the broken line and held (or failed to hold). |
| `SWEEP+` / `SWEEP-` | Liquidity sweep: a wick beyond the line with a close back on the original side. |
| `A+`, `A`, `B`, `C` | Grade of the current signal, next to the signal candle. |

Event labels are drawn for the top-ranked lines only (*Max lines with event labels*).

---

## 5. How signals work

A BUY / SELL arrow is not printed at the breakout. It needs a **confirmed retest** of the broken line:

1. **Breakout.** A resistance break is a bullish setup (BUY); a support break is a bearish setup (SELL).
2. **Score first.** The setup score (see below) must reach *Min setup score* (default 60) on some candle between the breakout and the retest. If it only reaches the minimum after the retest, that setup is discarded for good.
3. **Retest.** Price must touch the broken line again at least *N* candles after the breakout (default 5) and at most *Max candles* after it (default 50). With *Touch candle must close on breakout side* on, the touch candle must also close on the breakout side of the line.
4. **Invalidation.** A decisive close back through the line before the retest cancels the setup.
5. **Arrow.** The arrow is printed on the retest candle when it closes. It is **never back-filled** onto older candles later.

### Auto-flip (Auto-Change Signal Direction)
After a retest signal, if price closes beyond the retest candle's extreme **or** back across the trendline within *Failed-retest check window* candles (default 3), the retest has failed. The original arrow is withdrawn and the opposite arrow is printed on the failure candle, and the dashboard shows "retest FAILED – flip". Turn this off with *Auto-Change Signal Direction*.

> Because of auto-flip, an arrow can be replaced within the check window after it prints. Wait for the check window to pass if you want a signal that cannot flip.

### Setup score and grade
The setup score (0–100) combines: trend alignment (15), line strength (20), breakout quality (20), liquidity sweep (10), volume (5), momentum (5), multi-timeframe alignment (10) and the retest (15). Grades: **A+** 90 and above, **A** 80+, **B** 70+, **C** 60+, **D** below 60. *Confluence* counts how many of six factors agree (line strength 60+, MTF bias, sweep, high volume, RSI momentum, confirmed retest).

All calculations run once per new bar on closed candles.

---

## 6. The dashboard

The panel is made of native chart objects and updates every *Refresh interval* (default 500 ms).

| Section | What it shows |
|---|---|
| Header | Symbol, timeframe and market regime badge (green up, red down, blue range). |
| **Market** | Trend direction, regime, ATR, volatility state and current spread. |
| **Trendlines** | Nearest resistance and nearest support: price, strength, touches, distance (price and ATR) and breakout status. |
| **Breakout** | Latest breakout direction, status, quality score, volume, RSI momentum and retest state. |
| **Liquidity** | Whether price is near resistance or support (within 1 ATR) and the latest sweep with strength and age. |
| **MTF analysis** | Direction and score for each timeframe in the list, plus the combined MTF score and bias. |
| **Signal** | Current signal (BUY / SELL / WAIT with grade), confidence, confluence and the basis (which line and event). While a qualified breakout waits for its retest it shows "awaiting retest". |

Regime and trend use the close versus a 100-bar average in ATR units (0.75 ATR = trend, 2 ATR = strong trend). RSI of 55 or more is bullish and 45 or less is bearish. Volume above 1.5 × average is HIGH and below 0.75 × is LOW.

### Size and position
*Panel scale* (default 60 %) sets the size. With *Shrink panel automatically* on, the panel also shrinks to fit a small chart. Move it with *Panel X* and *Panel Y*.

---

## 7. Trading buttons

The bottom of the dashboard has six controls and two status lines.

| Control | What it does |
|---|---|
| **LOT SIZE SELECTION** dropdown | Lot size used by BUY and SELL. Click it to open a list of sizes valid for the symbol. |
| **BUY** / **SELL** | Sends a market order with the selected lot size. |
| **FLIP** | Reverses your position. Hedging account: closes the position(s), then opens the opposite side with the same volume. Netting account: sends one opposite order of twice the volume. |
| **PARTIAL BOOKING** + dropdown | Closes the chosen volume of your **newest** eligible position. The dropdown only offers volumes that leave a valid remainder. |
| **CLOSE TRADE** | Closes all eligible positions on this symbol. |
| Status lines | The first line shows your eligible positions; the second shows the result of the last action in the broker's own words. |

**Confirmation.** FLIP and CLOSE TRADE need two clicks within 4 seconds ("CONFIRM FLIP?" / "CONFIRM CLOSE?"). Turn this off with *Double-click confirm for FLIP and CLOSE TRADE*.

**Eligible positions** are positions on the chart's symbol opened with the EA's magic number. Enable *Also manage positions of other magic numbers* in the EA to include manual and other-EA positions on the same symbol.

**FLIP** refuses to run if you hold both BUY and SELL positions (use CLOSE TRADE first).

The buttons wait for the EA's reply. If nothing comes back within 8 seconds the dashboard reports "No response from the trade EA".

### EA inputs

| Input | Default | Meaning |
|---|---|---|
| Magic number | 20260101 | Identifies trades opened by the EA. |
| Also manage positions of other magic numbers | false | Let FLIP / PARTIAL / CLOSE act on manual and other-EA positions on the same symbol. |
| Max slippage (points) | 20 | Allowed price deviation on execution. |
| Order comment | Apex TL | Comment attached to orders. |
| Max lot per BUY / SELL click | 0 (off) | Rejects a BUY or SELL above this size. Useful as a fat-finger guard. |
| Max spread in points to open or flip | 0 (off) | Rejects BUY, SELL and FLIP while the spread is wider than this. FLIP is checked before anything is closed. |

The EA also checks that trading is allowed, quotes exist, the volume is valid and there is enough free margin before it sends an order.

---

## 8. Indicator settings reference

**Main:** *Bars to Breakout* (closes needed to confirm), *Line Size* (Small, Large, Both), *Show Pivots* (touch dots).

**Appearance:** line colours, widths and styles for large and small lines, strength labels, touch dots (all touches or base pivots only), dot size, BUY / SELL arrow visibility, size and colours.

**Strength Score Settings:** rank by strength first, and the seven component weights.

**Breakout Settings:** false-breakout window, retest-confirm window (used for the RETEST label), approaching distance, event-label switches.

**Liquidity / Momentum / Volume / Regime / MTF Settings:** sweep look-back, RSI on/off and period, volume average period, trend and volatility look-backs, MTF timeframe list (comma-separated, e.g. `D1,H4,H1,M30,M15`), matching weights, and bars fetched per timeframe.

**Signal Settings:** *Min setup score for BUY/SELL* (default 60). Raise it for fewer, higher-quality signals.

**Retest Confirmation:** the retest gate (on by default), minimum and maximum candles to wait, auto-flip on/off, flip check window, hold-close rule, and two score-timing options (score must be reached before the first touch; allow the retest candle itself to count).

**Dashboard PRO (layout and trading):** panel position, scale, auto-fit, refresh interval, initial lot (*Initial lot size for BUY / SELL*) and the double-click confirmation. *Dashboard Settings → Show dashboard* switches the whole panel on or off.

**Alert Settings:** choose the channels (popup, sound, push notification, email) and which events alert: confirmed breakout, false breakout, liquidity sweep, retest confirmed, and A / A+ setups. Each event alerts once. To receive push or email alerts, configure them in MT5 under *Tools → Options*.

**Advanced:** pivot lengths, ATR multiples, touch area, bars analysed and speed limits. The defaults follow the specification; change them only if you know why.

---

## 9. Troubleshooting

| Message or symptom | Fix |
|---|---|
| "Trade EA not attached" | Attach Apex Trade Panel Executor to the **same chart** as the indicator. |
| "No response from the trade EA" | Check that Algo Trading is green and the EA's smiley/face icon on the chart is active. Re-attach the EA. |
| "Trade EA detached" | The EA was removed from the chart. Buttons are disabled until you attach it again. |
| "Algo trading is disabled in the terminal" | Click the Algo Trading button in the toolbar. |
| "Invalid lot size" / "Volume invalid" | Pick a size from the dropdown; each symbol has its own minimum, step and maximum. |
| "Not enough free margin" | Lower the lot size. |
| "Spread … is above the limit" / "Lot … is above the EA limit" | Adjust or clear the EA's *Max spread* / *Max lot* inputs. |
| MTF shows `NO DATA` | Open the listed timeframes so history downloads. |
| Dashboard too big or cut off | Lower *Panel scale* or keep *Shrink panel automatically* on. |
| No arrows | Normal. Arrows only print after breakout + score + retest. Check the Signal section for "awaiting retest". |
| Dashboard missing in Strategy Tester | The panel is skipped in non-visual tests. Use visual mode to see it. |

---

## 10. Good practice

- Start on a demo account and watch how signals develop before using real money.
- Always set a stop loss in MT5 after entering. The buttons do not place one.
- Higher grades (A+ / A) and agreement with the MTF bias are stronger setups, but nothing here is a guarantee.
- Changing timeframe re-runs the analysis, so the dashboard briefly shows "waiting for data".
- Keep one indicator and one EA per chart.

*Copyright 2026, Apex Trendlines. All rights reserved.*
