Top-Down Analysis Workflow - Version 1

BigTimeGrampa · study · 131 行 · 点赞 8 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
indicator("Top-Down Analysis Workflow - Version 3", "Top-Down Workflow V3", overlay = true, max_lines_count = 50)
 
// HOW IT WORKS
// Monthly / Weekly: last CLOSED candle. Close above open = BUYING, below = SELLING, doji = WAIT.
//   Read from closed candles only, so the reading is the same on every chart timeframe
//   and changes by itself when a new Monthly or Weekly candle closes.
// Psychological level: the round number nearest to price, and whether it sits above or below price.
//   Auto spacing: forex every 100 pips (JPY every 1.00) with 50s between;
//   gold, silver, oil, indices, crypto one size below the price (gold: 100s with 50s between).
// Trendline and Entry sequence: reminders, done by eye.
// Bottom centre: date of the latest candle (day/month/year, GMT) and pair | timeframe.
 
// ===================== INPUTS =====================
dojiPct = input.float(10.0, "Doji: body smaller than % of candle range = WAIT", minval = 0, maxval = 100, step = 1, group = "Direction") / 100
 
showLvls  = input.bool(true, "Draw psychological levels", group = "Psychological levels")
nLvls     = input.int(5, "Number of levels", minval = 1, maxval = 20, group = "Psychological levels")
lvlMode   = input.string("Auto", "Spacing", options = ["Auto", "Custom"], group = "Psychological levels")
lvlCustom = input.float(50.0, "Custom main spacing (price units)", minval = 0, group = "Psychological levels")
halves    = input.bool(true, "Include half levels (the 50s)", group = "Psychological levels")
quarts    = input.bool(false, "Include quarter levels (Quarters Theory)", group = "Psychological levels")
lvlCol    = input.color(color.new(#787B86, 40), "Line colour", group = "Psychological levels")
 
txtCol  = input.color(#131722, "Text colour", group = "Panel")
txtSize = input.string("Normal", "Text size", options = ["Small", "Normal", "Large"], group = "Panel")
tblPos  = input.string("Top Right", "Panel position", options = ["Top Right", "Bottom Right", "Top Left", "Bottom Left"], group = "Panel")
 
showStamp = input.bool(true, "Show date and pair", group = "Date and pair")
stampSize = input.string("Small", "Size", options = ["Small", "Normal", "Large"], group = "Date and pair")
stampCol  = input.color(color.new(#787B86, 0), "Colour", group = "Date and pair")
 
// ===================== DIRECTION =====================
// 1 = buying, -1 = selling, 0 = wait (doji or no data)
f_candleDir(float o, float c, float h, float l) =>
    float rng = h - l
    int d = 0
    if not na(o) and not na(c) and rng > 0 and math.abs(c - o) > dojiPct * rng
        d := c > o ? 1 : -1
    d
 
[mO, mC, mH, mL] = request.security(syminfo.tickerid, "M", [open[1], close[1], high[1], low[1]], lookahead = barmerge.lookahead_on)
[wO, wC, wH, wL] = request.security(syminfo.tickerid, "W", [open[1], close[1], high[1], low[1]], lookahead = barmerge.lookahead_on)
mDir = f_candleDir(mO, mC, mH, mL)
wDir = f_candleDir(wO, wC, wH, wL)
 
// ===================== PSYCHOLOGICAL LEVELS =====================
f_unit() =>
    float p = close
    int e = int(math.floor(math.log10(p)))
    bool metal = syminfo.basecurrency == "XAU" or syminfo.basecurrency == "XAG"
    bool fx = syminfo.type == "forex" and not metal
    math.pow(10, fx ? e - 2 : e - 1)
 
var array<line> lvlLines = array.new<line>()
var float nearLvl = na
 
if barstate.islast
    while lvlLines.size() > 0
        line.delete(lvlLines.pop())
    if close > 0
        float U = lvlMode == "Custom" and lvlCustom > 0 ? lvlCustom : f_unit()
        float g = quarts ? U / 4 : halves ? U / 2 : U
        float center = math.round(close / g) * g
        nearLvl := math.round_to_mintick(center)
        if showLvls
            int lo = -int((nLvls - 1) / 2)
            int hi = lo + nLvls - 1
            for k = lo to hi
                float lvl = math.round_to_mintick(center + k * g)
                lvlLines.push(line.new(bar_index - 1, lvl, bar_index, lvl, extend = extend.both, color = lvlCol, width = 1, style = line.style_solid))
 
// ===================== PANEL (text only, no background) =====================
pos = tblPos == "Top Right" ? position.top_right : tblPos == "Bottom Right" ? position.bottom_right : tblPos == "Top Left" ? position.top_left : position.bottom_left
sz  = txtSize == "Small" ? size.small : txtSize == "Large" ? size.large : size.normal
var table t = table.new(pos, 2, 6, border_width = 0, frame_width = 0)
 
// Thin line under the row of the chart timeframe (-1 = no line)
// Monthly / 3M / 12M -> MONTHLY, Weekly -> WEEKLY, Daily -> PSYCHOLOGICAL LEVEL, 4H -> TRENDLINE, 1H -> ENTRY SEQUENCE
tfRow = timeframe.ismonthly ? 0 : timeframe.isweekly ? 1 : timeframe.isdaily ? 2 : (timeframe.isminutes and timeframe.multiplier == 240) ? 3 : (timeframe.isminutes and timeframe.multiplier == 60) ? 4 : -1
 
f_rowIdx(int i) =>
    tfRow >= 0 and i > tfRow ? i + 1 : i
 
f_row(int i, string label, string val) =>
    r = f_rowIdx(i)
    table.cell(t, 0, r, label, text_color = txtCol, text_size = sz, text_halign = text.align_center)
    table.cell(t, 1, r, val,   text_color = txtCol, text_size = sz, text_halign = text.align_center)
 
f_dirTxt(int d) =>
    na(d) ? "NO DATA" : d == 1 ? "BUYING" : d == -1 ? "SELLING" : "WAIT"
 
if barstate.islast
    string side = na(nearLvl) ? "" : nearLvl > close ? " ABOVE" : nearLvl < close ? " BELOW" : " AT PRICE"
    string lvlTxt = na(nearLvl) ? "NO DATA" : str.tostring(nearLvl, format.mintick) + side
 
    f_row(0, "MONTHLY",             f_dirTxt(mDir))
    f_row(1, "WEEKLY",              f_dirTxt(wDir))
    f_row(2, "PSYCHOLOGICAL LEVEL", lvlTxt)
    f_row(3, "TRENDLINE",           "CONFIRM TRENDLINE")
    f_row(4, "ENTRY SEQUENCE",      "MARK YOUR SEQUENCE")
 
    if tfRow >= 0
        table.cell(t, 0, tfRow + 1, "", height = 0.15, bgcolor = txtCol, text_size = size.tiny)
        table.cell(t, 1, tfRow + 1, "", height = 0.15, bgcolor = txtCol, text_size = size.tiny)
 
// ===================== DATE AND PAIR (bottom centre) =====================
f_tfTxt() =>
    int m = timeframe.multiplier
    string s = ""
    if timeframe.isseconds
        s := str.tostring(m) + "S"
    else if timeframe.isminutes
        s := m % 60 == 0 ? str.tostring(int(m / 60)) + "H" : str.tostring(m) + "M"
    else if timeframe.isdaily
        s := m == 1 ? "D" : str.tostring(m) + "D"
    else if timeframe.isweekly
        s := m == 1 ? "W" : str.tostring(m) + "W"
    else if timeframe.ismonthly
        s := m == 1 ? "M" : m == 12 ? "1 YEAR" : str.tostring(m) + " MONTHS"
    s
 
stSz = stampSize == "Normal" ? size.normal : stampSize == "Large" ? size.large : size.small
var table stamp = table.new(position.bottom_center, 1, 2, border_width = 0, frame_width = 0)
 
if barstate.islast
    if showStamp
        table.cell(stamp, 0, 0, str.format_time(time, "d/M/yyyy", "GMT"), text_color = stampCol, text_size = stSz, text_halign = text.align_center)
        table.cell(stamp, 0, 1, syminfo.ticker + " | " + f_tfTxt(),        text_color = stampCol, text_size = stSz, text_halign = text.align_center)
    else
        table.clear(stamp, 0, 0, 0, 1)

← 返回列表