Re: 🔺 MT5 XARD - Simple Trend Following Trading System

1181
SEMA logic explained by Claude AI

# XU SEMA v2.13 - Logic Explanation

This is a **multi-timeframe ZigZag indicator** with a ternary logic system and VWAP continuity tracking. Let me break down its core components:

## 🎯 Core Purpose

The indicator identifies swing highs/lows across 4 different periods (SEMA1-4) and tracks their directional bias using ternary logic, displaying them as symbols on the chart.

## 🔢 Ternary Logic System

Instead of binary (true/false), it uses **three states**:
- **TRIT_T (-1)**: Trend DOWN
- **TRIT_0 (0)**: NEUTRAL
- **TRIT_1 (1)**: Trend UP

This allows for more nuanced market state representation beyond simple bullish/bearish.

## 📊 Four SEMA Layers

Each SEMA is a ZigZag calculation with different parameters:

1. **SEMA1** (Period: 11) - Small dots, fastest signals
2. **SEMA2** (Period: 43) - Big dots, intermediate swings
3. **SEMA3** (Period: 175) - Arrows, major swings
4. **SEMA4** (Period: 703) - Squares, highest timeframe structure

Each uses:
- **Depth**: Lookback period for finding extremes
- **Deviation**: Minimum price movement threshold (in points)
- **Backstep**: Prevention of overlapping signals

## 🔄 ZigZag Calculation Logic

The `ZigZag_Calc()` function:

1. **Finds local extremes** within the depth period
2. **Validates them** against deviation threshold
3. **Prevents repainting** by checking backstep distance
4. **Alternates high/low** - removes invalidated points when a new extreme exceeds the previous

Example flow:
```
- Find highest high in last 11 bars
- Check if current bar is within deviation tolerance
- Remove any closer highs within backstep range
- Mark valid high in buffer
- Repeat for lows
```

## 🎨 Visual Display

Each SEMA level displays as Wingdings font characters:
- **Size increases** with timeframe (S1: 20 → S4: 78)
- **Colors configurable** for up/down (default: Orchid/Green)
- **Symbol codes** (S1kod-S6kod) determine character appearance

## 📈 VWAP Continuity System

The key innovation - maintains directional bias between zigzag points:

```cpp
GetBiasDirectionWithContinuity()
```

**Logic:**
1. Scans last 5000 bars for most recent high/low signals
2. Compares which occurred more recently
3. Maintains this direction until next valid zigzag point appears
4. Stores state in `currentSemaXSet` variables

**Without continuity**: Would show NEUTRAL between zigzag points
**With continuity**: Maintains last known direction (UP/DOWN)

## 🎛️ Bias Boxes

Three button displays at chart bottom showing current bias:

- **Square Box** → SEMA4 direction (highest timeframe)
- **Arrow Box** → SEMA3 direction
- **BigDot Box** → SEMA2 direction

Colors change: Green (uptrend) / Red (downtrend) / Gray (neutral)

## 🔍 Key Functions

### `GetBiasDirection()`
Determines trend by finding most recent high vs low zigzag point:
```
If latest_high_bar < latest_low_bar → TREND_DOWN
If latest_low_bar < latest_high_bar → TREND_UP
```

### `UpdateBiasBoxes()`
Updates button labels and colors based on `currentSemaXSet` ternary values

### `OnCalculate()`
Main execution loop:
1. Calculates all 4 zigzags on new bars
2. Updates white dot buffers (SEMA3)
3. Determines bias directions with continuity
4. Creates/updates chart objects (symbols)
5. Refreshes bias boxes

## 🛡️ Protection Features

- **Name verification** - prevents unauthorized modification
- **DPI scaling** - adjusts symbol sizes for different screen resolutions
- **Array resizing** - handles growing bar counts dynamically
- **Error handling** - checks array bounds before access

## 💡 Trading Application

The indicator helps identify:
- **Nested structures**: Higher timeframe trends containing lower timeframe swings
- **Trend alignment**: When all 4 SEMAs point same direction = strong trend
- **Divergences**: When lower timeframes reverse before higher ones
- **Entry timing**: Use faster SEMAs for entries within slower SEMA trends

The ternary logic allows for **three-way decision making** rather than binary yes/no, which better represents market uncertainty and transitional states.

XARD: What the documentation doesn't mention is that I've reconfigured the SEMA logic from a 5x to a 4x multiplier and now use timeframes that are 4x apart to capture fractal resonance -- Trade exclusively in the direction of [VWAP + EMA] when their colors synchronize - and exit immediately when those colors fall out of alignment.
These users thanked the author Vetis for the post (total 2):
Tomson, SOLESHOE


Re: 🔺 MT5 XARD - Simple Trend Following Trading System

1182
Vetis wrote: Tue Nov 04, 2025 9:04 am
XARD: What the documentation doesn't mention is that I've reconfigured the SEMA logic from a 5x to a 4x multiplier and now use timeframes that are 4x apart to capture fractal resonance -- Trade exclusively in the direction of [VWAP + EMA] when their colors synchronize - and exit immediately when those colors fall out of alignment.
" Trade exclusively in the direction of [VWAP + EMA] when their colors synchronize - and exit immediately when those colors fall out of alignment."

THANK YOU For this clarification !
(this also explain why smaller TF implies shorter trades)