STEP SONAR OPTIONS v1 - MT5
===========================
UltimateTrading.tools  |  https://ultimatetrading.tools
Version 1.00  |  Deriv Step & Volatility indices  |  Rise/Fall 5m & 15m

WHAT IT IS
----------
A Rise/Fall analysis indicator for Deriv Step and Volatility indices. It
measures how far price is stretched from equilibrium using a volatility
model of the market, marks RISE / FALL setups, projects where price can be
at a 5 m and 15 m expiry, and measures - on the history you have loaded -
what actually happened at those expiries. Nothing on the dashboard is a
forecast.

INSTALLATION
------------
1. MT5: File > Open Data Folder > MQL5 > Indicators.
2. Copy Step_Sonar_Options_v1_DERIV_MT5.mq5 into that folder.
3. Open it in MetaEditor and press Compile (F7).
4. In MT5, refresh the Navigator and drag the indicator onto a chart.

WHICH TIMEFRAME
---------------
Expiries must be a whole number of bars:
  M1   5m expiry = 5 bars,  15m expiry = 15 bars
  M5   5m expiry = 1 bar,   15m expiry = 3 bars
  M15  5m expiry = n/a,     15m expiry = 1 bar
Use M1 or M5 to score both expiries.

THE MODEL
---------
Step indices: every tick moves price by exactly +/- one step with equal
odds, so the volatility of a bar is known in advance:
    sigma per bar = step x sqrt(ticks per bar)
Volatility indices: constant annual volatility (V75 = 75 %/year), so
    sigma per bar = price x volatility x sqrt(bar seconds / seconds in a year)
Multi / Skew Step and other symbols use measured volatility (300 bars).

Market auto-detect (from the symbol name and description):
  Step Index 100-500   step 0.1 ... 0.5, 0.5 ticks per second
  Multi / Skew Step    measured sigma
  Volatility 10-250    volatility from the name, 0.5 ticks per second
  Volatility (1s)      1 tick per second
  Other                measured sigma
Overrides: market, step size, volatility %, ticks per second, sigma source.

ON THE CHART
------------
- Equilibrium: 60-bar average, with bands at 1, 2 and 3 sigma.
- Candles coloured by stretch: faded near equilibrium, vivid when stretched.
- Swing levels (8 bars each side, up to 4 live per side). SWEEP is marked
  when a wick runs at least 2 steps beyond a level and the candle closes
  back inside.
- Exhaustion arrows: the bar where price re-enters from beyond 2 sigma with
  a candle in the opposite direction.
- RISE / FALL labels (see below).
- Probability cone from the last candle to the longest expiry: +/-1 and
  +/-2 sigma, with markers at the 5 m and 15 m settlement points showing
  the expected spread in steps.
- Price grid (snapped to the step lattice on Step indices).
- Optional fair-odds planner (off): upper / lower barriers with the chance
  of reaching each first and the expected time to exit.
- Optional background tint while stretched (off).

RISE / FALL SIGNALS
-------------------
Score 0-3 per side, over the last 3 bars:
  1. stretch: price beyond -2 sigma (RISE) / +2 sigma (FALL)
  2. a swing low (RISE) / swing high (FALL) swept in the last 3 bars
  3. a streak of 5+ down (RISE) / up (FALL) candles
A label prints when the score reaches 2 of 3. By default the stretch must
be one of the two. Signals are evaluated on the closed candle (non-repaint).

DASHBOARD (top-left)
--------------------
  Market               detected market, step / volatility, ticks per second
  Sigma per bar        in steps and in price, ticks per bar
  Stretch              distance from equilibrium in sigma
  Drift                60-bar move in sigma
  Bar streak           with its coin-flip probability
  State                Equilibrium / Leaning / STRETCHED
  RISE | FALL score    live 0-3 dots
  Last signal          entry, move in steps, time left to each expiry
  Payout, break-even   wins needed for your payout (51.3% at 95%);
                       a tie loses unless "Allow equals" is on
  Per expiry           bars, coin-flip win %, tie % (Step), expected value
                       odds in this state: measured Rise / Fall / tie %
                       for the current stretch bucket at that expiry
                       evidence: effective sample size, 95% margin, verdict
                       ("too few samples", "no edge vs break-even",
                       "beats break-even in-sample (verify)")
                       signal record: n, win %, by direction, ties
  Sigma sanity check   measured vs model volatility; suggests a ticks/sec
                       or step correction if they disagree
  Reality check        martingale has negative expected value

Measured figures overlap in time, so the sample size is discounted to the
number of independent expiry windows before the margin is calculated.

INPUTS
------
1. Market            market, step, volatility %, ticks/sec, sigma source,
                     empirical lookback
2. Bands             equilibrium length, inner / outer / extreme sigma
3. Signals & levels  stretch threshold, streak length, exhaustion, sweeps,
                     sweep depth, RISE/FALL labels, require stretch,
                     swing levels, swing strength, max levels
4. Rise/Fall         expiry A / B (minutes), payout %, allow equals,
                     signals scored, close-only, signal record
5. Next-move map     cone, horizon, expiry markers, fair-odds planner,
                     barriers, round-trip cost, price grid
6. Bias gauge        dashboard rows, label next to the last candle
7. Look              colours, candle colouring, tint, dashboard position
8. Alerts            RISE/FALL, exhaustion, sweep; popup, push, sound
9. History           bars processed for the bias and record (20000)

ALERTS
------
RISE / FALL (on), exhaustion (off), sweep (off). Fired on live closed bars
only, never for history when the indicator loads.

BUFFERS (for EAs via iCustom / CopyBuffer)
------------------------------------------
   0  Equilibrium
 1-2  Upper / lower inner band
 3-4  Upper / lower outer band
 5-6  Upper / lower extreme band (drawn as dots)
12-13 Exhaustion rise / fall
  14  RISE (CALL)  - price where the label is drawn, EMPTY_VALUE otherwise
  15  FALL (PUT)   - same
  16  Stretch z (sigma)
Read shift 1 (the last closed candle).

DISCLAIMER
----------
Educational tool, not financial advice. The bias and signal record are
measurements on past data, not predictions. Rise/Fall contracts and
synthetic indices carry a high risk of loss. Test on a demo account first.
