PINE LIBRARY
Aktualisiert

SetupsLib

370
Library "SetupsLib"

f_get_mc_family_from_setup(setup_id)
  Parameters:
    setup_id (string)

f_setup_id_to_code(setup_id)
  Parameters:
    setup_id (string)

f_setup_id_to_mask(setup_id)
  Parameters:
    setup_id (string)

f_find_setup_spec(setup_db, setup_id)
  Parameters:
    setup_db (array<SetupSpec>)
    setup_id (string)

f_get_setup_horizon(setup_db, setup_id, fallback_horizon)
  Parameters:
    setup_db (array<SetupSpec>)
    setup_id (string)
    fallback_horizon (int)

f_register_event(engine_events, fire_condition, setup_id, setup_tooltip, setup_size_info)
  Parameters:
    engine_events (array<SetupEvent>)
    fire_condition (bool)
    setup_id (string)
    setup_tooltip (string)
    setup_size_info (string)

f_collect_debug(engine_events)
  Parameters:
    engine_events (array<SetupEvent>)

SetupSpec
  Fields:
    id (series string)
    name (series string)
    dir (series string)
    wr (series float)
    sharpe (series float)
    tp_pct (series float)
    sl_pct (series float)
    avg_bars (series int)
    tooltip (series string)

SetupSignal
  Fields:
    id (series string)
    tooltip (series string)
    use_pred_rounding (series bool)
    debug_enabled (series bool)
    size_info (series string)

SetupEvent
  Fields:
    id (series string)
    tooltip (series string)
    size_info (series string)
Versionshinweise
v2

Added:
f_check_showstoppers(spec, ctx)
  Parameters:
    spec (SetupSpec)
    ctx (SetupContext)

f_score_confidence(spec, ctx, impulse_strength)
  Parameters:
    spec (SetupSpec)
    ctx (SetupContext)
    impulse_strength (float)

f_register_event_v2(engine_events, fire_condition, spec, ctx, impulse_strength, size_info)
  Parameters:
    engine_events (array<SetupEvent>)
    fire_condition (bool)
    spec (SetupSpec)
    ctx (SetupContext)
    impulse_strength (float)
    size_info (string)

f_get_spec(setup_db, setup_id)
  Parameters:
    setup_db (array<SetupSpec>)
    setup_id (string)

f_build_setup_db()

SetupContext
  Fields:
    vec_osc (series float)
    mr_osc (series float)
    te_osc (series float)
    corr_osc (series float)
    ltf_corr (series float)
    pred_slope (series float)
    vec_p25 (series float)
    vec_p75 (series float)
    mr_p25 (series float)
    mr_p75 (series float)
    mr_p2 (series float)
    mr_p98 (series float)
    te_p25 (series float)
    te_p75 (series float)
    corr_p20 (series float)
    corr_p80 (series float)
    ltf_p20 (series float)
    ltf_p80 (series float)
    pred_p25 (series float)
    pred_p75 (series float)

Updated:
SetupEvent
  Fields:
    id (series string)
    tooltip (series string)
    size_info (series string)
    confidence (series float)
    showstopper_hits (series int)
Versionshinweise
v3

Added:
f_eval_showstoppers(mask, ctx)
  Evaluates showstoppers using generic slot-based oscillator context
  Parameters:
    mask (int): Bitmask of showstopper conditions to check (use SS_* constants)
    ctx (OscContext): OscContext containing oscillator values and percentiles
  Returns: bool True if any showstopper condition in the mask is triggered

f_seed_validation(next_setup_id, next_setup_direction, next_label, next_tooltip)
  Seeds a validation request with setup details
  Parameters:
    next_setup_id (string): Setup ID to validate
    next_setup_direction (string): Direction ("LONG" or "SHORT")
    next_label (label): Label reference for the setup
    next_tooltip (string): Tooltip text for the setup
  Returns: [setup_id, trigger_bar, entry_price, direction, label, tooltip, phase] Validation seed data

f_start_or_queue_validation(vs, next_setup_id, next_trigger_bar, next_entry_price, next_direction, next_label, next_tooltip, next_phase)
  Starts validation or queues it if validator is busy
  Parameters:
    vs (ValidationState): ValidationState object to update
    next_setup_id (string): Setup ID to validate
    next_trigger_bar (int): Bar index where setup fired
    next_entry_price (float): Entry price for the setup
    next_direction (string): Direction ("LONG" or "SHORT")
    next_label (label): Label reference
    next_tooltip (string): Tooltip text
    next_phase (int): Initial phase (usually 1)
  Returns: ValidationState Updated validation state

OscContext
  Fields:
    values (array<float>)
    p25 (array<float>)
    p75 (array<float>)
    p_lo (array<float>)
    p_hi (array<float>)

ValidationState
  Fields:
    validating_setup_id (series string)
    setup_trigger_bar (series int)
    setup_entry_price (series float)
    setup_direction (series string)
    current_mae_p10 (series float)
    current_mfe_p90 (series float)
    current_mae_alt (series float)
    current_mfe_alt (series float)
    selected_validation_direction (series string)
    validation_phase (series int)
    mae_viz_price (series float)
    mfe_viz_price (series float)
    validating_label (series label)
    validating_tooltip (series string)
    pending_setup_id (series string)
    pending_trigger_bar (series int)
    pending_entry_price (series float)
    pending_direction (series string)
    pending_label (series label)
    pending_tooltip (series string)
    pending_phase (series int)

Updated:
SetupSpec
  Fields:
    id (series string)
    name (series string)
    dir (series string)
    wr (series float)
    sharpe (series float)
    tp_pct (series float)
    sl_pct (series float)
    avg_bars (series int)
    tooltip (series string)
    timestop (series int)
    mc_family (series int)
    edge_ratio (series float)
    thesis_flags (series int)
    showstopper_mask (series int)
    impulse_penalty_scale (series float)
Versionshinweise
v4
Versionshinweise
v5
Versionshinweise
v6
Versionshinweise
v7

Added:
f_exit_logic(dir, tp1, pos_pnl, bars_held, pred_ma_now, pred_ma_3ago, pred_ma_1ago, trail_sl_in, max_pnl, low_price, high_price, close_price)
  Parameters:
    dir (string)
    tp1 (float)
    pos_pnl (float)
    bars_held (int)
    pred_ma_now (float)
    pred_ma_3ago (float)
    pred_ma_1ago (float)
    trail_sl_in (float)
    max_pnl (float)
    low_price (float)
    high_price (float)
    close_price (float)

Updated:
f_eval_showstoppers(mask, ctx)
  Parameters:
    mask (int)
    ctx (OscContext)

f_seed_validation(next_setup_id, next_setup_direction, next_label, next_tooltip)
  Parameters:
    next_setup_id (string)
    next_setup_direction (string)
    next_label (label)
    next_tooltip (string)

f_start_or_queue_validation(vs, next_setup_id, next_trigger_bar, next_entry_price, next_direction, next_label, next_tooltip, next_phase)
  Parameters:
    vs (ValidationState)
    next_setup_id (string)
    next_trigger_bar (int)
    next_entry_price (float)
    next_direction (string)
    next_label (label)
    next_tooltip (string)
    next_phase (int)
Versionshinweise
v8

Added:
f_create_level(price, bar_idx, sweep_dir, default_len, max_scan, col, width, dashed)
  Create a single tracked level line
  Parameters:
    price (float): Level price (na = skip)
    bar_idx (int): Bar index where created
    sweep_dir (int): +1=above, -1=below, 0=fixed (entry)
    default_len (int): Default line length in bars
    max_scan (int): Max bars to scan for late sweep (0=fixed)
    col (color): Line color
    width (int): Line width
    dashed (bool): True for dashed style
  Returns: LevelTracker

f_create_tpsl_levels(levels, dir, ep, tp1, tp2, sl, bar_idx, entry_len, default_len, max_scan, tp_col, sl_col, ep_col)
  Create entry + TP1 + TP2 + SL level trackers and push to array
  Parameters:
    levels (array<LevelTracker>): Global array of LevelTrackers
    dir (string): "LONG" or "SHORT"
    ep (float): Entry price
    tp1 (float): Take profit 1
    tp2 (float): Take profit 2
    sl (float): Stop loss
    bar_idx (int): Current bar_index
    entry_len (int): Entry line length (10)
    default_len (int): TP/SL default length (20)
    max_scan (int): Max sweep scan bars (300)
    tp_col (color): TP line color
    sl_col (color): SL line color
    ep_col (color): Entry line color
  Returns: [start_idx, count] Index range in the levels array

f_update_levels(levels, hi, lo, current_bar)
  Per-bar update: extend growing lines, detect sweeps, freeze expired
  Parameters:
    levels (array<LevelTracker>): Global array of LevelTrackers
    hi (float): Current bar high
    lo (float): Current bar low
    current_bar (int): Current bar_index

f_remove_levels(levels, start_idx, count)
  Delete lines for a position's levels (on exit)
  Parameters:
    levels (array<LevelTracker>): Global array
    start_idx (int): Start index of this position's levels
    count (int): Number of levels (typically 4)

f_freeze_levels(levels, start_idx, count)
  Freeze levels without deleting (keep visible on chart)
  Parameters:
    levels (array<LevelTracker>): Global array
    start_idx (int): Start index
    count (int): Number of levels

LevelTracker
  Fields:
    ln (series line)
    price (series float)
    start_bar (series int)
    sweep_dir (series int)
    default_len (series int)
    max_scan (series int)
    done (series bool)

Updated:
f_eval_showstoppers(mask, ctx)
  Evaluates showstoppers using generic slot-based oscillator context
  Parameters:
    mask (int): Bitmask of showstopper conditions to check (use SS_* constants)
    ctx (OscContext): OscContext containing oscillator values and percentiles
  Returns: bool True if any showstopper condition in the mask is triggered

f_seed_validation(next_setup_id, next_setup_direction, next_label, next_tooltip)
  Seeds a validation request with setup details
  Parameters:
    next_setup_id (string): Setup ID to validate
    next_setup_direction (string): Direction ("LONG" or "SHORT")
    next_label (label): Label reference for the setup
    next_tooltip (string): Tooltip text for the setup
  Returns: [setup_id, trigger_bar, entry_price, direction, label, tooltip, phase] Validation seed data

f_start_or_queue_validation(vs, next_setup_id, next_trigger_bar, next_entry_price, next_direction, next_label, next_tooltip, next_phase)
  Starts validation or queues it if validator is busy
  Parameters:
    vs (ValidationState): ValidationState object to update
    next_setup_id (string): Setup ID to validate
    next_trigger_bar (int): Bar index where setup fired
    next_entry_price (float): Entry price for the setup
    next_direction (string): Direction ("LONG" or "SHORT")
    next_label (label): Label reference
    next_tooltip (string): Tooltip text
    next_phase (int): Initial phase (usually 1)
  Returns: ValidationState Updated validation state

Removed:
f_exit_logic(dir, tp1, pos_pnl, bars_held, pred_ma_now, pred_ma_3ago, pred_ma_1ago, trail_sl_in, max_pnl, low_price, high_price, close_price)
Versionshinweise
v9

Added:
f_calc_tpsl(dir, ep, tp_pct, sl_pct, z2_up, z2_dn, z3_up, z3_dn, use_zones)
  Parameters:
    dir (string)
    ep (float)
    tp_pct (float)
    sl_pct (float)
    z2_up (float)
    z2_dn (float)
    z3_up (float)
    z3_dn (float)
    use_zones (bool)

f_exit_logic(dir, tp1, pos_pnl, bars_held, pred_ma_now, pred_ma_3ago, pred_ma_1ago, trail_sl_in, max_pnl, low_price, high_price, close_price)
  Parameters:
    dir (string)
    tp1 (float)
    pos_pnl (float)
    bars_held (int)
    pred_ma_now (float)
    pred_ma_3ago (float)
    pred_ma_1ago (float)
    trail_sl_in (float)
    max_pnl (float)
    low_price (float)
    high_price (float)
    close_price (float)

Updated:
f_create_level(price, bar_idx, sweep_dir, default_len, max_scan, col, width, dashed)
  Parameters:
    price (float)
    bar_idx (int)
    sweep_dir (int)
    default_len (int)
    max_scan (int)
    col (color)
    width (int)
    dashed (bool)

f_create_tpsl_levels(levels, dir, ep, tp1, tp2, sl, bar_idx, entry_len, default_len, max_scan, tp_col, sl_col, ep_col)
  Parameters:
    levels (array<LevelTracker>)
    dir (string)
    ep (float)
    tp1 (float)
    tp2 (float)
    sl (float)
    bar_idx (int)
    entry_len (int)
    default_len (int)
    max_scan (int)
    tp_col (color)
    sl_col (color)
    ep_col (color)

f_update_levels(levels, hi, lo, current_bar)
  Parameters:
    levels (array<LevelTracker>)
    hi (float)
    lo (float)
    current_bar (int)

f_remove_levels(levels, start_idx, count)
  Parameters:
    levels (array<LevelTracker>)
    start_idx (int)
    count (int)

f_freeze_levels(levels, start_idx, count)
  Parameters:
    levels (array<LevelTracker>)
    start_idx (int)
    count (int)

f_eval_showstoppers(mask, ctx)
  Parameters:
    mask (int)
    ctx (OscContext)

f_register_event_v2(events, condition, spec, ctx, impulse_strength, size_info)
  Parameters:
    events (array<SetupEvent>)
    condition (bool)
    spec (SetupSpec)
    ctx (OscContext)
    impulse_strength (float)
    size_info (string)

f_seed_validation(next_setup_id, next_setup_direction, next_label, next_tooltip)
  Parameters:
    next_setup_id (string)
    next_setup_direction (string)
    next_label (label)
    next_tooltip (string)

f_start_or_queue_validation(vs, next_setup_id, next_trigger_bar, next_entry_price, next_direction, next_label, next_tooltip, next_phase)
  Parameters:
    vs (ValidationState)
    next_setup_id (string)
    next_trigger_bar (int)
    next_entry_price (float)
    next_direction (string)
    next_label (label)
    next_tooltip (string)
    next_phase (int)
Versionshinweise
v10

Added:
f_register_event_auto(engine_events, setup_db, fire_condition, setup_id, setup_size_info)
  Parameters:
    engine_events (array<SetupEvent>)
    setup_db (array<SetupSpec>)
    fire_condition (bool)
    setup_id (string)
    setup_size_info (string)
Versionshinweise
v11

Added:
f_build_family_table()

f_family_get(fam, id)
  Parameters:
    fam (array<Family>)
    id (int)

f_family_match(fam_a, fam_b, soft)
  Parameters:
    fam_a (int)
    fam_b (int)
    soft (bool)

f_classify_market_state(fam, position, velocity, pressure, coupling, mrstate)
  Parameters:
    fam (array<Family>)
    position (float)
    velocity (float)
    pressure (float)
    coupling (float)
    mrstate (float)

f_build_setup_db_v19(fam)
  Parameters:
    fam (array<Family>)

f_get_edge_ratio_v19(spec)
  Parameters:
    spec (SetupSpec)

f_get_thesis_v19(spec)
  Parameters:
    spec (SetupSpec)

f_get_showstopper_mask_v19(spec)
  Parameters:
    spec (SetupSpec)

Family
  Fields:
    id (series int)
    label (series string)
    name (series string)
    direction (series int)
    directional (series bool)
    col (series color)

Updated:
SetupSpec
  Fields:
    id (series string)
    name (series string)
    dir (series string)
    family (Family)
    wr (series float)
    sharpe (series float)
    tp_pct (series float)
    sl_pct (series float)
    avg_bars (series int)
    tooltip (series string)
    timestop (series int)
    edge_ratio (series float)
    thesis (series string)
    thesis_flags (series int)
    showstopper_mask (series int)
    impulse_penalty_scale (series float)
    code (series int)
    mask (series int)
Versionshinweise
v12
Versionshinweise
v13
Versionshinweise
v14
Versionshinweise
v15
Versionshinweise
v16

Removed:
f_collect_debug(engine_events)

f_build_setup_db_v19(fam)

f_get_edge_ratio_v19(spec)

f_get_thesis_v19(spec)

f_get_showstopper_mask_v19(spec)
Versionshinweise
v17

Removed:
f_get_mc_family_from_setup(setup_id)

f_setup_id_to_code(setup_id)

f_setup_id_to_mask(setup_id)
Versionshinweise
v18

Added:
f_evaluate_exit(dir, pnl, max_pnl, bars_held, hi, lo, tp1, trail_sl_in, pred_ma_now, pred_rising_now, pred_rising_1ago)
  Parameters:
    dir (string)
    pnl (float)
    max_pnl (float)
    bars_held (int)
    hi (float)
    lo (float)
    tp1 (float)
    trail_sl_in (float)
    pred_ma_now (float)
    pred_rising_now (bool)
    pred_rising_1ago (bool)

f_simulate_bt_position(dir, ep, tp_pct, hold_limit, arr_close, arr_predma, offset, arr_size)
  Parameters:
    dir (string)
    ep (float)
    tp_pct (float)
    hold_limit (int)
    arr_close (array<float>)
    arr_predma (array<float>)
    offset (int)
    arr_size (int)
Versionshinweise
v19

Updated:
f_create_tpsl_levels(levels, dir, tp1, tp2, sl, bar_idx, default_len, max_scan, tp_col, sl_col)
  Parameters:
    levels (array<LevelTracker>)
    dir (string)
    tp1 (float)
    tp2 (float)
    sl (float)
    bar_idx (int)
    default_len (int)
    max_scan (int)
    tp_col (color)
    sl_col (color)

Removed:
f_remove_levels(levels, start_idx, count)
Versionshinweise
v20

Added:
f_update_exit_label(lbl, setup_id, dir, exit_code, pnl)
  Parameters:
    lbl (label)
    setup_id (string)
    dir (string)
    exit_code (int)
    pnl (float)
Versionshinweise
v21

Added:
f_get_exit_info(exit_code)
  Parameters:
    exit_code (int)

Updated:
f_simulate_bt_position(dir, ep, tp_pct, hold_limit, arr_close, arr_high, arr_low, arr_predma, offset, arr_size)
  Parameters:
    dir (string)
    ep (float)
    tp_pct (float)
    hold_limit (int)
    arr_close (array<float>)
    arr_high (array<float>)
    arr_low (array<float>)
    arr_predma (array<float>)
    offset (int)
    arr_size (int)
Versionshinweise
v22

Added:
f_get_mc_family(f1_vec, f2_corr, f3_innov, f4_te, f5_orth, f6_phi)
  Market state classifier using 6 normalized features (wrapper for backward compatibility)
  Parameters:
    f1_vec (float): Basket vector z-score
    f2_corr (float): Basket correlation z-score
    f3_innov (float): Innovation width z-score
    f4_te (float): Transfer entropy z-score
    f5_orth (float): Orthogonal component z-score
    f6_phi (float): Phi divergence z-score
  Returns: Family ID: 0=Continuation, 1=Mean-Revert, 2=Transition, 3=Velocity, 4=Uncertain
Versionshinweise
v23

Added:
f_config_to_spec(id, name, dir, tp_pct, sl_pct, hold_bars, wr, sharpe, edgeratio, thesis, showstopper_mask, code, mask)
  f_config_to_spec
description Converts a SetupConfig (from setupsDBGem) to SetupSpec (SetupsLib native type)
  Parameters:
    id (string)
    name (string)
    dir (string)
    tp_pct (float)
    sl_pct (float)
    hold_bars (int)
    wr (float)
    sharpe (float)
    edgeratio (float)
    thesis (string)
    showstopper_mask (int)
    code (int)
    mask (int)
  Returns: SetupSpec compatible with SetupsLib functions (f_register_event_v2, f_check_showstoppers, etc.)

Removed:
f_register_event(engine_events, fire_condition, setup_id, setup_tooltip, setup_size_info)

f_register_event_auto(engine_events, setup_db, fire_condition, setup_id, setup_size_info)
Versionshinweise
v24

Added:
f_build_osc_context(vec_osc, mr_osc, te_osc, corr_osc, ltf_corr, pred_slope, vec_p25, vec_p75, mr_p25, mr_p75, mr_p2, mr_p98, te_p25, te_p75, corr_p20, corr_p80, ltf_p20, ltf_p80, pred_p25, pred_p75)
  f_build_osc_context
description Builds OscContext from oscillator values and percentile boundaries
  Parameters:
    vec_osc (float): Vector oscillator value
    mr_osc (float): Mean reversion oscillator value
    te_osc (float): Transfer entropy oscillator value
    corr_osc (float): Correlation oscillator value
    ltf_corr (float): Lower timeframe correlation value
    pred_slope (float): Predictive slope value
    vec_p25 (float): Vector 25th percentile
    vec_p75 (float): Vector 75th percentile
    mr_p25 (float): MR 25th percentile
    mr_p75 (float): MR 75th percentile
    mr_p2 (float): MR 2nd percentile (lower extreme)
    mr_p98 (float): MR 98th percentile (upper extreme)
    te_p25 (float): TE 25th percentile
    te_p75 (float): TE 75th percentile
    corr_p20 (float): Correlation 20th percentile
    corr_p80 (float): Correlation 80th percentile
    ltf_p20 (float): LTF correlation 20th percentile
    ltf_p80 (float): LTF correlation 80th percentile
    pred_p25 (float): Predictive slope 25th percentile
    pred_p75 (float): Predictive slope 75th percentile
  Returns: OscContext with 6-slot arrays (vec, mr, te, corr, ltf_corr, pred_slope)

f_exit_label_text(exit_code, pnl)
  f_exit_label_text
description Generate exit label text based on exit code
  Parameters:
    exit_code (int): Exit type: 0=HardSL, 1=TrailSL, 2=PredFlip, 3=Breakeven, 4=TP1
    pnl (float): Position PnL percentage
  Returns: Label text string

f_exit_label_color(exit_code, pnl)
  f_exit_label_color
description Generate exit label color based on exit code and PnL
  Parameters:
    exit_code (int): Exit type: 0=HardSL, 1=TrailSL, 2=PredFlip, 3=Breakeven, 4=TP1
    pnl (float): Position PnL percentage
  Returns: Label color

Updated:
f_config_to_spec(id, name, dir, tp_pct, sl_pct, hold_bars, wr, sharpe, edgeratio, thesis, showstopper_mask, code, mask, tooltip)
  f_config_to_spec
description Converts a SetupConfig (from setupsDBGem) to SetupSpec (SetupsLib native type)
  Parameters:
    id (string)
    name (string)
    dir (string)
    tp_pct (float)
    sl_pct (float)
    hold_bars (int)
    wr (float)
    sharpe (float)
    edgeratio (float)
    thesis (string)
    showstopper_mask (int)
    code (int)
    mask (int)
    tooltip (string)
  Returns: SetupSpec compatible with SetupsLib functions (f_register_event_v2, f_check_showstoppers, etc.)
Versionshinweise
v25

Updated:
f_evaluate_exit(dir, pnl, max_pnl, bars_held, hi, lo, tp1, trail_sl_in, trail_sl_target, signal_reverse_check)
  Parameters:
    dir (string)
    pnl (float)
    max_pnl (float)
    bars_held (int)
    hi (float)
    lo (float)
    tp1 (float)
    trail_sl_in (float)
    trail_sl_target (float)
    signal_reverse_check (bool)

f_config_to_spec(id, name, dir, tp_pct, sl_pct, hold_bars, wr, sharpe, edgeratio, thesis, showstopper_mask, code, mask, tooltip, thesisflags, impulse_penalty_scale)
  f_config_to_spec
description Converts a SetupConfig (from setupsDBGem) to SetupSpec (SetupsLib native type)
  Parameters:
    id (string)
    name (string)
    dir (string)
    tp_pct (float)
    sl_pct (float)
    hold_bars (int)
    wr (float)
    sharpe (float)
    edgeratio (float)
    thesis (string)
    showstopper_mask (int)
    code (int)
    mask (int)
    tooltip (string)
    thesisflags (int)
    impulse_penalty_scale (float)
  Returns: SetupSpec compatible with SetupsLib functions (f_register_event_v2, f_eval_showstoppers, etc.)

Removed:
f_check_showstoppers(spec, ctx)

f_score_confidence(spec, ctx, impulse_strength)

SetupContext
Versionshinweise
v26

Added:
AggResult
  Fields:
    total (series int)
    wins (series int)
    avg_pnl (series float)
    sharpe (series float)
    mfe_mae (series float)
    mfe_raw (series float)
    mae_raw (series float)

ActivePosition
  Fields:
    setup_id (series string)
    dir (series string)
    entry_bar (series int)
    entry_price (series float)
    tp1 (series float)
    tp2 (series float)
    sl (series float)
    mc_p10 (series float)
    mc_p50 (series float)
    rrr (series float)
    is_active (series bool)
    setup_label (series label)
    tooltip (series string)
    levels_idx (series int)
    levels_cnt (series int)
    exit_code (series int)

HistoricalSetup
  Fields:
    bar_idx (series int)
    setup_id (series string)
    direction (series string)
    entry_price (series float)
    tp_pct (series float)
    sl_pct (series float)
    max_hold (series int)
    f1_snap (series float)
    f2_snap (series float)
    f3_snap (series float)
    f4_snap (series float)
    f5_snap (series float)
    f6_snap (series float)
    f7_snap (series float)
    packed_snap (series int)
    family_snap (Family)
    hist_avail (series int)
    coupling_regime_snap (series int)
    basket_fit_norm_snap (series float)
    rho_snap (series float)
    setup_code (series int)
    entry_ctx (series float)
    mc_oracle_dir (series string)
    actual_pnl (series float)
    actual_mae (series float)
    actual_mfe (series float)
    exit_reason (series string)
    mc_pct_agree (series float)
    mc_dir_pct (series float)
    mc_confirmed (series bool)
    mc_confidence (series float)
    knn_cands (series int)
    setup_label (series label)
    label_y (series float)
    orig_tooltip (series string)
    label_color_final (series color)
    label_text_final (series string)
    label_tooltip_final (series string)
Versionshinweise
v27

Added:
f_tp_new(price, size_fraction)
  Parameters:
    price (float)
    size_fraction (float)

f_sl_new(price)
  Parameters:
    price (float)

f_sl_trailing(initial_price, trail_distance, activate_at)
  Parameters:
    initial_price (float)
    trail_distance (float)
    activate_at (float)

f_spec_new(id, name, version, kind, family_id, code_id, default_rr, max_bars_in_state)
  Parameters:
    id (int)
    name (string)
    version (int)
    kind (series SetupKind)
    family_id (int)
    code_id (int)
    default_rr (float)
    max_bars_in_state (int)

f_signal_empty()

f_signal_new(setup_id, direction, entry_price, sl_price, confidence)
  Parameters:
    setup_id (int)
    direction (series TradeDirection enum from cybermediaboy/LearningLib/1)
    entry_price (float)
    sl_price (float)
    confidence (float)

method add_tp(sig, price, fraction)
  Add a TP tier to signal
  Namespace types: SetupSignal
  Parameters:
    sig (SetupSignal)
    price (float)
    fraction (float)

method current_r(p, price)
  Compute current R-multiple given live price
  Namespace types: ActivePosition
  Parameters:
    p (ActivePosition)
    price (float)

method update_trail(p, h, l)
  Update trailing stop given current high/low
  Namespace types: ActivePosition
  Parameters:
    p (ActivePosition)
    h (float)
    l (float)

f_registry_new()

method register(r, spec)
  Namespace types: SetupRegistry
  Parameters:
    r (SetupRegistry)
    spec (SetupSpec)

method find(r, setup_id)
  Namespace types: SetupRegistry
  Parameters:
    r (SetupRegistry)
    setup_id (int)

method enabled(r, setup_id)
  Namespace types: SetupRegistry
  Parameters:
    r (SetupRegistry)
    setup_id (int)

f_aggregator_new(max_active, max_events)
  Parameters:
    max_active (int)
    max_events (int)

method drain_events(agg)
  Drain events into caller-supplied array (mutates and clears).
Caller iterates, dispatches to LogLib / VisLib, then ignores.
  Namespace types: SetupAggregator
  Parameters:
    agg (SetupAggregator)

method process_signal(agg, sig, reg)
  Process a SetupSignal — create new position if direction != FLAT.
Returns mutated aggregator. Capacity-checked: if at max_active,
emits SIGNAL_REJECTED and skips.
  Namespace types: SetupAggregator
  Parameters:
    agg (SetupAggregator)
    sig (SetupSignal)
    reg (SetupRegistry)

method tick(agg, h, l, c, reg)
  Per-bar tick. Updates trailing stops, evaluates TPSL hits,
transitions states, emits events, prunes closed positions.
Caller invokes once per bar after process_signal calls.
h, l, c = current bar high, low, close.
  Namespace types: SetupAggregator
  Parameters:
    agg (SetupAggregator)
    h (float)
    l (float)
    c (float)
    reg (SetupRegistry)

method close_all(agg, price, reason)
  Force-close all positions (e.g. session end). Caller-supplied price.
  Namespace types: SetupAggregator
  Parameters:
    agg (SetupAggregator)
    price (float)
    reason (series ExitReason)

f_compute_sl(dir, entry, mode, metric, param)
  Compute SL price given mode + parameters.
ATR_MULT: caller passes atr_value as `metric`; mult as `param`.
FIXED_PCT: param = pct (e.g. 0.02 for 2%).
STRUCTURE_BASED: caller passes anchor price as `metric`; param ignored.
DYNAMIC: caller passes absolute price as `metric`; param ignored.
FIXED_RR: not applicable for SL (use FIXED_PCT or ATR_MULT).
  Parameters:
    dir (series TradeDirection enum from cybermediaboy/LearningLib/1)
    entry (float)
    mode (series TPSLMode)
    metric (float)
    param (float)

f_compute_tp(dir, entry, sl_price, mode, metric, param)
  Compute TP price given mode + SL distance for RR mode.
  Parameters:
    dir (series TradeDirection enum from cybermediaboy/LearningLib/1)
    entry (float)
    sl_price (float)
    mode (series TPSLMode)
    metric (float)
    param (float)

f_lifecycle_str(s)
  Parameters:
    s (series LifecycleState)

f_exit_str(r)
  Parameters:
    r (series ExitReason)

f_kind_str(k)
  Parameters:
    k (series SetupKind)

f_event_str(k)
  Parameters:
    k (series EventKind)

f_tpsl_mode_str(m)
  Parameters:
    m (series TPSLMode)

TPLevel
  TPLevel — one take-profit tier
  Fields:
    price (series float): absolute target price
    size_fraction (series float): portion of position to close at this level [0,1]
    hit (series bool): hit flag (set by aggregator)
    hit_bar (series int): bar index when hit (-1 if not hit)

SLLevel
  SLLevel — stop-loss with optional trailing
  Fields:
    price (series float): current stop price
    initial_price (series float): original placement (for analytics)
    is_trailing (series bool): trail flag
    trail_distance (series float): distance to maintain when trailing (price units)
    trail_activate_at (series float): price at which trailing activates (na = immediate)
    trail_high_water (series float): highest favorable excursion (long: highest high; short: lowest low)
    hit (series bool): hit flag
    hit_bar (series int): bar index when hit

Event
  Event — one record drained by caller
  Fields:
    kind (series EventKind): EventKind
    bar_index (series int): emit bar
    setup_id (series int): attached setup
    position_id (series int): attached position (-1 if none)
    price (series float): relevant price (entry/exit/level/...)
    meta_int (series int): free integer
    meta_float (series float): free float
    msg (series string): short string label

SetupRegistry
  SetupRegistry — bounded collection of SetupSpec
  Fields:
    specs (array<SetupSpec>)

Versionshinweise
v28

Updated:
f_signal_new(setup_id, direction, entry_price, sl_price, confidence)
  Parameters:
    setup_id (int)
    direction (series TradeDirection enum from cybermediaboy/LearningLib/3)
    entry_price (float)
    sl_price (float)
    confidence (float)

f_compute_sl(dir, entry, mode, metric, param)
  Compute SL price given mode + parameters.
ATR_MULT: caller passes atr_value as `metric`; mult as `param`.
FIXED_PCT: param = pct (e.g. 0.02 for 2%).
STRUCTURE_BASED: caller passes anchor price as `metric`; param ignored.
DYNAMIC: caller passes absolute price as `metric`; param ignored.
FIXED_RR: not applicable for SL (use FIXED_PCT or ATR_MULT).
  Parameters:
    dir (series TradeDirection enum from cybermediaboy/LearningLib/3)
    entry (float)
    mode (series TPSLMode)
    metric (float)
    param (float)

f_compute_tp(dir, entry, sl_price, mode, metric, param)
  Compute TP price given mode + SL distance for RR mode.
  Parameters:
    dir (series TradeDirection enum from cybermediaboy/LearningLib/3)
    entry (float)
    sl_price (float)
    mode (series TPSLMode)
    metric (float)
    param (float)

SetupSignal
  SetupSignal — atomic signal record produced by indicator
  Fields:
    setup_id (series int): which setup emitted this
    bar_index (series int): emission bar
    direction (series TradeDirection enum from cybermediaboy/LearningLib/3): LONG / SHORT / FLAT (FLAT = exit-only)
    entry_price (series float): intended entry
    tp_prices (array<float>): array of TP prices (parallel with tp_fractions)
    tp_fractions (array<float>): sizes
    sl_price (series float): SL price (initial or trailing anchor)
    sl_trailing (series bool): trail flag
    sl_trail_dist (series float): trail distance
    confidence (series float): [0,1]
    features (array<float>): feature vector (for ML logging)
    meta (series int): free-form integer (setup-specific encoding)
    valid (series bool): set true to indicate live signal; false = no-op heartbeat

ActivePosition
  ActivePosition — managed lifecycle of one trade
  Fields:
    id (series int): unique within aggregator
    setup_id (series int): owning setup
    state (series LifecycleState): LifecycleState
    direction (series TradeDirection enum from cybermediaboy/LearningLib/3): LONG / SHORT
    entry_price (series float): fill price
    entry_bar (series int): fill bar
    signal_bar (series int): bar of original signal
    size (series float): position size (lots, contracts, units — caller convention)
    tp_levels (array<TPLevel>): array<TPLevel>
    sl_level (SLLevel): SLLevel
    bars_in_state (series int): count since last state transition
    exit_reason (series ExitReason): populated on close
    exit_price (series float): populated on close
    exit_bar (series int): populated on close
    realized_r (series float): R-multiple realized (positive = win)
    meta_a (series int): / meta_b carried from SetupSpec for analytics
    meta_b (series int)
Versionshinweise
v29
Versionshinweise
v30

Added:
f_compose_setup_value(spec, readings)
  Compose setup value from oscillator readings
  Parameters:
    spec (SetupSpec): SetupSpec with composition_kind
    readings (array<OscReading> type from cybermediaboy/OscLib/2): array<OscReading> oscillator snapshots
  Returns: Composite value (na when composition_kind=NONE)

f_validate_setup_spec(spec)
  Validate SetupSpec length contracts
  Parameters:
    spec (SetupSpec): SetupSpec to validate
  Returns: true if valid, false otherwise

f_validate_setup_signal(signal, spec)
  Validate SetupSignal length contracts
  Parameters:
    signal (SetupSignal): SetupSignal to validate
    spec (SetupSpec): SetupSpec for contract reference
  Returns: true if valid, false otherwise

Updated:
f_spec_new(id, name, version, kind, family_id, code_id, default_rr, max_bars_in_state, osc_specs, osc_periods, osc_zscore_lens, osc_weights, composition_kind)
  Create SetupSpec with oscillator metadata
  Parameters:
    id (int): Setup ID
    name (string): Setup name
    version (int): Setup version
    kind (series SetupKind): SetupKind
    family_id (int): Family ID
    code_id (int): Code ID
    default_rr (float): Default R:R ratio
    max_bars_in_state (int): Max bars before timeout
    osc_specs (array<OscSpec> type from cybermediaboy/OscLib/2): Oscillator specs (empty array for legacy /29 shape)
    osc_periods (array<int>): Oscillator periods (parallel to osc_specs)
    osc_zscore_lens (array<int>): Z-score windows (parallel to osc_specs)
    osc_weights (array<float>): Oscillator weights (length 0 or matches osc_specs)
    composition_kind (string): Composition kind from OSC_COMP_*
  Returns: SetupSpec

f_signal_empty()
  Create empty SetupSignal
  Returns: Empty SetupSignal

TPLevel
  TP level configuration
  Fields:
    price (series float): Target price
    fraction (series float): Position fraction to close (0.0-1.0)
    hit (series bool): Whether level was hit
    hit_bar (series int): Bar index when hit

SLLevel
  SL level configuration
  Fields:
    price (series float): Current SL price
    initial_price (series float): Original SL price
    is_trailing (series bool): Whether SL trails
    trail_distance (series float): Trailing distance
    trail_activate_at (series float): Price level to activate trailing
    trail_high_water (series float): Highest favorable price seen (for trailing logic)
    hit (series bool): Whether SL was hit
    hit_bar (series int): Bar index when hit

SetupSpec
  SetupSpec — descriptor / metadata for a setup
  Fields:
    id (series int): integer dispatch id (unique per indicator)
    name (series string): human-readable
    version (series int): monotonic versioning
    kind (series SetupKind): SetupKind classification
    family_id (series int): meta_a — family/category (used by kNN tournaments)
    code_id (series int): meta_b — specific code within family
    default_rr (series float): default reward:risk ratio
    default_tp_mode (series TPSLMode): TPSLMode for TP defaults
    default_sl_mode (series TPSLMode): TPSLMode for SL defaults
    max_bars_in_state (series int): cap for TIMED_OUT detection
    enabled (series bool): master enable flag
    osc_specs (array<OscSpec> type from cybermediaboy/OscLib/2): array<OscSpec> oscillator descriptors (length 0..N)
    osc_periods (array<int>): array<int> periods (parallel, introspection-only, series int)
    osc_zscore_lens (array<int>): array<int> z-score windows (parallel, introspection-only)
    osc_weights (array<float>): array<float> weights (length 0 or matches osc_specs)
    composition_kind (series string): string from OSC_COMP_* constants

SetupSignal
  SetupSignal — atomic signal record produced by indicator
  Fields:
    setup_id (series int): which setup emitted this
    bar_index (series int): emission bar
    direction (series TradeDirection): LONG / SHORT / FLAT (FLAT = exit-only)
    entry_price (series float): intended entry
    tp_prices (array<float>): array of TP prices (parallel with tp_fractions)
    tp_fractions (array<float>): sizes
    sl_price (series float): SL price (initial or trailing anchor)
    sl_trailing (series bool): trail flag
    sl_trail_dist (series float): trail distance
    confidence (series float): [0,1]
    features (array<float>): feature vector (for ML logging)
    meta (series int): free-form integer (setup-specific encoding)
    valid (series bool): set true to indicate live signal; false = no-op heartbeat
    osc_readings (array<OscReading> type from cybermediaboy/OscLib/2): array<OscReading> oscillator snapshots (parallel to spec.osc_specs)
    composite_value (series float): float composite oscillator value (na when composition_kind=NONE)
    feature_names (array<string>): array<string> feature names (parallel to features[])

Removed:
f_tp_new(price, size_fraction)

f_sl_new(price)

f_sl_trailing(initial_price, trail_distance, activate_at)

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.