PINE LIBRARY

EKSSMT

207
Library "EKSSMT"
SSMT (Smart Money Tool) detection engine library. Handles normal and hidden SMT detection,
QCISD level creation/management, PSP (Price Sync Pattern) calculation, multi-condition alert logic,
status bar color computation, and all session/quarter math.
Extracted from qt-ultimate-enigma.pine to avoid TradingView compiler timeout.

init_qcisd_state()
  Creates and returns an initialized QCISDState with empty arrays.
  Returns: QCISDState with all arrays initialized

add_to_line_array(arr, value, limit)
  Adds a line to a managed array, deleting the oldest if over the limit.
  Parameters:
    arr (array<line>): The line array to manage
    value (line): The new line to add
    limit (int): Maximum array size

add_to_label_array(arr, value, limit)
  Adds a label to a managed array, deleting the oldest if over the limit.
  Parameters:
    arr (array<label>): The label array to manage
    value (label): The new label to add
    limit (int): Maximum array size

compute_sessions(t, tz, dayStartHour)
  Computes all session and quarter values for the current bar.
Calculates micro, 90m, daily, weekly, monthly, quarterly, and yearly session indices,
plus change flags for each.
  Parameters:
    t (int): The current bar time
    tz (string): Timezone string (e.g. "UTC-4")
    dayStartHour (int): Hour of day start in the given timezone (e.g. 18)
  Returns: SessionState with all computed session/quarter values

f_main_process(_tf_ok, _val_ses, op, cls, hi, lo, ti)
  Tracks H/L/close extremes per session period. Core price tracking for SSMT detection.
  Parameters:
    _tf_ok (bool): Whether the current timeframe is within the valid range
    _val_ses (int): The current session index value
    op (float): Open price (chart or correlated asset)
    cls (float): Close price
    hi (float): High price
    lo (float): Low price
    ti (int): Time value
  Returns: Tuple of 18 values: [hmaxt, lmint, hmax2, lmin2, hmax1, lmin1, hmax, lmin, hmaxt1, lmint1, clsmax, clsmax1, clsmaxt1, clsmin, clsmin1, clsmint1, clsmaxt, clsmint]

f_ssmt(cfg, qcisd_state, ah2, ah1, ah0, al2, al1, al0, bh2, bh1, bh0, bl2, bl1, bl0, _hmaxt, _lmint, _hmaxt1, _lmint1, _tfok, _val_ses, showon, _smt_clr, _smt_txt_clr, _tf_ok_V, lbl, name, pair, _inv, _time_limit, ssmt_pair, ssmt_pair2)
  Normal SMT detection with line/label drawing and QCISD level creation.
  Parameters:
    cfg (SSMTConfig): SSMTConfig settings
    qcisd_state (QCISDState): QCISDState arrays for QCISD level management
    ah2 (float): Chart asset high 2 periods ago
    ah1 (float): Chart asset high 1 period ago
    ah0 (float): Chart asset current high
    al2 (float): Chart asset low 2 periods ago
    al1 (float): Chart asset low 1 period ago
    al0 (float): Chart asset current low
    bh2 (float): Correlated asset high 2 periods ago
    bh1 (float): Correlated asset high 1 period ago
    bh0 (float): Correlated asset current high
    bl2 (float): Correlated asset low 2 periods ago
    bl1 (float): Correlated asset low 1 period ago
    bl0 (float): Correlated asset current low
    _hmaxt (int): Time of current high maximum
    _lmint (int): Time of current low minimum
    _hmaxt1 (int): Time of previous high maximum
    _lmint1 (int): Time of previous low minimum
    _tfok (bool): Whether timeframe is valid for this SSMT level
    _val_ses (int): Current session index
    showon (bool): Whether to show this SSMT level on chart
    _smt_clr (color): Color for SSMT lines
    _smt_txt_clr (color): Color for SSMT label text
    _tf_ok_V (bool): Whether timeframe is valid for visibility
    lbl (string): Label text string
    name (string): SSMT timeframe name ("90m", "Daily", "Weekly", etc.)
    pair (int): Pair number (2=secondary, 3=tertiary)
    _inv (bool): Whether this pair is inverse correlated
    _time_limit (int): Time limit for active status checking (dayStart or 0)
    ssmt_pair (string): Name string of secondary pair
    ssmt_pair2 (string): Name string of tertiary pair
  Returns: Tuple: [_bear1, _bear0, _bull1, _bull0, ret_smtbe, ret_smtbu, _is_act_beh, _is_act_bul]

f_hidden_ssmt(cfg, _clsmax, _clsmax1, _clsmin, _clsmin1, _clsmaxt, _clsmaxt1, _clsmint, _clsmint1, _cclsmax, _cclsmax1, _cclsmin, _cclsmin1, _tfok, showon, _smt_clr, _smt_txt_clr, _val_ses, _tf_ok_V, lbl, name, pair, _inv, _time_limit, ssmt_pair, ssmt_pair2)
  Hidden SMT detection with line/label drawing.
  Parameters:
    cfg (SSMTConfig): SSMTConfig settings
    _clsmax (float): Current close max
    _clsmax1 (float): Previous close max
    _clsmin (float): Current close min
    _clsmin1 (float): Previous close min
    _clsmaxt (int): Time of current close max
    _clsmaxt1 (int): Time of previous close max
    _clsmint (int): Time of current close min
    _clsmint1 (int): Time of previous close min
    _cclsmax (float): Correlated asset current close max
    _cclsmax1 (float): Correlated asset previous close max
    _cclsmin (float): Correlated asset current close min
    _cclsmin1 (float): Correlated asset previous close min
    _tfok (bool): Whether timeframe is valid
    showon (bool): Whether to show on chart
    _smt_clr (color): Color for hidden SSMT lines
    _smt_txt_clr (color): Color for hidden SSMT label text
    _val_ses (int): Current session index
    _tf_ok_V (bool): Whether timeframe is within visibility range
    lbl (string): Label text string
    name (string): SSMT timeframe name
    pair (int): Pair number (2=secondary, 3=tertiary)
    _inv (bool): Whether pair is inverse correlated
    _time_limit (int): Time limit for active status checking
    ssmt_pair (string): Name string of secondary pair
    ssmt_pair2 (string): Name string of tertiary pair
  Returns: Tuple: [_hbear0, _lbull0, ret_hsmtbe, ret_hsmtbu, _is_act_hbeh, _is_act_hbul]

run_ssmt(cfg, qcisd_state, _tf_ok, _tf_ok_V, _val_ses, name, _show_smt, _smt_clr, _hsmt_clr, _smt_txt_clr, _show_hsmt, X_SSMT, shortname, _time_limit, xo0, xc0, xh0, xl0, xt0, yo0, yc0, yh0, yl0, yt0, ssmt_pair, ssmt_pair2, arr_inv, triad_ok, showsmt2)
  Orchestrator that calls f_main_process + f_ssmt + f_hidden_ssmt for each timeframe.
This replaces f_allrun from the monolithic indicator.
  Parameters:
    cfg (SSMTConfig): SSMTConfig settings
    qcisd_state (QCISDState): QCISDState arrays
    _tf_ok (bool): Whether timeframe is within valid range
    _tf_ok_V (bool): Whether timeframe is within visibility range
    _val_ses (int): Current session index value
    name (string): SSMT timeframe name ("90m", "Daily", "Weekly", etc.)
    _show_smt (bool): Whether to show normal SSMT
    _smt_clr (color): Color for normal SSMT lines
    _hsmt_clr (color): Color for hidden SSMT lines
    _smt_txt_clr (color): Color for SSMT label text
    _show_hsmt (bool): Whether to show hidden SSMT
    X_SSMT (array<bool>): The bool array (size 14) for this timeframe's SSMT state
    shortname (string): Short name for labels (e.g. "90m", "D", "W")
    _time_limit (int): Time limit for active status (dayStart or 0)
    xo0 (float): Secondary asset open
    xc0 (float): Secondary asset close
    xh0 (float): Secondary asset high
    xl0 (float): Secondary asset low
    xt0 (int): Secondary asset time
    yo0 (float): Tertiary asset open
    yc0 (float): Tertiary asset close
    yh0 (float): Tertiary asset high
    yl0 (float): Tertiary asset low
    yt0 (int): Tertiary asset time
    ssmt_pair (string): Name of secondary pair
    ssmt_pair2 (string): Name of tertiary pair
    arr_inv (array<bool>): Array of inversion flags [inv_secondary, inv_tertiary]
    triad_ok (bool): Whether triad mode is active
    showsmt2 (bool): Whether to show SMT pair 2

run_alert(cfg, a_con1, a_con3, number, M_SSMT, W_SSMT, D_SSMT, Q_SSMT, Y_SSMT, N_SSMT, m_SSMT, newMo, newW, newD, newN, newm, newQ, newY)
  Multi-condition alert logic for SSMT signals.
  Parameters:
    cfg (SSMTConfig): SSMTConfig settings
    a_con1 (string): First alert condition string (e.g. "W Bull SSMT")
    a_con3 (string): Second alert condition string
    number (string): Alert number string ("1", "2", "3", "4")
    M_SSMT (array<bool>): Monthly SSMT state array (size 14)
    W_SSMT (array<bool>): Weekly SSMT state array
    D_SSMT (array<bool>): Daily SSMT state array
    Q_SSMT (array<bool>): Quarterly SSMT state array
    Y_SSMT (array<bool>): Yearly SSMT state array
    N_SSMT (array<bool>): 90m SSMT state array
    m_SSMT (array<bool>): Micro SSMT state array
    newMo (bool): Whether monthly session just changed
    newW (bool): Whether weekly session just changed
    newD (bool): Whether daily session just changed
    newN (bool): Whether 90m session just changed
    newm (bool): Whether micro session just changed
    newQ (bool): Whether quarterly session just changed
    newY (bool): Whether yearly session just changed

calc_psp_adaptive(_show, xc0, xo0, xt0, yc0, yo0, yt0, arr_inv, triad_ok, dyad_ok, showsmt1, showsmt2)
  PSP (Price Sync Pattern) adaptive bar-by-bar divergence calculation.
  Parameters:
    _show (bool): Whether PSP is enabled and visible
    xc0 (float): Secondary asset close
    xo0 (float): Secondary asset open
    xt0 (int): Secondary asset time
    yc0 (float): Tertiary asset close
    yo0 (float): Tertiary asset open
    yt0 (int): Tertiary asset time
    arr_inv (array<bool>): Inversion flags array [inv_secondary, inv_tertiary]
    triad_ok (bool): Whether triad mode is active
    dyad_ok (bool): Whether dyad mode is active
    showsmt1 (bool): Whether SMT pair 1 is shown
    showsmt2 (bool): Whether SMT pair 2 is shown
  Returns: Tuple: [bull_signal, bear_signal]

get_sb_color_norm(_arr, _c_bull, _c_bear, _c_sand, _c_neut)
  Computes the status bar color for a given SSMT timeframe array.
  Parameters:
    _arr (array<bool>): The SSMT bool array (size 14) for this timeframe
    _c_bull (color): Bullish color
    _c_bear (color): Bearish color
    _c_sand (color): Sandwich/conflict color
    _c_neut (color): Neutral color
  Returns: The computed color for the status bar cell

process_qcisd(qcisd_state, cfg)
  QCISD global processor and mitigation loop. Handles confirmation, invalidation,
retest detection, and cleanup of QCISD levels.
  Parameters:
    qcisd_state (QCISDState): QCISDState arrays to process
    cfg (SSMTConfig): SSMTConfig settings

SSMTConfig
  Configuration settings for SSMT detection, drawing, alerts, and QCISD engine.
  Fields:
    hidelines (series bool): Whether to hide SSMT divergence lines on chart
    hidelabels (series bool): Whether to hide SSMT divergence labels on chart
    normstyle (series string): Line style for normal SSMT lines (line.style_solid, etc.)
    hiddstyle (series string): Line style for hidden SSMT lines
    i_font (series string): Text size for SSMT labels ("tiny", "small", "normal", "large", "huge")
    alerttype (series string): Type of SSMT to show/alert ("All", "Normal", "Hidden")
    ssmt_history_limit (series int): Maximum number of SSMT lines/labels to keep
    show_qcisd (series bool): Whether QCISD engine is enabled
    bias_input (series string): Market bias for QCISD ("Bullish", "Bearish", "Neutral")
    qcisd_bull_clr (series color): Color for bullish QCISD levels
    qcisd_bear_clr (series color): Color for bearish QCISD levels
    qcisd_pend_clr (series color): Color for pending (threatened) QCISD levels
    qcisd_text_clr (series color): Color for QCISD label text
    qcisd_width (series int): Line width for QCISD levels
    qcisd_lbl_size (series string): Text size for QCISD labels (size.tiny, size.small, size.normal)
    qcisd_mono (series bool): Whether to use monospace font for QCISD labels
    qcisd_max_limit (series int): Maximum number of QCISD lines to draw
    qcisd_trigger (series string): HP-QCISD alert trigger mode ("All", "Confirmation", "Invalidation", "Retest", "Off")
    qcisd_norm_trigger (series string): Normal QCISD alert trigger mode

QCISDState
  Holds the global QCISD state arrays. Passed by reference so library functions can modify in place.
  Fields:
    g_q_lines (array<line>): Array of QCISD line drawings
    g_q_lbls (array<label>): Array of QCISD label drawings
    g_q_dirs (array<int>): Array of directions (1=bullish, -1=bearish)
    g_q_hp (array<bool>): Array of high-probability flags
    g_q_conf (array<bool>): Array of confirmation flags
    g_q_names (array<string>): Array of SSMT source names (e.g. "90m", "Daily")
    g_q_pairs (array<string>): Array of pair names

SessionState
  Holds all computed session and quarter values for the current bar.
  Fields:
    val_sesm (series int): Micro session index (0-63)
    val_ses (series int): 90m session index (0-15)
    val_sesD (series int): Daily session index (0-3)
    val_sesW (series int): Weekly session index (0-6)
    val_sesMo (series int): Monthly session index (0-4)
    val_sesQ (series int): Quarterly session index (0-3)
    val_sesY (series int): Yearly session index (0-3)
    newMo (series bool): Whether monthly session just changed
    newW (series bool): Whether weekly session just changed
    newD (series bool): Whether daily session just changed
    newN (series bool): Whether 90m session just changed
    newm (series bool): Whether micro session just changed
    newQ (series bool): Whether quarterly session just changed
    newY (series bool): Whether yearly session just changed
    dayStart (series int): Timestamp of the current day start

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.