Advertisement IC Markets

Equal highs swept at London open: reclaim entry vs wait for BOS

Discuss 1-minute to 15-minute price action setups, fading intraday momentum, key support/resistance zones, and proven short-term trading methodologies.
LondonScalper
Posts: 965
Joined: Sat Sep 05, 2026 7:54 am

Equal highs swept at London open: reclaim entry vs wait for BOS

Post by LondonScalper »

Equal highs are magnets. Sweeping them is not automatically a reverse signal.

I used to enter on the first reclaim wick. Too early, too often. Now: sweep of equal highs at London open puts me on alert; entry waits for either a firm reclaim hold or a small break of structure against the sweep, depending on pace. If price sweeps and keeps going with displacement, I do not invent a fade to feel clever.

Rule of thumb: reclaim-only when the sweep looks stop-hunty and thin; wait for BOS when the tape is fast and I need confirmation I am not fading strength. Equal highs that formed over many hours deserve more respect than two accidental prints that look equal if you squint.

I mark equal highs before London when I can. Discovering them mid-spike is how you rationalise a late click.
  • Reclaim entry or wait for BOS — which camp are you in?
  • Does equal-highs context change that choice for you?
This sits next to the broader sweep-vs-chase discussion, but I want the equal-highs case specifically.
Recommended broker for automated trading & scalping IC Markets
PropScalpDesk
Posts: 521
Joined: Sat Sep 19, 2026 7:50 pm

Re: Equal highs swept at London open: reclaim entry vs wait for BOS

Post by PropScalpDesk »

Before choosing a camp, it's worth checking which price the sweep happened on. MT charts show the bid by default, but the buy stops above equal highs are triggered by the ask. So on a normal spread a real sweep of those stops can happen without the bid chart ever printing above the highs, and a "sweep" you do see on the bid means the ask went some way further.

Practically: with ask lines turned on, I only treat it as a sweep if the ask traded through the equal highs by more than one or two spreads. Smaller pokes than that behave more like noise than stop runs for me, and I wait for a break of structure in those cases.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Equal highs swept at London open: reclaim entry vs wait for BOS

Post by PTScalper »

LondonScalper wrote: Wed Sep 16, 2026 11:24 pm Equal highs are magnets. Sweeping them is not automatically a reverse signal.

I used to enter on the first reclaim wick. Too early, too often. Now: sweep of equal highs at London open puts me on alert; entry waits for either a firm reclaim hold or a small break of structure against the sweep, depending on pace. If price sweeps and keeps going with displacement, I do not invent a fade to feel clever.

Rule of thumb: reclaim-only when the sweep looks stop-hunty and thin; wait for BOS when the tape is fast and I need confirmation I am not fading strength. Equal highs that formed over many hours deserve more respect than two accidental prints that look equal if you squint.

I mark equal highs before London when I can. Discovering them mid-spike is how you rationalise a late click.
  • Reclaim entry or wait for BOS — which camp are you in?
  • Does equal-highs context change that choice for you?
This sits next to the broader sweep-vs-chase discussion, but I want the equal-highs case specifically.
Hi LondonScalper,

I firmly sit in the context-dependent hybrid camp, but if forced to choose a baseline survival mechanism, I lean toward waiting for the BOS (Break of Structure). Your evolution from firing at the first reclaim wick to requiring either a firm hold or structural confirmation is exactly what separates sustainable trading from guessing.

To answer your second question: the equal-highs context absolutely changes the choice.

Equal highs (EQHs) are not just resistance levels; they are engineered liquidity pools. Because they are highly visible to retail participants, a sweep of a legitimate EQH triggers a massive concentration of buy-stops and breakout orders. This uniquely concentrated liquidity dictates how the entry must be handled:

The Reclaim-Only Scenario (The Snap): When those multi-hour EQHs are swept, the reversal should be violent and immediate. If the tape shows a fast, thin, wick-heavy stab that instantly snaps back below the line, a reclaim entry is justified. The narrative is complete: the stops were triggered solely to fill larger short orders. If price hangs out above the EQHs for more than a candle or two, the reclaim thesis is dead—it's no longer a trap; it's acceptance.

The BOS Mandate (The Displacement Filter): Because EQHs are such strong magnets, a sweep often brings heavy volume. When the tape is fast and sweeping the EQHs with full-bodied displacement, waiting for a BOS becomes mandatory. Fading that momentum without a lower-timeframe structural shift is stepping in front of a freight train. The BOS is the required proof that the aggressive sweep was a manipulation phase (like a London Open Judas Swing) rather than the start of a true trend expansion.

Your rule to pre-mark them before London is critical. The London open specializes in hunting Asian session EQHs to set the high or low of the day. If you are identifying the EQHs mid-spike, you are already reacting to price rather than anticipating it, which almost always results in a highly emotional, poorly priced click.

When you do opt to wait for the BOS after a fast, displacement-heavy sweep, what lower timeframe are you using to confirm that structural shift without getting chopped up in the noise?
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Equal highs swept at London open: reclaim entry vs wait for BOS

Post by PTScalper »

Here is a complete TradingView Pine Script (v5) built exactly around the logic i just described.

Rather than a generic "reversal" indicator, this script is purpose-built for your specific philosophy. It mechanically identifies Equal Highs (EQHs), projects them as magnets, and then actively watches how price behaves when that liquidity is swept—separating the Immediate Reclaims (the "Snap") from the Micro BOS (the momentum shift).

The Pine Script (v5)

Code: Select all

//@version=5
indicator("Equal Highs: Sweep, Reclaim & BOS", overlay=true, max_lines_count=100)

// ==============================================================================
// 1. INPUTS
// ==============================================================================
grp1 = "Equal Highs Settings"
pLen = input.int(10, "Pivot Lookback Bars (Left & Right)", group=grp1, tooltip="How many bars on each side to confirm a swing high. Higher = more significant highs.")
thresholdTicks = input.float(15.0, "EQH Tolerance (Ticks)", group=grp1, tooltip="Maximum distance between two highs to be considered 'Equal'. 10 ticks = 1 pip on 5-digit forex.")

grp2 = "Signal Toggles"
showReclaim = input.bool(true, "Show Reclaim Signals", group=grp2)
showBOS = input.bool(true, "Show Micro BOS Signals", group=grp2)

// ==============================================================================
// 2. STATE VARIABLES
// ==============================================================================
var float p1_price = na, var int p1_time = na // Most recent pivot
var float p2_price = na, var int p2_time = na // Previous pivot
var float activeEQH = na                      // The active magnet level
var line eqhLine = na                         // Visual line for the EQH
var bool isSwept = false                      // Has the level been pierced?
var float sweepLow = na                       // Tracks the micro-structure low during the sweep

// ==============================================================================
// 3. IDENTIFYING MULTI-HOUR EQUAL HIGHS
// ==============================================================================
// Find pivot highs
ph = ta.pivothigh(high, pLen, pLen)
threshold = thresholdTicks * syminfo.mintick

if not na(ph)
    // Shift old pivot back, store new pivot
    p2_price := p1_price
    p2_time := p1_time
    p1_price := ph
    p1_time := bar_index - pLen

    // Check if the two recent pivots form an Equal High
    if not na(p2_price) and math.abs(p1_price - p2_price) <= threshold
        activeEQH := math.max(p1_price, p2_price) // Set magnet at the absolute highest point
        isSwept := false
        sweepLow := na
        
        // Draw the EQH Magnet Line
        eqhLine := line.new(p2_time, activeEQH, p1_time, activeEQH, color=color.new(color.red, 20), style=line.style_solid, width=2)
        line.extend(eqhLine, extend.right)

// ==============================================================================
// 4. THE TAPE: RECLAIMS VS BOS 
// ==============================================================================
reclaimTrigger = false
bosTrigger = false

if not na(activeEQH)
    
    // SCENARIO A: The Initial Sweep
    if high > activeEQH and not isSwept
        isSwept := true
        sweepLow := low // Mark the structural low of the candle that sweeps the EQH
        
        // Visual update: Dim the line to show stops were hit
        line.set_color(eqhLine, color.new(color.gray, 50)) 
        line.set_style(eqhLine, line.style_dashed)
        line.set_extend(eqhLine, extend.none) // Stop extending after sweep
        line.set_x2(eqhLine, bar_index)

        // Check for Immediate Reclaim (Thin, stop-hunt tape)
        if close < activeEQH
            reclaimTrigger := true
            activeEQH := na // Kill the level so it doesn't fire twice

    // SCENARIO B: Tracking the Sweep for a Delayed Reclaim or BOS
    else if isSwept
        
        // Trail the micro-structure low if price continues pushing up with displacement
        if high > high[1] and low > sweepLow
            sweepLow := low
            
        // 1. Delayed Reclaim (Closed above previously, now closes below)
        if close < activeEQH and close[1] >= activeEQH
            reclaimTrigger := true
            activeEQH := na // Kill the level
            
        // 2. Break of Structure (Tape is fast, price holds above EQH, but breaks micro-structure)
        else if not na(sweepLow) and close < sweepLow and close[1] >= sweepLow
            bosTrigger := true
            activeEQH := na // Kill the level

// ==============================================================================
// 5. PLOTTING
// ==============================================================================
plotshape(showReclaim and reclaimTrigger, "Reclaim", shape.triangledown, location.abovebar, color=color.red, size=size.small, text="RECLAIM")
plotshape(showBOS and bosTrigger, "Micro BOS", shape.xcross, location.abovebar, color=color.orange, size=size.small, text="BOS")

// Optional: Plot the micro structure low during a sweep for visual clarity
plot(isSwept and not na(activeEQH) ? sweepLow : na, "Sweep Structure Low", color=color.new(color.orange, 50), style=plot.style_cross)
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Equal highs swept at London open: reclaim entry vs wait for BOS

Post by PTScalper »

How to use this alongside your methodology:

The Magnet (Solid Red Line): The script looks for two structural pivot highs that land within a few ticks of each other. Once validated, it projects a solid red line forward. This satisfies your rule of mapping them out before the London volume hits.

The Sweep & Dim: The exact moment price wicks above the EQH, the script changes the line to a dashed gray line and stops extending it. The stops have been hunted; the level is now "spent."

The "Reclaim" Signal (Red Triangle): If the candle sweeps the highs but fails to hold and closes back below the level, a red triangle fires. This is your cue for the "thin tape / snap-back" scenario.

The "BOS" Signal (Orange Cross): If price sweeps the highs with displacement and holds above the line, the script starts trailing the low of the advancing candles (plotted as little orange crosses). If price subsequently drops and closes below that micro-structure low, it fires a BOS signal. This protects you from fading strength while still getting you into the reversal once structure shifts.

Tuning the inputs:
Depending on the asset you trade (e.g., NQ, Gold, EURUSD) and timeframe (e.g., 5m, 15m), you will need to adjust the Pivot Lookback (I suggest 10-15 for multi-hour highs) and the EQH Tolerance (how "perfect" the highs need to be to count as equal).
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Equal highs swept at London open: reclaim entry vs wait for BOS

Post by PTScalper »

To elevate this to a "Pro" level, we need to move away from basic shapes and single-variable tracking. A professional, institutional-grade tool needs to do the following:

Both Sides of the Book: It must track both Equal Highs (Buy-Side Liquidity) and Equal Lows (Sell-Side Liquidity).

Session Context: You mentioned the London Open. The script should visually highlight specific time windows (like the Asian Range) where these EQHs/EQLs are typically engineered, so you can watch them get hunted at the London/NY open.

User-Defined Types (UDTs): Pro scripts use Pine Script’s object-oriented structures to manage complex states cleanly without bugging out during live tape.

Actionable Risk UI: Instead of just a dot on the screen, a pro tool plots a label showing the exact Entry, Stop Loss (the absolute extreme of the sweep), and a visual Risk line.

Automation Ready: Fully integrated alert() function for webhook trading or mobile notifications.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Equal highs swept at London open: reclaim entry vs wait for BOS

Post by PTScalper »

Here is the fully rebuilt Institutional Liquidity & Sweep [PRO] script.

The Pine Script (v5)

Code: Select all

//@version=5
indicator("Institutional Liquidity: EQH/EQL Sweeps [PRO]", overlay=true, max_lines_count=500, max_labels_count=500, max_boxes_count=100)

// ==============================================================================
// 1. INPUTS & SETTINGS
// ==============================================================================
grp_liq = "Liquidity & Structure"
pLen = input.int(10, "Pivot Lookback", group=grp_liq, tooltip="Bars needed on each side to form a swing point.")
tickTol = input.float(15.0, "Equal Tolerance (Ticks)", group=grp_liq, tooltip="Max distance between two pivots to be considered 'Equal'.")

grp_ses = "Session & Context"
useSession = input.bool(true, "Highlight Accumulation Session", group=grp_ses)
sessTime = input.session("1800-0200", "Accumulation Session (Exchange Time)", group=grp_ses, tooltip="E.g., Asian session. Sweeps of highs/lows formed here are high probability.")
sessColor = input.color(color.new(color.blue, 90), "Session Color", group=grp_ses)

grp_ui = "Visuals & Alerts"
showLabels = input.bool(true, "Show Entry & Stop Loss Labels", group=grp_ui)

// ==============================================================================
// 2. USER-DEFINED TYPES (UDT) FOR STATE MANAGEMENT
// ==============================================================================
type LiquidityLevel
    float price       = na
    int   timeStart   = na
    bool  isActive    = false
    bool  isSwept     = false
    float sweepExtr   = na // Highest high (EQH) or Lowest low (EQL) of the sweep
    float triggerBOS  = na // Micro structure to break for BOS entry
    line  visualLine  = na

var LiquidityLevel eqh = LiquidityLevel.new()
var LiquidityLevel eql = LiquidityLevel.new()

// ==============================================================================
// 3. SESSION HIGHLIGHTING
// ==============================================================================
inSession = not na(time(timeframe.period, sessTime))
var int sessStart = na
if inSession and not inSession[1]
    sessStart := time
if not inSession and inSession[1] and useSession
    box.new(sessStart, high, time, low, xloc=xloc.bar_time, bgcolor=sessColor, border_color=na)

// ==============================================================================
// 4. CORE LOGIC: IDENTIFYING EQUAL HIGHS (EQH) & EQUAL LOWS (EQL)
// ==============================================================================
threshold = tickTol * syminfo.mintick

// Find Pivots
ph = ta.pivothigh(high, pLen, pLen)
pl = ta.pivotlow(low, pLen, pLen)

// Track previous pivots to compare against
var float last_ph = na, var int time_ph = na
var float last_pl = na, var int time_pl = na

// Evaluate EQH
if not na(ph)
    if not na(last_ph) and math.abs(ph - last_ph) <= threshold
        // Valid EQH Found
        eqh.price := math.max(ph, last_ph)
        eqh.timeStart := time_ph
        eqh.isActive := true
        eqh.isSwept := false
        if not na(eqh.visualLine)
            line.delete(eqh.visualLine)
        eqh.visualLine := line.new(eqh.timeStart, eqh.price, time, eqh.price, xloc=xloc.bar_time, color=color.new(color.red, 20), width=2, style=line.style_solid)
        line.extend(eqh.visualLine, extend.right)
    
    last_ph := ph
    time_ph := time[pLen]

// Evaluate EQL
if not na(pl)
    if not na(last_pl) and math.abs(pl - last_pl) <= threshold
        // Valid EQL Found
        eql.price := math.min(pl, last_pl)
        eql.timeStart := time_pl
        eql.isActive := true
        eql.isSwept := false
        if not na(eql.visualLine)
            line.delete(eql.visualLine)
        eql.visualLine := line.new(eql.timeStart, eql.price, time, eql.price, xloc=xloc.bar_time, color=color.new(color.blue, 20), width=2, style=line.style_solid)
        line.extend(eql.visualLine, extend.right)

    last_pl := pl
    time_pl := time[pLen]

// ==============================================================================
// 5. THE TAPE: SWEEP, RECLAIM, AND BOS EXECUTION
// ==============================================================================

// Helper Function for Entry UI
draw_entry(txt, extPrice, isShort) =>
    if showLabels
        clr = isShort ? color.red : color.blue
        lblY = isShort ? high : low
        sty = isShort ? label.style_label_down : label.style_label_up
        slText = "\nSL: " + str.tostring(extPrice, format.mintick)
        label.new(time, lblY, txt + slText, xloc=xloc.bar_time, color=clr, textcolor=color.white, style=sty, size=size.small)

// --- PROCESS EQH (SHORT SCENARIOS) ---
if eqh.isActive
    // Initial Sweep
    if high > eqh.price and not eqh.isSwept
        eqh.isSwept := true
        eqh.sweepExtr := high
        eqh.triggerBOS := low
        line.set_style(eqh.visualLine, line.style_dashed)
        line.set_color(eqh.visualLine, color.new(color.gray, 50))
        line.set_extend(eqh.visualLine, extend.none)
        line.set_x2(eqh.visualLine, time)
        
        // Instant Reclaim (Thin Tape)
        if close < eqh.price
            draw_entry("RECLAIM", eqh.sweepExtr, true)
            alert("EQH Instant Reclaim Short. SL: " + str.tostring(eqh.sweepExtr), alert.freq_once_per_bar_close)
            eqh.isActive := false
            
    // Swept, now waiting for Delayed Reclaim or BOS
    else if eqh.isSwept
        // Trail extreme and micro-structure low
        if high > eqh.sweepExtr
            eqh.sweepExtr := high
        if high > high[1] and low > eqh.triggerBOS
            eqh.triggerBOS := low
            
        // Trigger 1: Delayed Reclaim
        if close < eqh.price and close[1] >= eqh.price
            draw_entry("RECLAIM", eqh.sweepExtr, true)
            alert("EQH Delayed Reclaim Short. SL: " + str.tostring(eqh.sweepExtr), alert.freq_once_per_bar_close)
            eqh.isActive := false
            
        // Trigger 2: Micro BOS (Displacement Filter)
        else if close < eqh.triggerBOS and close[1] >= eqh.triggerBOS
            draw_entry("BOS", eqh.sweepExtr, true)
            alert("EQH Micro BOS Short. SL: " + str.tostring(eqh.sweepExtr), alert.freq_once_per_bar_close)
            eqh.isActive := false

// --- PROCESS EQL (LONG SCENARIOS) ---
if eql.isActive
    // Initial Sweep
    if low < eql.price and not eql.isSwept
        eql.isSwept := true
        eql.sweepExtr := low
        eql.triggerBOS := high
        line.set_style(eql.visualLine, line.style_dashed)
        line.set_color(eql.visualLine, color.new(color.gray, 50))
        line.set_extend(eql.visualLine, extend.none)
        line.set_x2(eql.visualLine, time)
        
        // Instant Reclaim (Thin Tape)
        if close > eql.price
            draw_entry("RECLAIM", eql.sweepExtr, false)
            alert("EQL Instant Reclaim Long. SL: " + str.tostring(eql.sweepExtr), alert.freq_once_per_bar_close)
            eql.isActive := false
            
    // Swept, now waiting for Delayed Reclaim or BOS
    else if eql.isSwept
        // Trail extreme and micro-structure high
        if low < eql.sweepExtr
            eql.sweepExtr := low
        if low < low[1] and high < eql.triggerBOS
            eql.triggerBOS := high
            
        // Trigger 1: Delayed Reclaim
        if close > eql.price and close[1] <= eql.price
            draw_entry("RECLAIM", eql.sweepExtr, false)
            alert("EQL Delayed Reclaim Long. SL: " + str.tostring(eql.sweepExtr), alert.freq_once_per_bar_close)
            eql.isActive := false
            
        // Trigger 2: Micro BOS (Displacement Filter)
        else if close > eql.triggerBOS and close[1] <= eql.triggerBOS
            draw_entry("BOS", eql.sweepExtr, false)
            alert("EQL Micro BOS Long. SL: " + str.tostring(eql.sweepExtr), alert.freq_once_per_bar_close)
            eql.isActive := false
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Equal highs swept at London open: reclaim entry vs wait for BOS

Post by PTScalper »

What makes this code "Pro":

Symmetry (Buy-Side & Sell-Side): It now actively seeks Equal Lows (EQLs) as well, drawing thick blue lines. A sweep of EQLs fires bullish setups, providing complete coverage of the market's liquidity pools.

The Session Box (Killzones): In the settings, you can define a time range (defaulted to 1800-0200 exchange time, roughly the Asian session). It will paint this block blue on your chart. This allows you to visually identify EQHs/EQLs that built up during low-volume hours, so you can stalk the exact moment London opens and sweeps them.

Dynamic Stop Loss Labels: When a valid Reclaim or BOS fires, the script draws a clean label on the chart. Crucially, it doesn't just say "Entry"—it programmatically references eqh.sweepExtr (the absolute highest tick of the sweep candle) and prints the exact Stop Loss price on the label. No guessing where your invalidation point is.

Proper State Management: By using Pine Script v5 type declarations (LiquidityLevel), the script encapsulates all data for a level—its price, its extreme point, its micro-structure low, and its line ID. This prevents the messy "spaghetti code" that causes indicators to repaint or mix up long/short logic when multiple things happen at once.

Webhook Automation: The alert() function is fully coded with dynamic text. You can hook this straight into a service like 3Commas or Alertatron by setting up a single "Any Alert() Function Call" alert in TradingView.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Equal highs swept at London open: reclaim entry vs wait for BOS

Post by PTScalper »

Here is the complete translation of the PRO Equal Highs/Lows script into a cTrader Custom Indicator using C# (.NET) and the cTrader Automate API.

cTrader uses a completely different architecture than TradingView (C# vs Pine Script). To ensure it performs at a professional institutional grade, I have custom-built the pivot detection, session handling (which draws background rectangles), and state management to work seamlessly with cTrader's tick-by-tick charting engine.

How to Install in cTrader:

1.) Open cTrader and go to the Automate tab (left menu).

2.) Click New -> Indicator.

3.) Name it InstitutionalLiquidityPro.

4.) Delete all the default code in the editor and paste the code below.

5.) Click Build (or press Ctrl+B).
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Equal highs swept at London open: reclaim entry vs wait for BOS

Post by PTScalper »

The cTrader C# Code

Code: Select all

using System;
using cAlgo.API;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class InstitutionalLiquidityPro : Indicator
    {
        // ==============================================================================
        // 1. PARAMETERS
        // ==============================================================================
        [Parameter("Pivot Lookback", Group = "Liquidity & Structure", DefaultValue = 10, MinValue = 2)]
        public int PLen { get; set; }

        [Parameter("Equal Tolerance (Ticks)", Group = "Liquidity & Structure", DefaultValue = 15.0)]
        public double TickTol { get; set; }

        [Parameter("Highlight Accumulation Session", Group = "Session & Context", DefaultValue = true)]
        public bool UseSession { get; set; }

        [Parameter("Session Start Hour (UTC)", Group = "Session & Context", DefaultValue = 18, MinValue = 0, MaxValue = 23)]
        public int SessionStartHour { get; set; }

        [Parameter("Session End Hour (UTC)", Group = "Session & Context", DefaultValue = 2, MinValue = 0, MaxValue = 23)]
        public int SessionEndHour { get; set; }

        [Parameter("Session Color", Group = "Session & Context", DefaultValue = "20, 0, 0, 255")]
        public string SessionColorStr { get; set; }

        [Parameter("Show Entry Labels", Group = "Visuals & Alerts", DefaultValue = true)]
        public bool ShowLabels { get; set; }

        // ==============================================================================
        // 2. STATE MANAGEMENT (UDT)
        // ==============================================================================
        private class LiquidityLevel
        {
            public double Price;
            public int TimeIndex;
            public bool IsActive;
            public bool IsSwept;
            public double SweepExtr;
            public double TriggerBOS;
            public string LineName;
        }

        private LiquidityLevel _eqh;
        private LiquidityLevel _eql;

        private double _lastPh, _lastPl;
        private int _timePh, _timePl;
        
        private Color _sessionColor;
        private int _sessionStartIndex = -1;
        private bool _inSession = false;

        // ==============================================================================
        // 3. INITIALIZATION
        // ==============================================================================
        protected override void Initialize()
        {
            _eqh = new LiquidityLevel { IsActive = false };
            _eql = new LiquidityLevel { IsActive = false };
            
            _lastPh = double.NaN;
            _lastPl = double.NaN;
            
            // Parse Session Color string to C# Color
            var colorParts = SessionColorStr.Split(',');
            if (colorParts.Length == 4)
            {
                _sessionColor = Color.FromArgb(
                    int.Parse(colorParts[0].Trim()), 
                    int.Parse(colorParts[1].Trim()), 
                    int.Parse(colorParts[2].Trim()), 
                    int.Parse(colorParts[3].Trim()));
            }
            else
            {
                _sessionColor = Color.FromArgb(20, Color.Blue);
            }
        }

        // ==============================================================================
        // 4. CORE CALCULATION LOGIC (Runs per bar / per tick)
        // ==============================================================================
        public override void Calculate(int index)
        {
            // We need enough bars to look back for pivots
            if (index < PLen * 2) return;

            DrawSessionBoxes(index);
            DetectPivots(index);
            ProcessEQH(index);
            ProcessEQL(index);
            
            // Extend active lines to the current bar
            if (_eqh.IsActive && !_eqh.IsSwept)
                Chart.DrawLine(_eqh.LineName, Bars.OpenTimes[_eqh.TimeIndex], _eqh.Price, Bars.OpenTimes[index], _eqh.Price, Color.Red, 2, LineStyle.Solid);
                
            if (_eql.IsActive && !_eql.IsSwept)
                Chart.DrawLine(_eql.LineName, Bars.OpenTimes[_eql.TimeIndex], _eql.Price, Bars.OpenTimes[index], _eql.Price, Color.Blue, 2, LineStyle.Solid);
        }

        // ==============================================================================
        // 5. HELPER METHODS
        // ==============================================================================
        
        private void DetectPivots(int index)
        {
            int pivotIndex = index - PLen;
            double threshold = TickTol * Symbol.TickSize;

            // --- Check for Pivot High ---
            bool isPivotHigh = true;
            for (int i = pivotIndex - PLen; i <= pivotIndex + PLen; i++)
            {
                if (i == pivotIndex) continue;
                if (Bars.HighPrices[i] > Bars.HighPrices[pivotIndex])
                {
                    isPivotHigh = false;
                    break;
                }
            }

            if (isPivotHigh)
            {
                double ph = Bars.HighPrices[pivotIndex];
                if (!double.IsNaN(_lastPh) && Math.Abs(ph - _lastPh) <= threshold)
                {
                    // EQH Validated
                    _eqh.Price = Math.Max(ph, _lastPh);
                    _eqh.TimeIndex = _timePh;
                    _eqh.IsActive = true;
                    _eqh.IsSwept = false;
                    _eqh.LineName = "EQH_" + Bars.OpenTimes[pivotIndex].Ticks;
                }
                _lastPh = ph;
                _timePh = pivotIndex;
            }

            // --- Check for Pivot Low ---
            bool isPivotLow = true;
            for (int i = pivotIndex - PLen; i <= pivotIndex + PLen; i++)
            {
                if (i == pivotIndex) continue;
                if (Bars.LowPrices[i] < Bars.LowPrices[pivotIndex])
                {
                    isPivotLow = false;
                    break;
                }
            }

            if (isPivotLow)
            {
                double pl = Bars.LowPrices[pivotIndex];
                if (!double.IsNaN(_lastPl) && Math.Abs(pl - _lastPl) <= threshold)
                {
                    // EQL Validated
                    _eql.Price = Math.Min(pl, _lastPl);
                    _eql.TimeIndex = _timePl;
                    _eql.IsActive = true;
                    _eql.IsSwept = false;
                    _eql.LineName = "EQL_" + Bars.OpenTimes[pivotIndex].Ticks;
                }
                _lastPl = pl;
                _timePl = pivotIndex;
            }
        }

        private void ProcessEQH(int index)
        {
            if (!_eqh.IsActive) return;

            double high = Bars.HighPrices[index];
            double low = Bars.LowPrices[index];
            double close = Bars.ClosePrices[index];
            double prevClose = Bars.ClosePrices[index - 1];

            // 1. Initial Sweep
            if (high > _eqh.Price && !_eqh.IsSwept)
            {
                _eqh.IsSwept = true;
                _eqh.SweepExtr = high;
                _eqh.TriggerBOS = low;

                // Dim the line (Stop Hunt hit)
                Chart.DrawLine(_eqh.LineName, Bars.OpenTimes[_eqh.TimeIndex], _eqh.Price, Bars.OpenTimes[index], _eqh.Price, Color.Gray, 1, LineStyle.Dots);

                // Instant Reclaim
                if (close < _eqh.Price)
                {
                    DrawEntryLabel("RECLAIM", index, _eqh.SweepExtr, true);
                    _eqh.IsActive = false;
                }
            }
            // 2. Tracking the Sweep
            else if (_eqh.IsSwept)
            {
                // Trail Extreme and BOS Trigger
                if (high > _eqh.SweepExtr) _eqh.SweepExtr = high;
                if (high > Bars.HighPrices[index - 1] && low > _eqh.TriggerBOS) _eqh.TriggerBOS = low;

                // Delayed Reclaim
                if (close < _eqh.Price && prevClose >= _eqh.Price)
                {
                    DrawEntryLabel("RECLAIM", index, _eqh.SweepExtr, true);
                    _eqh.IsActive = false;
                }
                // Micro BOS
                else if (close < _eqh.TriggerBOS && prevClose >= _eqh.TriggerBOS)
                {
                    DrawEntryLabel("BOS", index, _eqh.SweepExtr, true);
                    _eqh.IsActive = false;
                }
            }
        }

        private void ProcessEQL(int index)
        {
            if (!_eql.IsActive) return;

            double high = Bars.HighPrices[index];
            double low = Bars.LowPrices[index];
            double close = Bars.ClosePrices[index];
            double prevClose = Bars.ClosePrices[index - 1];

            // 1. Initial Sweep
            if (low < _eql.Price && !_eql.IsSwept)
            {
                _eql.IsSwept = true;
                _eql.SweepExtr = low;
                _eql.TriggerBOS = high;

                // Dim the line
                Chart.DrawLine(_eql.LineName, Bars.OpenTimes[_eql.TimeIndex], _eql.Price, Bars.OpenTimes[index], _eql.Price, Color.Gray, 1, LineStyle.Dots);

                // Instant Reclaim
                if (close > _eql.Price)
                {
                    DrawEntryLabel("RECLAIM", index, _eql.SweepExtr, false);
                    _eql.IsActive = false;
                }
            }
            // 2. Tracking the Sweep
            else if (_eql.IsSwept)
            {
                // Trail Extreme and BOS Trigger
                if (low < _eql.SweepExtr) _eql.SweepExtr = low;
                if (low < Bars.LowPrices[index - 1] && high < _eql.TriggerBOS) _eql.TriggerBOS = high;

                // Delayed Reclaim
                if (close > _eql.Price && prevClose <= _eql.Price)
                {
                    DrawEntryLabel("RECLAIM", index, _eql.SweepExtr, false);
                    _eql.IsActive = false;
                }
                // Micro BOS
                else if (close > _eql.TriggerBOS && prevClose <= _eql.TriggerBOS)
                {
                    DrawEntryLabel("BOS", index, _eql.SweepExtr, false);
                    _eql.IsActive = false;
                }
            }
        }

        private void DrawEntryLabel(string txt, int index, double stopLoss, bool isShort)
        {
            if (!ShowLabels) return;

            string name = "LBL_" + txt + "_" + Bars.OpenTimes[index].Ticks;
            Color clr = isShort ? Color.Red : Color.Blue;
            double yPos = isShort ? Bars.HighPrices[index] + (10 * Symbol.TickSize) : Bars.LowPrices[index] - (10 * Symbol.TickSize);
            VerticalAlignment vAlign = isShort ? VerticalAlignment.Bottom : VerticalAlignment.Top;

            string labelText = $"{txt}\nSL: {Math.Round(stopLoss, Symbol.Digits)}";
            
            Chart.DrawText(name, labelText, Bars.OpenTimes[index], yPos, clr, vAlign, HorizontalAlignment.Center);
        }

        private void DrawSessionBoxes(int index)
        {
            if (!UseSession) return;

            var time = Bars.OpenTimes[index];
            int h = time.Hour;

            bool currentInSession = (SessionStartHour > SessionEndHour) 
                ? (h >= SessionStartHour || h < SessionEndHour) 
                : (h >= SessionStartHour && h < SessionEndHour);

            if (currentInSession && !_inSession)
            {
                _sessionStartIndex = index;
                _inSession = true;
            }
            else if (!currentInSession && _inSession)
            {
                // Session ended, draw the box
                double highest = double.MinValue;
                double lowest = double.MaxValue;

                for (int i = _sessionStartIndex; i < index; i++)
                {
                    if (Bars.HighPrices[i] > highest) highest = Bars.HighPrices[i];
                    if (Bars.LowPrices[i] < lowest) lowest = Bars.LowPrices[i];
                }

                string boxName = "Session_" + Bars.OpenTimes[_sessionStartIndex].Ticks;
                Chart.DrawRectangle(boxName, Bars.OpenTimes[_sessionStartIndex], highest, Bars.OpenTimes[index], lowest, _sessionColor)
                     .IsFilled = true;

                _inSession = false;
            }
        }
    }
}
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
Post Reply