Indicator · Pine Script v6 · On the chart

Ghost Engine

by h33rnan

Ghost Engine is an overlay indicator that tracks the Asian session range, London and New York killzones, and the New York midnight open.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code146
Settings5inputs
LicenceMIT
Last update6 months ago12 Apr 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

146 lines of Pine Script v6 from Ghost-Engine.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

Ghost-Engine.pine
//@version=6
indicator('Ghost Engine', max_labels_count = 500, max_lines_count = 500, max_boxes_count = 500, max_bars_back = 5000, calc_bars_count = 10000, overlay = true)

// ═══════════════════════════════════════════════════════════════════════════════
// 1. TEMAS & UI QUIRÚRGICA (MODO GHOST)
// ═══════════════════════════════════════════════════════════════════════════════
string G_THEME = "Estética Quirúrgica & UI"
string themeChoice = input.string("Artic", "Tema Visual", options = ["Artic", "Mono"], group=G_THEME)
bool isLight = input.bool(false, "☀️ Modo Claro", group=G_THEME)

color thBull = themeChoice == "Mono" ? (isLight ? #616161 : #9e9e9e) : (isLight ? #0288d1 : #4fc3f7) 
color thBear = themeChoice == "Mono" ? (isLight ? #212121 : #424242) : (isLight ? #512da8 : #b39ddb) 
color txtMain = isLight ? color.black : color.white
color txtSub = isLight ? color.new(color.black, 60) : color.new(color.white, 70)
color trapCol = color.rgb(255, 111, 0)
color bgHud = color.new(color.black, 100) 

// ══════════════════════════════════════════════════════════════════════════
// 2. PARÁMETROS: ESTRUCTURA Y TIEMPO
// ══════════════════════════════════════════════════════════════════════════
string G_CORE = "Motor Quant"
bool use_atr_mode   = input.bool(true, "APEX: Usar % Dinámico (ATR)", group=G_CORE)
float atr_mult      = input.float(3.0, "APEX: Multiplicador ATR", minval=0.1, step=0.1, group=G_CORE)
bool show_ote       = input.bool(true, "APEX: Proyectar OTE Box", group=G_CORE)

string tz_ny = "America/New_York"
string asia_ses = "1900-0000"

// ══════════════════════════════════════════════════════════════════════════
// 3. MOTOR CHRONO (TRAMPAS INVISIBLES)
// ══════════════════════════════════════════════════════════════════════════
tf = timeframe.period
is_asia = math.sign(nz(time(tf, asia_ses, tz_ny)))
is_ldn  = math.sign(nz(time(tf, "0200-1100", tz_ny)))
is_ny   = math.sign(nz(time(tf, "0700-1600", tz_ny)))
is_mid  = math.sign(nz(time(tf, "0000-0005", tz_ny)))

var float midnight_price = na
if is_mid > is_mid[1]
    midnight_price := open

var float asia_max = na, var float asia_min = na
var int bsl_status = 0, var line bsl_line = na, var label bsl_trap_lbl = na
var int ssl_status = 0, var line ssl_line = na, var label ssl_trap_lbl = na

if is_asia > is_asia[1]
    asia_max := high, asia_min := low
    bsl_status := 0, ssl_status := 0

if is_asia == 1
    asia_max := math.max(high, asia_max), asia_min := math.min(low, asia_min)

if is_asia[1] == 1 and is_asia == 0
    bsl_line := line.new(bar_index, asia_max, bar_index + 10, asia_max, color=color.new(txtSub, 50), style=line.style_dotted)
    ssl_line := line.new(bar_index, asia_min, bar_index + 10, asia_min, color=color.new(txtSub, 50), style=line.style_dotted)

if not na(bsl_line) and bsl_status != 1
    line.set_x2(bsl_line, bar_index + 5)
    if close > asia_max
        bsl_status := 1, line.delete(bsl_line), bsl_line := na
    else if high > asia_max and close <= asia_max and bsl_status == 0
        bsl_status := 2, line.set_color(bsl_line, trapCol), line.set_style(bsl_line, line.style_solid)
        bsl_trap_lbl := label.new(bar_index, high, "[ ⚠ TRAP ]", color=trapCol, textcolor=color.black, style=label.style_label_down, size=size.tiny)

if not na(ssl_line) and ssl_status != 1
    line.set_x2(ssl_line, bar_index + 5)
    if close < asia_min
        ssl_status := 1, line.delete(ssl_line), ssl_line := na
    else if low < asia_min and close >= asia_min and ssl_status == 0
        ssl_status := 2, line.set_color(ssl_line, trapCol), line.set_style(ssl_line, line.style_solid)
        ssl_trap_lbl := label.new(bar_index, low, "[ ⚠ TRAP ]", color=trapCol, textcolor=color.black, style=label.style_label_up, size=size.tiny)

// ══════════════════════════════════════════════════════════════════════════
// 4. MOTOR APEX (ESTRUCTURA Y OTE)
// ══════════════════════════════════════════════════════════════════════════
var int direction = 0, var float last_pivot_price = na, var int last_pivot_index = na
var float current_extreme_price = na, var int current_extreme_index = na, var line current_line = na
var int trend_state = 0, var float pending_high = na, var int pending_high_idx = na
var float pending_low = na, var int pending_low_idx = na, var string last_break_type = "NONE"
var box active_ote = na
var float ph1_price = na, var int ph1_index = na, var float pl1_price = na, var int pl1_index = na 

float pct_change = (use_atr_mode ? (ta.atr(14) / close * 100 * atr_mult) : 5.0) / 100
float src_high = high, float src_low = low

if bar_index == 0
    direction := 1, trend_state := 1, last_pivot_price := src_low, last_pivot_index := bar_index
    current_extreme_price := src_high, current_extreme_index := bar_index

if not na(pending_high) and close > pending_high
    is_choch = (trend_state == -1), trend_state := 1, last_break_type := is_choch ? "CHoCH (BULL)" : "BOS (BULL)"
    line.new(pending_high_idx, pending_high, bar_index, pending_high, color=color.new(thBull, 60), style=line.style_dashed, width=1)
    label.new(bar_index, pending_high, is_choch ? "CHoCH" : "BOS", color=color.new(color.black, 100), textcolor=thBull, style=label.style_label_down, size=size.tiny)
    pending_high := na
if not na(pending_low) and close < pending_low
    is_choch = (trend_state == 1), trend_state := -1, last_break_type := is_choch ? "CHoCH (BEAR)" : "BOS (BEAR)"
    line.new(pending_low_idx, pending_low, bar_index, pending_low, color=color.new(thBear, 60), style=line.style_dashed, width=1)
    label.new(bar_index, pending_low, is_choch ? "CHoCH" : "BOS", color=color.new(color.black, 100), textcolor=thBear, style=label.style_label_up, size=size.tiny)
    pending_low := na

if direction == 1
    if src_high > current_extreme_price
        current_extreme_price := src_high, current_extreme_index := bar_index, line.set_xy2(current_line, current_extreme_index, current_extreme_price)
    if src_low < current_extreme_price * (1 - pct_change)
        ph1_price := current_extreme_price, ph1_index := current_extreme_index, pending_high := current_extreme_price, pending_high_idx := current_extreme_index
        if show_ote and not na(pl1_price)
            box.delete(active_ote)
            active_ote := box.new(ph1_index, ph1_price - (ph1_price - pl1_price) * 0.618, bar_index + 10, ph1_price - (ph1_price - pl1_price) * 0.786, border_color=color.new(thBull, 50), border_style=line.style_dashed, bgcolor=color.new(thBull, 90), text="OTE Buy", text_color=color.new(thBull, 50), text_size=size.tiny, text_halign=text.align_right)
        direction := -1, last_pivot_price := current_extreme_price, last_pivot_index := current_extreme_index
        current_extreme_price := src_low, current_extreme_index := bar_index
        current_line := line.new(last_pivot_index, last_pivot_price, current_extreme_index, current_extreme_price, color=color.new(thBear, 20), width=1)
else
    if src_low < current_extreme_price
        current_extreme_price := src_low, current_extreme_index := bar_index, line.set_xy2(current_line, current_extreme_index, current_extreme_price)
    if src_high > current_extreme_price * (1 + pct_change)
        pl1_price := current_extreme_price, pl1_index := current_extreme_index, pending_low := current_extreme_price, pending_low_idx := current_extreme_index
        if show_ote and not na(ph1_price)
            box.delete(active_ote)
            active_ote := box.new(pl1_index, pl1_price + (ph1_price - pl1_price) * 0.786, bar_index + 10, pl1_price + (ph1_price - pl1_price) * 0.618, border_color=color.new(thBear, 50), border_style=line.style_dashed, bgcolor=color.new(thBear, 90), text="OTE Sell", text_color=color.new(thBear, 50), text_size=size.tiny, text_halign=text.align_right)
        direction := 1, last_pivot_price := current_extreme_price, last_pivot_index := current_extreme_index
        current_extreme_price := src_high, current_extreme_index := bar_index
        current_line := line.new(last_pivot_index, last_pivot_price, current_extreme_index, current_extreme_price, color=color.new(thBull, 20), width=1)

if not na(active_ote)
    box.set_right(active_ote, bar_index + 10)

// ══════════════════════════════════════════════════════════════════════════
// 5. CINTA DE TELEMETRÍA (HUD MÍNIMO + FIRMA)
// ══════════════════════════════════════════════════════════════════════════
string active_session = is_ny == 1 ? "[ NY ZONE ]" : (is_ldn == 1 ? "[ LDN ZONE ]" : (is_asia == 1 ? "[ ASIA RANGE ]" : "OUT OF SESSION"))
color sess_col = is_ny == 1 ? thBull : (is_ldn == 1 ? thBear : txtSub)
string pd_text = not na(midnight_price) ? (close > midnight_price ? "BIAS: PREMIUM" : "BIAS: DISCOUNT") : "BIAS: WAITING"
color pd_color = not na(midnight_price) ? (close > midnight_price ? thBear : thBull) : txtSub

var table dash = table.new(position.top_right, 4, 2, border_width=0, bgcolor=bgHud)
if barstate.islast
    // Fila 1: Telemetría
    table.cell(dash, 0, 0, active_session, text_color=sess_col, text_size=size.small, text_font_family=font.family_monospace)
    table.cell(dash, 1, 0, "|  " + pd_text, text_color=pd_color, text_size=size.small, text_font_family=font.family_monospace)
    table.cell(dash, 2, 0, "|  APEX: " + (trend_state == 1 ? "BULL" : "BEAR") + " [" + last_break_type + "]", text_color=(trend_state == 1 ? thBull : thBear), text_size=size.small, text_font_family=font.family_monospace)
    string trapS = bsl_status == 2 ? "|  ⚠ TRAP BSL" : (ssl_status == 2 ? "|  ⚠ TRAP SSL" : "")
    table.cell(dash, 3, 0, trapS, text_color=trapCol, text_size=size.small, text_font_family=font.family_monospace)
    
    // Fila 2: Firma Integrada
    table.merge_cells(dash, 0, 1, 3, 1)
    table.cell(dash, 0, 1, "Created by H33RNAN", text_color=txtSub, text_size=size.normal, text_font_family=font.family_monospace, text_halign=text.align_center)

Overview

Ghost Engine prints a trap tag when price sweeps an Asian high or low and then closes back inside the range. It maps break of structure and change of character, and can project an optimal trade entry box for the next pullback. A one-line HUD shows the active session, midnight premium or discount bias, and structural state. Theme, light mode, ATR sizing, and the entry box are user settings. It does not place trades.

Details

Published by

h33rnan on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

SMC / ICT / price action, Sessions & time, Support & resistance, Screeners & dashboards

Markets

Forex

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Tema VisualstringArticthemeChoice
☀️ Modo ClaroboolfalseisLight
APEX: Usar % Dinámico (ATR)booltrueuse_atr_mode
APEX: Multiplicador ATRfloat3.0atr_mult
APEX: Proyectar OTE Boxbooltrueshow_ote
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Golden Bullet Strategy

by TradersPost
218 stars

The Golden Bullet Strategy is an overlay signal indicator based on Smart Money Concepts and time-based liquidity models. It identifies liquidity sweeps of a designated reference session range during a specified hunt window. It then confirms Market Structure Sh

Indicator v6 SMC / ICT / price actionSessions & time
Updated 3 months ago · None stated GitHub repository of Golden Bullet Strategy

This indicator detects and draws the first Fair Value Gap (FVG) that forms in each hourly session based on a selected lower timeframe, with specialized handling for Regular Trading Hours (RTH) confluence windows. It draws FVG range boxes, midpoint lines, hourl

Indicator v5 SMC / ICT / price actionSupport & resistance Repaints

Clusterbreak

by Jferheart
15 stars

This indicator identifies Break of Structure (BOS) and Market Structure Shift (MSS) zones, plotting automated bracket levels on the price chart. It triggers signals when a reversal breaks a swing point formed inside an opposing zone, projecting stop loss and t

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 4 weeks ago · None stated GitHub repository of Clusterbreak

MyTTFM - Clean

by dbruce1990
12 stars

MyTTFM - Clean draws a higher-timeframe candle overlay on the price chart and marks related ICT fractal structure. It plots configurable HTF candles, period separator lines, midpoint levels, a T-Spot box, and labels for recent C2 and C3 patterns plus swept lev

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · None stated GitHub repository of MyTTFM - Clean

Apex Protocol Assistant

by alboogycOdR
6 stars

Apex Protocol Assistant is a Smart Money Concepts indicator designed for session-based trading. It determines market direction using a higher timeframe Exponential Moving Average and highlights Asian range boundaries alongside London and New York killzones. Th

Indicator v5 SMC / ICT / price actionSessions & time
Updated 7 months ago · None stated GitHub repository of Apex Protocol Assistant

This overlay indicator researches multi-timeframe setup zones for NQ and ES futures on the price chart. It builds chart, five-minute through four-hour zones, including transformed IFVG and BB zones, scores them, and tracks liquidity pools and structure. During

Indicator v6 Support & resistanceSMC / ICT / price action Repaints
Updated 7 weeks ago · MPL-2.0 GitHub repository of Meridian - Futures Setups Research

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers