Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=6
- indicator("Fractal Model Pro - TTrades (modular, v6)", overlay=true, max_labels_count=500, max_lines_count=500, max_boxes_count=200)
- // ======================================================
- // =============== FRAMEWORK & INPUTS MODULE ============
- // ======================================================
- enable_module_cisd = input.bool(true, "Enable CISD Module")
- enable_module_smt = input.bool(true, "Enable SMT Module")
- enable_module_structure = input.bool(true, "Enable Market Structure (CHoCH/BOS)")
- enable_module_proj = input.bool(true, "Enable Projections")
- enable_module_htf = input.bool(true, "Enable HTF Candles")
- enable_module_history = input.bool(true, "Enable History (30 setups)")
- enable_info_panel = input.bool(true, "Show Info Panel")
- use_time_filter = input.bool(true, "Use Time Filters (Hybrid)")
- tf1_on = input.bool(true, "Enable Filter 1")
- tf1_session = input.session("0000-2359", "Filter 1 Session (hhmm-hhmm)")
- tf2_on = input.bool(false, "Enable Filter 2")
- tf2_session = input.session("0000-2359", "Filter 2 Session (hhmm-hhmm)")
- tf3_on = input.bool(false, "Enable Filter 3")
- tf3_session = input.session("0000-2359", "Filter 3 Session (hhmm-hhmm)")
- ndm_auto_bias = input.bool(true, "Automatic NDM Bias (Auto)")
- bias_manual = input.string("Auto", "Manual Bias Override", options=["Auto", "Bullish", "Bearish"])
- use_next_day_model = input.bool(true, "Use Next-Day Model (NDM) rules for bias")
- smt_master_toggle = input.bool(true, "Master SMT Toggle")
- smt_require_for_cisd = input.bool(false, "Require SMT to confirm CISD (optional)")
- smt1_use = input.bool(true, "Use SMT Pair 1")
- smt1_symA = input.symbol("TVC:DXY", "SMT Pair 1 - Symbol A")
- smt1_symB = input.symbol("FX:EURUSD", "SMT Pair 1 - Symbol B")
- smt1_inverse = input.bool(false, "Invert Pair 1?")
- smt_pivot_len = input.int(3, "SMT Pivot Lookback (bars)", minval=1)
- ms_pivot_len = input.int(3, "Structure Pivot Length (fractal)", minval=1)
- ms_min_range = input.float(0.0, "Min range (percent) to count as structure move", step=0.1)
- ms_detect_choch = input.bool(true, "Detect CHoCH (Change of Character)")
- ms_detect_bos = input.bool(true, "Detect BOS (Break of Structure)")
- c2_body_ratio_threshold = input.float(0.5, "C2 Body Ratio Threshold (0-1)", step=0.05)
- c2_wick_body_ratio = input.float(1.5, "C2 Wick / Body Ratio", step=0.1)
- c2_max_bars_to_c3 = input.int(20, "Max bars to wait for C3 (XC2 timeout)")
- c3_wick_not_through_c2_eq = input.bool(true, "C3 wick must not go through C2 EQ")
- c4_max_bars_to_wait = input.int(200, "Max bars to wait for C4 after CISD (XC4 timeout)", minval=1)
- proj_master_toggle = input.bool(true, "Enable Projections")
- proj_mode = input.string("Both", "Projection Mode", options=["Model", "EQ/Fib", "Both"])
- proj_show_plus1 = input.bool(true, "+1")
- proj_show_0 = input.bool(true, "0 (EQ)")
- proj_show_minus1 = input.bool(true, "-1")
- proj_show_minus2 = input.bool(true, "-2")
- proj_show_minus25 = input.bool(true, "-2.5")
- proj_show_minus4 = input.bool(true, "-4")
- proj_show_minus45 = input.bool(true, "-4.5")
- proj_extend_right = input.bool(true, "Extend Projections Right")
- proj_anchor_body_or_wick = input.string("Body", "Projection Anchor", options=["Body", "Wick"])
- show_htf_overlay = input.bool(true, "Show HTF Candle Overlay")
- htf_map = input.string("Auto", "HTF Mapping Mode", options=["Auto", "Manual"])
- htf_manual_tf = input.timeframe("60", "Manual HTF timeframe (when HTF Mapping = Manual)")
- htf_show_last_n = input.int(3, "Show last n HTF candles", minval=1, maxval=6)
- htf_box_fill_opacity = input.int(80, "HTF box fill opacity (0-255)", minval=0, maxval=255)
- htf_body_thickness = input.int(8, "HTF body thickness (visual)", minval=1, maxval=50)
- show_eq_htf = input.bool(true, "Show HTF EQ (0/50/100)")
- show_eq_cisd = input.bool(true, "Show CISD EQ (mid-body)")
- history_enabled = input.bool(true, "Save setups to History")
- history_max_entries = input.int(30, "Max History Setups", minval=1, maxval=200)
- theme_mode = input.string("Modern", "Theme", options=["TTrades Classic", "Modern", "Dark"])
- col_proj = input.color(color.new(color.blue, 0), "Projection Color")
- col_cisd_bull = input.color(color.new(color.green, 0), "CISD Bull Color")
- col_cisd_bear = input.color(color.new(color.red, 0), "CISD Bear Color")
- col_htf_bull = input.color(color.new(color.teal, 80), "HTF Bull Fill")
- col_htf_bear = input.color(color.new(color.maroon, 80), "HTF Bear Fill")
- alerts_enabled = input.bool(true, "Enable alerts")
- security_request_budget = input.int(12, "Security call budget (max simultaneous)", minval=1, maxval=40)
- debug_mode = input.bool(false, "Debug mode (show extra labels)")
- // ------------------------------------------------------
- // Helpers
- // ------------------------------------------------------
- inside_time_filter() =>
- if not use_time_filter
- true
- else
- s1 = tf1_on ? not na(time(timeframe.period, tf1_session)) : false
- s2 = tf2_on ? not na(time(timeframe.period, tf2_session)) : false
- s3 = tf3_on ? not na(time(timeframe.period, tf3_session)) : false
- s1 or s2 or s3
- body_size(o,c) => math.abs(c - o)
- candle_range(h,l) => (h - l)
- body_ratio(o,h,l,c) => (candle_range(h,l) == 0.0) ? 0.0 : math.abs(c - o) / candle_range(h,l)
- // safe security wrapper (simple)
- safe_request(sym, tf, expr) =>
- // in heavy scripts we'd gate by security_request_budget
- request.security(sym, tf, expr)
- // ======================================================
- // Module A: Market Structure (CHoCH / BOS)
- // ======================================================
- var float ms_last_swing_high = na
- var float ms_last_swing_low = na
- var bool ms_bos_bull = false
- var bool ms_bos_bear = false
- var bool ms_choch_bull = false
- var bool ms_choch_bear = false
- var int ms_trend = 0
- if not enable_module_structure
- var int ms_trend1 = 0
- else
- var float prev_sh_price = na
- var int prev_sh_bar = na
- var float last_sh_price = na
- var int last_sh_bar = na
- var float prev_sl_price = na
- var int prev_sl_bar = na
- var float last_sl_price = na
- var int last_sl_bar = na
- ph = ta.pivothigh(high, ms_pivot_len, ms_pivot_len)
- pl = ta.pivotlow(low, ms_pivot_len, ms_pivot_len)
- if not na(ph)
- pivot_bar = bar_index - ms_pivot_len
- pivot_price = ph
- prev_sh_price := last_sh_price
- prev_sh_bar := last_sh_bar
- last_sh_price := pivot_price
- last_sh_bar := pivot_bar
- if debug_mode
- label.new(pivot_bar, pivot_price, "SH", style=label.style_label_down, color=color.orange, textcolor=color.white)
- if not na(pl)
- pivot_bar = bar_index - ms_pivot_len
- pivot_price = pl
- prev_sl_price := last_sl_price
- prev_sl_bar := last_sl_bar
- last_sl_price := pivot_price
- last_sl_bar := pivot_bar
- if debug_mode
- label.new(pivot_bar, pivot_price, "SL", style=label.style_label_up, color=color.teal, textcolor=color.white)
- if not na(prev_sh_price) and not na(last_sh_price) and not na(prev_sl_price) and not na(last_sl_price)
- up_condition = (last_sh_price > prev_sh_price) and (last_sl_price > prev_sl_price)
- down_condition = (last_sh_price < prev_sh_price) and (last_sl_price < prev_sl_price)
- if up_condition
- ms_trend := 1
- else if down_condition
- ms_trend := -1
- else
- ms_trend := 0
- else
- ms_trend := 0
- ms_bos_bull := false
- ms_bos_bear := false
- if not na(prev_sh_price)
- if close > prev_sh_price
- ms_bos_bull := true
- if not na(prev_sl_price)
- if close < prev_sl_price
- ms_bos_bear := true
- ms_choch_bull := false
- ms_choch_bear := false
- if ms_detect_choch
- if ms_trend == 1 and ms_bos_bear
- ms_choch_bear := true
- if ms_trend == -1 and ms_bos_bull
- ms_choch_bull := true
- if debug_mode
- ttxt = ms_trend == 1 ? "Trend: UP" : ms_trend == -1 ? "Trend: DOWN" : "Trend: N"
- label.new(bar_index, high, ttxt, style=label.style_label_left, color=color.new(color.blue, 90), textcolor=color.white, size=size.small)
- if ms_bos_bull and ms_detect_bos
- label.new(bar_index, high, "BOS↑", style=label.style_label_down, color=color.new(color.green, 0), textcolor=color.white, size=size.small)
- if ms_bos_bear and ms_detect_bos
- label.new(bar_index, low, "BOS↓", style=label.style_label_up, color=color.new(color.red, 0), textcolor=color.white, size=size.small)
- if ms_choch_bull
- label.new(bar_index, low, "CHoCH↑", style=label.style_label_up, color=color.new(color.lime, 0), textcolor=color.black, size=size.small)
- if ms_choch_bear
- label.new(bar_index, high, "CHoCH↓", style=label.style_label_down, color=color.new(color.orange, 0), textcolor=color.black, size=size.small)
- ms_last_swing_high := last_sh_price
- ms_last_swing_low := last_sl_price
- // ======================================================
- // Module B: Liquidity Engine (Pools, Sweeps, Swings)
- // ======================================================
- liq_pool_lookback = input.int(20, "Liquidity Pool Lookback (bars)", minval=3)
- liq_pool_tol_pct = input.float(0.3, "Pool tolerance (%) - e.g. 0.3 = 0.3%", step=0.1)
- liq_sweep_threshold_atr = input.float(0.5, "Sweep threshold (ATR multiples)", step=0.1)
- liq_min_pool_hits = input.int(2, "Min hits in lookback to count as pool", minval=1)
- liq_history_max = input.int(30, "Max liquidity pool history entries", minval=1, maxval=200)
- tol_price(p) => p * (liq_pool_tol_pct / 100.0)
- atr_val = ta.atr(14)
- var bool liq_pool_high = false
- var bool liq_pool_low = false
- var bool liq_sweep_bear = false
- var bool liq_sweep_bull = false
- var float last_pool_high_price = na
- var float last_pool_low_price = na
- var float[] liq_pool_high_history = array.new_float()
- var float[] liq_pool_low_history = array.new_float()
- ref_sh = float(na)
- ref_sl = float(na)
- if not na(ms_last_swing_high)
- ref_sh := ms_last_swing_high
- if not na(ms_last_swing_low)
- ref_sl := ms_last_swing_low
- calc_pool_high() =>
- mh = ta.highest(high, liq_pool_lookback)
- t = tol_price(mh)
- cnt = 0
- for i = 0 to liq_pool_lookback - 1
- if math.abs(high[i] - mh) <= t
- cnt += 1
- [mh, cnt]
- calc_pool_low() =>
- ml = ta.lowest(low, liq_pool_lookback)
- t = tol_price(ml)
- cnt = 0
- for i = 0 to liq_pool_lookback - 1
- if math.abs(low[i] - ml) <= t
- cnt += 1
- [ml, cnt]
- [mh, mh_count] = calc_pool_high()
- [ml, ml_count] = calc_pool_low()
- if mh_count >= liq_min_pool_hits and math.abs(high - mh) <= tol_price(mh)
- liq_pool_high := true
- last_pool_high_price := mh
- array.push(liq_pool_high_history, mh)
- if array.size(liq_pool_high_history) > liq_history_max
- array.shift(liq_pool_high_history)
- else
- liq_pool_high := false
- if ml_count >= liq_min_pool_hits and math.abs(low - ml) <= tol_price(ml)
- liq_pool_low := true
- last_pool_low_price := ml
- array.push(liq_pool_low_history, ml)
- if array.size(liq_pool_low_history) > liq_history_max
- array.shift(liq_pool_low_history)
- else
- liq_pool_low := false
- liq_sweep_bear := false
- liq_sweep_bull := false
- if not na(ref_sh)
- wick_above = (high > ref_sh + (atr_val * liq_sweep_threshold_atr))
- close_back_inside = (close < ref_sh)
- if wick_above and close_back_inside
- liq_sweep_bear := true
- if debug_mode
- label.new(bar_index, high, "SweepHigh", color=color.red, style=label.style_label_down, textcolor=color.white)
- if not na(ref_sl)
- wick_below = (low < ref_sl - (atr_val * liq_sweep_threshold_atr))
- close_back_inside_low = (close > ref_sl)
- if wick_below and close_back_inside_low
- liq_sweep_bull := true
- if debug_mode
- label.new(bar_index, low, "SweepLow", color=color.green, style=label.style_label_up, textcolor=color.white)
- if debug_mode
- if not na(last_pool_high_price)
- label.new(bar_index, last_pool_high_price, "PoolH", color=color.new(color.orange, 60), style=label.style_label_left, textcolor=color.white)
- if not na(last_pool_low_price)
- label.new(bar_index, last_pool_low_price, "PoolL", color=color.new(color.blue, 60), style=label.style_label_left, textcolor=color.white)
- // ======================================================
- // Module C: C2 / C3 Engine (Body-% version)
- // ======================================================
- var bool bullC2 = false
- var bool bearC2 = false
- var bool bullC3 = false
- var bool bearC3 = false
- var bool xc2 = false
- var bool xc4 = false
- var int lastC2Bar = na
- var float lastC2High = na
- var float lastC2Low = na
- var float lastC2EQ = na
- var int lastC2Dir = 0
- var int lastC3Bar = na
- var float lastC3Close = na
- var float proj_anchor_price = na
- var bool proj_anchor_is_body = true
- var int c2_wait_start_bar = na
- var int c4_wait_start_bar = na
- var bool awaiting_c4 = false
- bullC2 := false
- bearC2 := false
- bullC3 := false
- bearC3 := false
- xc2 := false
- xc4 := false
- curr_body_pct = body_ratio(open, high, low, close) * 100.0
- curr_body = math.abs(close - open)
- top_wick = high - math.max(open, close)
- bot_wick = math.min(open, close) - low
- wick_body_top_ratio = curr_body == 0 ? 9999.0 : (top_wick / curr_body)
- wick_body_bot_ratio = curr_body == 0 ? 9999.0 : (bot_wick / curr_body)
- is_bull_body = close > open
- is_bear_body = open > close
- cond_body_pct = curr_body_pct >= (c2_body_ratio_threshold * 100.0)
- wick_ok = (wick_body_top_ratio <= c2_wick_body_ratio) and (wick_body_bot_ratio <= c2_wick_body_ratio)
- tf_ok = inside_time_filter()
- if tf_ok
- if is_bull_body and cond_body_pct and wick_ok
- bullC2 := true
- lastC2Bar := bar_index
- lastC2Dir := 1
- lastC2High := high
- lastC2Low := low
- lastC2EQ := math.min(open, close) + (math.abs(close - open) * 0.5)
- c2_wait_start_bar := bar_index
- lastC3Bar := na
- lastC3Close := na
- if debug_mode
- label.new(bar_index, low, "C2↑", style=label.style_label_up, color=color.new(color.lime,0), textcolor=color.black)
- if is_bear_body and cond_body_pct and wick_ok
- bearC2 := true
- lastC2Bar := bar_index
- lastC2Dir := -1
- lastC2High := high
- lastC2Low := low
- lastC2EQ := math.min(open, close) + (math.abs(close - open) * 0.5)
- c2_wait_start_bar := bar_index
- lastC3Bar := na
- lastC3Close := na
- if debug_mode
- label.new(bar_index, high, "C2↓", style=label.style_label_down, color=color.new(color.orange,0), textcolor=color.white)
- if not na(lastC2Bar)
- if lastC2Dir == 1 and bar_index > lastC2Bar
- if close > lastC2High
- if not c3_wick_not_through_c2_eq or (low >= lastC2EQ)
- bullC3 := true
- lastC3Bar := bar_index
- lastC3Close := close
- proj_anchor_is_body := (proj_anchor_body_or_wick == "Body")
- proj_anchor_price := proj_anchor_is_body ? (open + close) / 2.0 : high
- c2_wait_start_bar := na
- if debug_mode
- label.new(bar_index, low, "C3↑", style=label.style_label_up, color=color.new(color.green,0), textcolor=color.white)
- if lastC2Dir == -1 and bar_index > lastC2Bar
- if close < lastC2Low
- if not c3_wick_not_through_c2_eq or (high <= lastC2EQ)
- bearC3 := true
- lastC3Bar := bar_index
- lastC3Close := close
- proj_anchor_is_body := (proj_anchor_body_or_wick == "Body")
- proj_anchor_price := proj_anchor_is_body ? (open + close) / 2.0 : low
- c2_wait_start_bar := na
- if debug_mode
- label.new(bar_index, high, "C3↓", style=label.style_label_down, color=color.new(color.red,0), textcolor=color.white)
- if not na(c2_wait_start_bar)
- bars_waited = bar_index - c2_wait_start_bar
- if bars_waited >= c2_max_bars_to_c3 and na(lastC3Bar)
- xc2 := true
- if debug_mode
- if lastC2Dir == 1
- label.new(lastC2Bar, lastC2Low, "XC2", style=label.style_label_left, color=color.new(color.gray,0), textcolor=color.white)
- else
- label.new(lastC2Bar, lastC2High, "XC2", style=label.style_label_left, color=color.new(color.gray,0), textcolor=color.white)
- c2_wait_start_bar := na
- lastC2Bar := na
- lastC2High := na
- lastC2Low := na
- lastC2EQ := na
- lastC2Dir := 0
- if awaiting_c4 and not na(c4_wait_start_bar)
- if bar_index - c4_wait_start_bar >= c4_max_bars_to_wait
- xc4 := true
- awaiting_c4 := false
- c4_wait_start_bar := na
- if debug_mode
- label.new(bar_index, close, "XC4", style=label.style_label_center, color=color.new(color.gray,0), textcolor=color.white)
- // ======================================================
- // Module D: CISD Finalization + History + T-Spot
- // ======================================================
- var bool smt_bull = false
- var bool smt_bear = false
- show_tspot = input.bool(true, "Show T-Spot on CISD")
- tspot_label_size = input.string("small", "T-Spot label size", options=["tiny","small","normal","large"])
- history_draw_labels = input.bool(true, "Draw History Markers on Chart")
- history_label_color = input.color(color.new(color.gray, 20), "History marker color")
- var int[] hist_time = array.new_int()
- var int[] hist_dir = array.new_int()
- var float[] hist_anchor = array.new_float()
- var string[] hist_outcome = array.new_string()
- save_history(dir, anchor_price, outcome_str) =>
- array.push(hist_time, bar_index) // store bar_index for exact placement
- array.push(hist_dir, dir)
- array.push(hist_anchor, anchor_price)
- array.push(hist_outcome, outcome_str)
- while array.size(hist_time) > history_max_entries
- array.shift(hist_time)
- array.shift(hist_dir)
- array.shift(hist_anchor)
- array.shift(hist_outcome)
- var bool final_cisd_bull = false
- var bool final_cisd_bear = false
- final_cisd_bull := false
- final_cisd_bear := false
- cisd_require_sweep = input.bool(false, "CISD requires liquidity sweep?")
- cisd_require_msb = input.bool(false, "CISD requires BOS/CHoCH shift?")
- cisd_min_body_pct = input.float(30, "Min candle body % for displacement", minval=1, maxval=100)
- is_displacement() =>
- body = math.abs(close - open)
- rng = high - low
- rng > 0 and ((body / rng) * 100.0) >= cisd_min_body_pct
- // Finalize with SMT gating & history
- smt_ok_for_bull() =>
- if not smt_master_toggle
- true
- else
- if not smt_require_for_cisd
- true
- else
- smt_bull
- smt_ok_for_bear() =>
- if not smt_master_toggle
- true
- else
- if not smt_require_for_cisd
- true
- else
- smt_bear
- if enable_module_cisd
- cisd_bear = false
- cisd_bull = false
- bear_swing_break = not na(ms_last_swing_low) and close < ms_last_swing_low
- bear_liq = liq_sweep_bear or (not cisd_require_sweep)
- bear_shift = (ms_bos_bear or ms_choch_bear or not cisd_require_msb)
- if ms_trend == 1 and is_displacement() and bear_swing_break and bear_liq and bear_shift
- // tentative cisd flag
- cisd_bear := true
- else
- cisd_bear := false
- bull_swing_break = not na(ms_last_swing_high) and close > ms_last_swing_high
- bull_liq = liq_sweep_bull or (not cisd_require_sweep)
- bull_shift = (ms_bos_bull or ms_choch_bull or not cisd_require_msb)
- if ms_trend == -1 and is_displacement() and bull_swing_break and bull_liq and bull_shift
- cisd_bull := true
- else
- cisd_bull := false
- if cisd_bull and tf_ok
- if smt_ok_for_bull()
- final_cisd_bull := true
- c_anchor = not na(proj_anchor_price) ? proj_anchor_price : (not na(ms_last_swing_low) ? ms_last_swing_low : close)
- if history_enabled
- save_history(1, c_anchor, "valid")
- awaiting_c4 := true
- c4_wait_start_bar := bar_index
- if show_tspot
- lbltxt = "T↑"
- lblsize = tspot_label_size == "tiny" ? size.tiny : tspot_label_size == "small" ? size.small : tspot_label_size == "normal" ? size.normal : size.large
- label.new(bar_index, c_anchor, lbltxt, style=label.style_label_up, color=col_cisd_bull, textcolor=color.white, size=lblsize)
- if cisd_bear and tf_ok
- if smt_ok_for_bear()
- final_cisd_bear := true
- c_anchor = not na(proj_anchor_price) ? proj_anchor_price : (not na(ms_last_swing_high) ? ms_last_swing_high : close)
- if history_enabled
- save_history(-1, c_anchor, "valid")
- awaiting_c4 := true
- c4_wait_start_bar := bar_index
- if show_tspot
- lbltxt = "T↓"
- lblsize = tspot_label_size == "tiny" ? size.tiny : tspot_label_size == "small" ? size.small : tspot_label_size == "normal" ? size.normal : size.large
- label.new(bar_index, c_anchor, lbltxt, style=label.style_label_down, color=col_cisd_bear, textcolor=color.white, size=lblsize)
- if xc4
- anchor = not na(proj_anchor_price) ? proj_anchor_price : not na(lastC3Close) ? lastC3Close : close
- if history_enabled
- save_history(lastC2Dir == 1 ? 1 : -1, anchor, "xc4")
- awaiting_c4 := false
- c4_wait_start_bar := na
- if debug_mode
- label.new(bar_index, close, "XC4 Recorded", color=color.gray, textcolor=color.white)
- if xc2
- anchor = not na(lastC2EQ) ? lastC2EQ : not na(lastC2High) ? lastC2High : close
- if history_enabled
- save_history(lastC2Dir == 1 ? 1 : -1, anchor, "xc2")
- if debug_mode
- label.new(bar_index, anchor, "XC2 Recorded", color=color.gray, textcolor=color.white)
- // Draw history markers precisely using stored bar_index
- if history_enabled and history_draw_labels and hist_time.size() > 0
- draw_count = math.min(array.size(hist_time) - 1, math.min(history_max_entries, 20))
- for i = 0 to draw_count
- idx = array.size(hist_time) - 1 - i
- bi = array.get(hist_time, idx)
- dirn = array.get(hist_dir, idx)
- anc = array.get(hist_anchor, idx)
- out = array.get(hist_outcome, idx)
- marktxt = dirn == 1 ? "H↑" : "H↓"
- clr = dirn == 1 ? color.new(color.green, 30) : color.new(color.red, 30)
- // draw at saved bar index
- label.new(bi, anc, marktxt, color=history_label_color, textcolor=color.white, style=label.style_label_left, size=size.tiny)
- // ======================================================
- // Module E: HTF Candle Engine & EQ
- // ======================================================
- get_auto_htf(string tf) =>
- // tf is current chart timeframe string or multiplier; map to HTF
- // We'll use simple mapping rules:
- // if current <= 5m -> 60, 15 -> 240, 60 -> D, 240 -> W, D -> M
- switch
- tf == "5" => "60"
- tf == "15" => "240"
- tf == "60" => "D"
- tf == "240" => "W"
- tf == "1D" => "M"
- => "D"
- htf_tf = (htf_map == "Manual") ? htf_manual_tf : get_auto_htf(timeframe.period)
- // Get last N HTF candles using request.security; fetch series of open/high/low/close with history
- htf_open_0 = request.security(syminfo.tickerid, htf_tf, open)
- htf_high_0 = request.security(syminfo.tickerid, htf_tf, high)
- htf_low_0 = request.security(syminfo.tickerid, htf_tf, low)
- htf_close_0= request.security(syminfo.tickerid, htf_tf, close)
- htf_open_1 = request.security(syminfo.tickerid, htf_tf, open[1])
- htf_high_1 = request.security(syminfo.tickerid, htf_tf, high[1])
- htf_low_1 = request.security(syminfo.tickerid, htf_tf, low[1])
- htf_close_1= request.security(syminfo.tickerid, htf_tf, close[1])
- htf_open_2 = request.security(syminfo.tickerid, htf_tf, open[2])
- htf_high_2 = request.security(syminfo.tickerid, htf_tf, high[2])
- htf_low_2 = request.security(syminfo.tickerid, htf_tf, low[2])
- htf_close_2= request.security(syminfo.tickerid, htf_tf, close[2])
- draw_htf(offset, o,h,l,c) =>
- // draw simple lines representing candle: vertical wick + small body rectangle via two lines
- bodyTop = math.max(o, c)
- bodyBot = math.min(o, c)
- colorEdge = c > o ? color.green : color.red
- colorFill = c > o ? col_htf_bull : col_htf_bear
- // wick
- line.new(bar_index - offset, h, bar_index - offset, l, width=1, color=colorEdge)
- // body rectangle using two lines (left & right)
- line.new(bar_index - offset - 1, bodyTop, bar_index - offset - 1, bodyBot, width=htf_body_thickness, color=colorFill)
- // small horizontal caps
- line.new(bar_index - offset - 1, bodyTop, bar_index - offset + 1, bodyTop, color=colorEdge)
- line.new(bar_index - offset - 1, bodyBot, bar_index - offset + 1, bodyBot, color=colorEdge)
- if enable_module_htf and show_htf_overlay and barstate.islast
- offset = 20
- draw_htf(offset, htf_open_0, htf_high_0, htf_low_0, htf_close_0)
- draw_htf(offset+6, htf_open_1, htf_high_1, htf_low_1, htf_close_1)
- draw_htf(offset+12, htf_open_2, htf_high_2, htf_low_2, htf_close_2)
- if show_eq_htf and enable_module_htf and barstate.islast
- heq50 = htf_low_0 + (htf_high_0 - htf_low_0) * 0.5
- line.new(bar_index, heq50, bar_index + 2, heq50, extend=extend.right, color=color.orange)
- label.new(bar_index, heq50, "HTF 50%", style=label.style_label_left, textcolor=color.orange)
- // ======================================================
- // Module F: SMT Engine (pivot-based, single pair)
- // ======================================================
- smt_bull := false
- smt_bear := false
- if enable_module_smt and smt1_use and enable_module_smt
- // fetch HL from comparison symbol
- [h2,l2,c2] = request.security(smt1_symA, timeframe.period, [high, low, close])
- [h3,l3,c3] = request.security(smt1_symB, timeframe.period, [high, low, close])
- // pivots on base chart and symbols
- ph_base = ta.pivothigh(high, smt_pivot_len, smt_pivot_len)
- pl_base = ta.pivotlow(low, smt_pivot_len, smt_pivot_len)
- ph_symA = ta.pivothigh(h2, smt_pivot_len, smt_pivot_len)
- ph_symB = ta.pivothigh(h3, smt_pivot_len, smt_pivot_len)
- pl_symA = ta.pivotlow(l2, smt_pivot_len, smt_pivot_len)
- pl_symB = ta.pivotlow(l3, smt_pivot_len, smt_pivot_len)
- // simple divergence detection on highs (bearish) and lows (bullish)
- // when base makes higher-high but sym makes lower-high -> bearish SMT
- if not na(ph_base) and not na(ph_symA) and not na(ph_symB)
- // compare direction between base and pair (use symA primarily)
- delta_base = ph_base - ph_base[1]
- delta_sym = ph_symA - ph_symA[1]
- if (delta_base > 0) and (delta_sym < 0)
- smt_bear := true
- if debug_mode
- label.new(bar_index, ph_base, "SMT Bear", color=color.purple, style=label.style_label_down, textcolor=color.white)
- if not na(pl_base) and not na(pl_symA) and not na(pl_symB)
- delta_base_l = pl_base - pl_base[1]
- delta_sym_l = pl_symA - pl_symA[1]
- if (delta_base_l < 0) and (delta_sym_l > 0)
- smt_bull := true
- if debug_mode
- label.new(bar_index, pl_base, "SMT Bull", color=color.purple, style=label.style_label_up, textcolor=color.white)
- // ======================================================
- // Projections Engine
- // ======================================================
- plot_proj(price, lvl, name) =>
- if not proj_master_toggle
- na
- else
- y = price + lvl
- l = line.new(bar_index - 1, y, bar_index, y, extend = proj_extend_right ? extend.right : extend.none, color = col_proj, width = 1)
- l
- // Only draw projections when anchor exists
- if proj_master_toggle and not na(proj_anchor_price)
- // interpret projection multipliers as price offsets—here we will use percentage of ATR for demonstration
- // but per your original design, these are relative levels; we'll implement as price + (proj_multiplier * ATR*mult)
- atr_for_proj = ta.atr(14)
- if proj_show_plus1
- plot_proj(proj_anchor_price, atr_for_proj * 1.0, "+1")
- if proj_show_0
- line.new(bar_index - 1, proj_anchor_price, bar_index, proj_anchor_price, extend = proj_extend_right ? extend.right : extend.none, color = color.orange, width = 1)
- if proj_show_minus1
- plot_proj(proj_anchor_price, -atr_for_proj * 1.0, "-1")
- if proj_show_minus2
- plot_proj(proj_anchor_price, -atr_for_proj * 2.0, "-2")
- if proj_show_minus25
- plot_proj(proj_anchor_price, -atr_for_proj * 2.5, "-2.5")
- if proj_show_minus4
- plot_proj(proj_anchor_price, -atr_for_proj * 4.0, "-4")
- if proj_show_minus45
- plot_proj(proj_anchor_price, -atr_for_proj * 4.5, "-4.5")
- // ======================================================
- // Info Panel
- // ======================================================
- if enable_info_panel and barstate.islast
- // assemble text
- bias_text = ndm_auto_bias ? (final_cisd_bull ? "Bull" : final_cisd_bear ? "Bear" : "Neutral") : bias_manual
- phase_text = bullC3 ? "C3" : bearC3 ? "C3" : bullC2 ? "C2" : bearC2 ? "C2" : "Idle"
- smt_text = smt_bull ? "SMT Bull" : smt_bear ? "SMT Bear" : "None"
- cisd_text = final_cisd_bull ? "Bull CISD" : final_cisd_bear ? "Bear CISD" : "None"
- fail_text = xc2 ? "XC2" : xc4 ? "XC4" : "None"
- proj_text = not na(proj_anchor_price) ? "Anchored" : "Off"
- filter_text = inside_time_filter() ? "In" : "Out"
- htf_text = str.tostring(htf_tf)
- info = "MODEL PANEL\nBias: " + bias_text + "\nPhase: " + phase_text + "\nCISD: " + cisd_text + "\nSMT: " + smt_text + "\nFailures: " + fail_text + "\nProj: " + proj_text + "\nFilter: " + filter_text + "\nHTF: " + htf_text
- label.new(bar_index, high, info, style=label.style_label_right, textcolor=color.white, color=color.new(color.black, 80), size=size.large, xloc=xloc.bar_index, yloc=yloc.price)
- // ======================================================
- // Final cleanup (throttle debug objects)
- // ======================================================
- if not debug_mode
- // Optionally, remove transient labels created earlier to avoid clutter (keeps T-spots & history)
- na
Advertisement
Add Comment
Please, Sign In to add comment