Attachments forums

Re: TradingView Indicators to MT5 Indicators

RevelationZ, Sun Nov 15, 2026 3:54 am

Future Reference

TD9 Reversal

Code: Select all

  
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Choliszt

//@version=6
indicator("TD Sequential Blocks v6", shorttitle="TD Seq Blocks", overlay=true, max_labels_count=500)

// =========================
// Inputs
// =========================
show_incomplete = input.bool(true, "顯示進行中序列 1-8")
show_completed  = input.bool(true, "顯示完成序列 9")
atr_len         = input.int(14, "ATR 長度", minval=1)
offset_mult     = input.float(0.45, "標籤上下偏移 ATR 倍數", step=0.05)
small_size      = input.string("small", "一般數字大小", options=["tiny", "small", "normal"])
nine_size       = input.string("normal", "數字 9 大小", options=["small", "normal", "large"])

// =========================
// Helpers
// =========================
atr_value = ta.atr(atr_len)

f_size(sz) =>
    if sz == "tiny"
        size.tiny
    else if sz == "small"
        size.small
    else if sz == "normal"
        size.normal
    else
        size.large

normal_text_size = f_size(small_size)
nine_text_size   = f_size(nine_size)

// =========================
// Colors
// =========================
// Buy:冷色系
buy_block_soft = color.new(color.aqua, 65)
buy_block_nine = color.new(color.lime, 0)
buy_text_soft  = color.white
buy_text_nine  = color.black

// Sell:暖色系
sell_block_soft = color.new(color.orange, 65)
sell_block_nine = color.new(color.red, 0)
sell_text_soft  = color.white
sell_text_nine  = color.white

// =========================
// TD Buy Setup
// close > close[4]
// =========================
buy_condition = close > close[4]
var int buy_setup_count = 0

if buy_condition
    buy_setup_count := nz(buy_setup_count[1]) + 1
else
    buy_setup_count := 0

// 完成 Buy 9
if show_completed and buy_setup_count == 9
    for i = 0 to 8
        num_to_display = 9 - i
        is_nine = num_to_display == 9

        block_color = is_nine ? buy_block_nine : buy_block_soft
        text_color  = is_nine ? buy_text_nine  : buy_text_soft
        txt_size    = is_nine ? nine_text_size : normal_text_size
        y_pos       = high[i] + atr_value[i] * offset_mult

        label.new(
             x=bar_index - i,
             y=y_pos,
             text=str.tostring(num_to_display),
             yloc=yloc.price,
             style=label.style_label_down,
             color=block_color,
             textcolor=text_color,
             size=txt_size
         )

// 進行中 Buy 1~8
if show_incomplete and barstate.islast and buy_setup_count > 0 and buy_setup_count < 9
    for i = 0 to buy_setup_count - 1
        num_to_display = buy_setup_count - i
        y_pos = high[i] + atr_value[i] * offset_mult

        label.new(
             x=bar_index - i,
             y=y_pos,
             text=str.tostring(num_to_display),
             yloc=yloc.price,
             style=label.style_label_down,
             color=color.new(buy_block_soft, 15),
             textcolor=buy_text_soft,
             size=normal_text_size
         )

// =========================
// TD Sell Setup
// close < close[4]
// =========================
sell_condition = close < close[4]
var int sell_setup_count = 0

if sell_condition
    sell_setup_count := nz(sell_setup_count[1]) + 1
else
    sell_setup_count := 0

// 完成 Sell 9
if show_completed and sell_setup_count == 9
    for i = 0 to 8
        num_to_display = 9 - i
        is_nine = num_to_display == 9

        block_color = is_nine ? sell_block_nine : sell_block_soft
        text_color  = is_nine ? sell_text_nine  : sell_text_soft
        txt_size    = is_nine ? nine_text_size : normal_text_size
        y_pos       = low[i] - atr_value[i] * offset_mult

        label.new(
             x=bar_index - i,
             y=y_pos,
             text=str.tostring(num_to_display),
             yloc=yloc.price,
             style=label.style_label_up,
             color=block_color,
             textcolor=text_color,
             size=txt_size
         )

// 進行中 Sell 1~8
if show_incomplete and barstate.islast and sell_setup_count > 0 and sell_setup_count < 9
    for i = 0 to sell_setup_count - 1
        num_to_display = sell_setup_count - i
        y_pos = low[i] - atr_value[i] * offset_mult

        label.new(
             x=bar_index - i,
             y=y_pos,
             text=str.tostring(num_to_display),
             yloc=yloc.price,
             style=label.style_label_up,
             color=color.new(sell_block_soft, 15),
             textcolor=sell_text_soft,
             size=normal_text_size
         )
All files in topic