Winchester 10X1T Mountains Down Pro

Kingzenno · study · 162 行 · 点赞 21 · TradingView 原页

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

Pine Script

//@version=6
// Winchester 10X1T Mountains Down Pro
// Own engine, written from scratch for the 10X1T method:
// 1. Pressure: two two-pole smoothers (fast and slow) on the source; the downward gap between them is the pressure.
// 2. The gap is ranked 0..100 against its own recent history. That rank is the mountain you see.
//    A bar only counts when the fast smoother is really below the slow one (gap above zero).
// 3. Mountain rules (judged on closed bars only):
//    a mountain starts when pressure reaches the mountain level; it only ends when pressure falls back
//    into the neutral zone. A dip that stays above neutral belongs to the SAME mountain.
//    Mountains are numbered in a row; an upward mountain starts the count again.
// 4. Colour: grey when calm, white from the mountain level, gold from the peak level. Nothing in between.
// 5. Exhaustion: price pushed below the low of the previous mountain, but the apex gap (in ATR) was smaller.
indicator("Winchester 10X1T Mountains Down Pro", shorttitle="10X1T Mtn Down Pro", overlay=false, precision=2, max_labels_count=500)
 
grpP    = "Pressure engine"
src     = input.source(hl2, "Source", group=grpP)
fastLen = input.int(12, "Fast smoother", minval=2, group=grpP)
slowLen = input.int(48, "Slow smoother", minval=3, group=grpP)
rankLen = input.int(100, "Rank look back", minval=10, group=grpP)
atrLen  = input.int(14, "Volatility length (ATR, exhaustion only)", minval=1, group=grpP)
 
grpM    = "Mountains"
mtnLvl  = input.int(87, "Mountain level", minval=1, maxval=100, group=grpM)
peakLvl = input.int(95, "Peak pressure level", minval=1, maxval=100, group=grpM)
neuLvl  = input.int(50, "Neutral level", minval=0, maxval=99, group=grpM, tooltip="A new mountain is only counted after pressure fell back to this level. A dip that stays above it belongs to the same mountain.")
showNum = input.bool(true, "Number each mountain", group=grpM)
showEx  = input.bool(true, "Mark exhaustion", group=grpM)
 
grpS      = "Style"
showGuide = input.bool(false, "Level guides", group=grpS)
showBox   = input.bool(true, "Status line", group=grpS)
 
// ── Engine ──
f_smooth(float x, int len) =>
    float a  = math.exp(-1.414 * math.pi / len)
    float b  = 2.0 * a * math.cos(1.414 * math.pi / len)
    float c3 = -a * a
    float c1 = 1.0 - b - c3
    var float y = na
    float p1 = nz(y[1], x)
    float p2 = nz(y[2], p1)
    y := na(x[1]) ? x : c1 * (x + x[1]) / 2.0 + b * p1 + c3 * p2
    y
 
fast  = f_smooth(src, fastLen)
slow  = f_smooth(src, slowLen)
vol   = ta.atr(atrLen)
gap   = slow - fast
oGap  = -gap
gapA  = vol > 0 ? gap / vol : na
myP   = ta.percentrank(gap, rankLen)
otP   = ta.percentrank(oGap, rankLen)
mySig = myP >= mtnLvl and gap > 0
otSig = otP >= mtnLvl and oGap > 0
 
// ── Mountain logic (closed bars) ──
var bool  mOn     = false
var bool  mInLvl  = false
var bool  mNeu    = true
var int   mCnt    = 0
var int   mApxB   = na
var float mApxP   = na
var float mApxG   = na
var float mExt    = na
var bool  mExFlag = false
var float mPrevX  = na
var float mPrevG  = na
var label mLbl    = na
var bool  oNeu    = true
 
bool mStart = false
bool mFade  = false
bool mExNew = false
 
if barstate.isconfirmed and not na(myP) and not na(otP) and not na(gapA)
    // the other side only restarts the count
    if otP < neuLvl
        oNeu := true
    if otSig and oNeu
        oNeu := false
        mCnt := 0
        mPrevX := na
        mPrevG := na
    if mySig
        if not mOn
            if mNeu
                mNeu := false
                mOn := true
                mStart := true
                mCnt += 1
                mApxB := bar_index
                mApxP := myP
                mApxG := gapA
                mExt := low
                mExFlag := false
                mLbl := na
        else
            if gapA > mApxG
                mApxB := bar_index
                mApxP := myP
                mApxG := gapA
            mExt := math.min(mExt, low)
        mInLvl := mOn
    else
        if mOn
            mExt := math.min(mExt, low)
            if mInLvl
                mFade := true
            mInLvl := false
            if myP < neuLvl
                mOn := false
                mPrevX := mExt
                mPrevG := mApxG
    if myP < neuLvl
        mNeu := true
    if mFade
        bool ex = mCnt >= 2 and not na(mPrevX) and mExt < mPrevX and mApxG < mPrevG
        if ex and not mExFlag
            mExNew := true
        mExFlag := ex
        if showNum
            string txt = str.tostring(mCnt) + (ex and showEx ? " EX" : "")
            string tip = "Downward mountain " + str.tostring(mCnt) + "\nApex gap " + str.tostring(mApxG, "#.##") + " ATR" + (na(mPrevG) ? "" : "\nPrevious mountain " + str.tostring(mPrevG, "#.##") + " ATR") + (ex ? "\nPrice lower, pressure lower: exhaustion" : "")
            color lc = ex ? color.rgb(214, 64, 64) : mCnt >= 2 ? color.rgb(184, 140, 20) : color.rgb(125, 115, 90)
            if na(mLbl)
                mLbl := label.new(mApxB, -mApxP, txt, xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_up, color=lc, textcolor=mCnt >= 2 and not ex ? color.black : color.white, size=size.small, tooltip=tip)
            else
                label.set_xy(mLbl, mApxB, -mApxP)
                label.set_text(mLbl, txt)
                label.set_color(mLbl, lc)
                label.set_tooltip(mLbl, tip)
 
// ── Look: the classic three colours, nothing washed out ──
neutralCol = color.rgb(120, 125, 135)
warnCol    = color.rgb(255, 255, 255)
extCol     = color.rgb(184, 140, 20)
colM       = mySig ? (myP >= peakLvl ? extCol : warnCol) : neutralCol
 
plot(-myP, title="Downward Pressure", color=colM, style=plot.style_columns, linewidth=2)
hline(0, title="Zero", color=color.new(color.gray, 70), linestyle=hline.style_solid)
plot(showGuide ? -neuLvl : na, title="Neutral level", color=color.new(color.gray, 60), linewidth=1, style=plot.style_circles, display=display.pane)
plot(showGuide ? -mtnLvl : na, title="Mountain level", color=color.new(warnCol, 60), linewidth=1, style=plot.style_circles, display=display.pane)
plot(showGuide ? -peakLvl : na, title="Peak level", color=color.new(extCol, 45), linewidth=1, style=plot.style_circles, display=display.pane)
// keeps room for the mountain numbers inside the pane (invisible)
plot(-118, title="Label room", color=color.new(color.gray, 100), display=display.pane, editable=false)
 
stateNo = mySig ? (na(mApxG) or not mOn or gapA >= mApxG ? 1 : 2) : (mOn and myP >= neuLvl ? 3 : 0)
plot(gapA, title="Pressure gap (ATR)", display=display.data_window)
plot(mCnt, title="Mountain number in this row", display=display.data_window)
plot(stateNo, title="Phase (1 building, 2 past apex, 3 dip, 0 calm)", display=display.data_window)
 
var table box = table.new(position.top_right, 1, 1)
if barstate.islast and showBox
    string ph = stateNo == 1 ? "building" : stateNo == 2 ? "past apex" : stateNo == 3 ? "dip, same mountain" : "calm"
    string bx = mCnt > 0 ? "Down mountain " + str.tostring(mCnt) + ", " + ph + (mExFlag ? ", exhaustion" : "") : "Down: " + ph
    bool lightBg = color.r(chart.bg_color) + color.g(chart.bg_color) + color.b(chart.bg_color) > 450
    table.cell(box, 0, 0, bx, text_color=lightBg ? color.rgb(40, 44, 52) : color.rgb(220, 224, 230), bgcolor=lightBg ? color.new(color.white, 20) : color.new(color.black, 40), text_size=size.small)
 
alertcondition(mStart, title="Downward mountain started", message="10X1T Mountains Down Pro: downward mountain started")
alertcondition(mStart and mCnt == 2, title="Second downward mountain", message="10X1T Mountains Down Pro: second downward mountain started, watch the Cipher Dot")
alertcondition(mFade, title="Downward push past apex", message="10X1T Mountains Down Pro: downward pressure fell below the mountain level")
alertcondition(mExNew, title="Downward exhaustion", message="10X1T Mountains Down Pro: price lower than the previous mountain, pressure lower")

← 返回列表