Kabir Ultimate Pro V6 - Camarilla, Trend AI, FIB & Liquidity

kabirtrader288 · study · 395 行 · 点赞 76 · TradingView 原页

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

Pine Script

//@version=6
indicator("KABIR ULTIMATE PRO V6 - CAMARILLA + TREND AI + FIB + OB + LIQUIDITY", overlay=true, max_lines_count=500, max_labels_count=500)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 1. GENERAL
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
g0 = "GENERAL SETTINGS"
lineBars = input.int(100, "Half Screen Line Length", minval=20, maxval=200, group=g0)
labelSize = input.string("Medium", "Right Label Size", options=["Small", "Medium", "Large"], group=g0)
showLabels = input.bool(true, "Right Side Labels", group=g0)
 
lblSize = labelSize == "Small" ? size.small : labelSize == "Large" ? size.large : size.normal
midWidth = 2
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 2. CAMARILLA
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
g1 = "CAMARILLA TIMEFRAMES"
showD = input.bool(true, "Daily", group=g1)
showW = input.bool(true, "Weekly", group=g1)
showM = input.bool(true, "Monthly", group=g1)
show3M = input.bool(true, "3 Months", group=g1)
show6M = input.bool(true, "6 Months", group=g1)
showY = input.bool(true, "Yearly", group=g1)
 
colD = input.color(color.white, "Daily Color", group=g1)
colW = input.color(color.aqua, "Weekly Color", group=g1)
colM = input.color(color.orange, "Monthly Color", group=g1)
col3M = input.color(color.fuchsia, "3M Color", group=g1)
col6M = input.color(color.lime, "6M Color", group=g1)
colY = input.color(color.yellow, "Yearly Color", group=g1)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 3. TREND AI ENGINE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
g2 = "TREND AI - SMART TRENDLINES"
showMain = input.bool(true, "Show Main Trendline", group=g2)
showInternal = input.bool(true, "Show Internal Trendline", group=g2)
mainPivot = input.int(10, "Main Pivot Length", minval=2, maxval=50, group=g2)
internalFactor = input.float(0.8, "Internal Pivot Factor", minval=0.2, maxval=2, step=0.1, group=g2)
touchTolerance = input.float(0.35, "Trendline Touch Tolerance (ATR)", minval=0.05, step=0.05, group=g2)
maxSlope = input.float(0.35, "Maximum Trendline Slope (ATR/Bar)", minval=0.05, step=0.05, group=g2)
 
g3 = "TREND AI - SUPPORT / RESISTANCE"
showSR = input.bool(true, "Show Support / Resistance", group=g3)
mergeThreshold = input.float(0.5, "Level Merge Threshold (ATR)", minval=0.1, step=0.1, group=g3)
maxLevels = input.int(3, "Maximum Active Levels", minval=1, maxval=3, group=g3)
 
g4 = "TREND AI - BREAKOUTS"
breakDistance = input.float(0.3, "Confirmed Break Distance (ATR)", minval=0.05, step=0.05, group=g4)
minBreakGap = input.int(25, "Minimum Break Label Gap", minval=1, group=g4)
showBreak = input.bool(true, "Show Confirmed Break", group=g4)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 4. FIBONACCI
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
g5 = "MTF FIBONACCI"
showDailyFib = input.bool(true, "Daily Fib", group=g5)
showWeeklyFib = input.bool(true, "Weekly Fib", group=g5)
showMonthlyFib = input.bool(false, "Monthly Fib", group=g5)
 
dailyFibColor = input.color(color.orange, "Daily Color", group=g5)
weeklyFibColor = input.color(color.aqua, "Weekly Color", group=g5)
monthlyFibColor = input.color(color.fuchsia, "Monthly Color", group=g5)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 5. POC / OB / LIQUIDITY
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
g6 = "POC SETTINGS"
showPOC = input.bool(true, "Show Daily POC", group=g6)
pocColor = input.color(color.yellow, "POC Color", group=g6)
 
g7 = "ORDER BLOCK SETTINGS"
showOB = input.bool(true, "Show Order Blocks", group=g7)
bullColor = input.color(color.aqua, "Bullish OB", group=g7)
bearColor = input.color(color.fuchsia, "Bearish OB", group=g7)
 
g8 = "LIQUIDITY SETTINGS"
showLiq = input.bool(true, "Show Liquidity", group=g8)
liqPeriod = input.int(20, "Liquidity Pivot Lookback", minval=5, maxval=100, group=g8)
bslColor = input.color(color.red, "BSL Color", group=g8)
sslColor = input.color(color.lime, "SSL Color", group=g8)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 6. ATR
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
atr = ta.atr(14)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 7. DRAWING ARRAYS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var line[] allLines = array.new_line()
var label[] allLabels = array.new_label()
 
f_clear() =>
    if array.size(allLines) > 0
        for i = array.size(allLines) - 1 to 0
            line.delete(array.get(allLines, i))
        array.clear(allLines)
 
    if array.size(allLabels) > 0
        for i = array.size(allLabels) - 1 to 0
            label.delete(array.get(allLabels, i))
        array.clear(allLabels)
 
f_draw(float price, string tag, color col, int width, line_style) =>
    if not na(price)
        int x1 = math.max(0, bar_index - lineBars)
        int x2 = bar_index + lineBars
 
        line ln = line.new(x1, price, x2, price, xloc=xloc.bar_index, color=col, width=width, style=line_style)
        array.push(allLines, ln)
 
        if showLabels
            label lb = label.new(x2, price, tag + "  " + str.tostring(price, format.mintick), xloc=xloc.bar_index, style=label.style_none, textcolor=col, size=lblSize, textalign=text.align_left)
            array.push(allLabels, lb)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 8. CAMARILLA CALCULATION
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
f_cam(string tf, string name, bool visible, color col) =>
    [o, h, l, c] = request.security(syminfo.tickerid, tf, [open[1], high[1], low[1], close[1]], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
 
    if visible and not na(h) and not na(l) and l != 0
        float r = h - l
        float h1 = c + r * (1.1 / 12)
        float h2 = c + r * (1.1 / 6)
        float h3 = c + r * (1.1 / 4)
        float h4 = c + r * (1.1 / 2)
        float h5 = (h / l) * c
        float l1 = c - r * (1.1 / 12)
        float l2 = c - r * (1.1 / 6)
        float l3 = c - r * (1.1 / 4)
        float l4 = c - r * (1.1 / 2)
        float l5 = c - (h5 - c)
 
        f_draw(c, name + " P", col, midWidth, line.style_solid)
        f_draw(h1, name + " H1", col, midWidth, line.style_solid)
        f_draw(h2, name + " H2", col, midWidth, line.style_solid)
        f_draw(h3, name + " H3", col, midWidth, line.style_solid)
        f_draw(h4, name + " H4", col, midWidth, line.style_solid)
        f_draw(h5, name + " H5", col, midWidth, line.style_solid)
        f_draw(l1, name + " L1", col, midWidth, line.style_solid)
        f_draw(l2, name + " L2", col, midWidth, line.style_solid)
        f_draw(l3, name + " L3", col, midWidth, line.style_solid)
        f_draw(l4, name + " L4", col, midWidth, line.style_solid)
        f_draw(l5, name + " L5", col, midWidth, line.style_solid)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 9. FIBONACCI
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
f_fib(string name, float h, float l, bool visible, color col) =>
    if visible and not na(h) and not na(l) and h > l
        float diff = h - l
        f_draw(h, name + " 1.000", col, midWidth, line.style_solid)
        f_draw(l, name + " 0.000", col, midWidth, line.style_solid)
        f_draw(l + diff * 0.786, name + " 0.786", col, midWidth, line.style_dashed)
        f_draw(l + diff * 0.618, name + " 0.618", col, midWidth, line.style_dashed)
        f_draw(l + diff * 0.500, name + " 0.500", col, midWidth, line.style_dashed)
        f_draw(l + diff * 0.382, name + " 0.382", col, midWidth, line.style_dashed)
        f_draw(l + diff * 0.236, name + " 0.236", col, midWidth, line.style_dashed)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 10. MTF DATA
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[dHigh, dLow, dClose] = request.security(syminfo.tickerid, "D", [high[1], low[1], close[1]], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
 
[wHigh, wLow] = request.security(syminfo.tickerid, "W", [high[1], low[1]], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
 
[mHigh, mLow] = request.security(syminfo.tickerid, "M", [high[1], low[1]], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
 
dailyPOC = request.security(syminfo.tickerid, "D", (high[1] + low[1] + close[1]) / 3, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 11. ORDER BLOCK ENGINE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var float bullOB = na
var float bearOB = na
 
bullImpulse = close > open and close > high[1] and close - open > atr * 1.2
bearImpulse = close < open and close < low[1] and open - close > atr * 1.2
 
if bullImpulse and close[1] < open[1]
    bullOB := low[1]
 
if bearImpulse and close[1] > open[1]
    bearOB := high[1]
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 12. LIQUIDITY ENGINE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
pivotH = ta.pivothigh(high, liqPeriod, liqPeriod)
pivotL = ta.pivotlow(low, liqPeriod, liqPeriod)
 
var float bslPrice = na
var float sslPrice = na
 
if not na(pivotH)
    bslPrice := pivotH
 
if not na(pivotL)
    sslPrice := pivotL
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 13. TREND AI PIVOT ENGINE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
internalLen = math.max(2, int(math.round(mainPivot * internalFactor)))
 
mainPH = ta.pivothigh(high, mainPivot, mainPivot)
mainPL = ta.pivotlow(low, mainPivot, mainPivot)
intPH = ta.pivothigh(high, internalLen, internalLen)
intPL = ta.pivotlow(low, internalLen, internalLen)
 
var float mph1 = na
var float mph2 = na
var int mphx1 = na
var int mphx2 = na
 
var float mpl1 = na
var float mpl2 = na
var int mplx1 = na
var int mplx2 = na
 
var float iph1 = na
var float iph2 = na
var int iphx1 = na
var int iphx2 = na
 
var float ipl1 = na
var float ipl2 = na
var int iplx1 = na
var int iplx2 = na
 
if not na(mainPH)
    mph2 := mph1
    mphx2 := mphx1
    mph1 := mainPH
    mphx1 := bar_index - mainPivot
 
if not na(mainPL)
    mpl2 := mpl1
    mplx2 := mplx1
    mpl1 := mainPL
    mplx1 := bar_index - mainPivot
 
if not na(intPH)
    iph2 := iph1
    iphx2 := iphx1
    iph1 := intPH
    iphx1 := bar_index - internalLen
 
if not na(intPL)
    ipl2 := ipl1
    iplx2 := iplx1
    ipl1 := intPL
    iplx1 := bar_index - internalLen
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 14. TREND AI TOUCH VALIDATION
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
f_hasTouch(int oldX, int newX, float oldY, float newY, bool resistance) =>
    int touches = 0
    if not na(oldX) and not na(newX) and newX > oldX
        float slope = (newY - oldY) / (newX - oldX)
        int startX = math.max(oldX, bar_index - 500)
        for x = startX to newX
            int off = bar_index - x
            if off >= 0 and off <= 500
                float linePrice = oldY + slope * (x - oldX)
                float distance = resistance ? math.abs(high[off] - linePrice) : math.abs(low[off] - linePrice)
                if distance <= atr[off] * touchTolerance
                    touches += 1
    touches >= 2
 
f_trendDraw(int oldX, float oldY, int newX, float newY, string tag, color col, bool resistance) =>
    if not na(oldX) and not na(newX) and newX > oldX
        float slope = (newY - oldY) / (newX - oldX)
        float projected = newY + slope * (bar_index + lineBars - newX)
        bool slopeOK = math.abs(slope) <= atr * maxSlope
        bool touchesOK = f_hasTouch(oldX, newX, oldY, newY, resistance)
 
        if slopeOK and touchesOK
            line ln = line.new(oldX, oldY, bar_index + lineBars, projected, xloc=xloc.bar_index, color=col, width=midWidth)
            array.push(allLines, ln)
 
            if showLabels
                label lb = label.new(bar_index + lineBars, projected, tag + "  " + str.tostring(projected, format.mintick), xloc=xloc.bar_index, style=label.style_none, textcolor=col, size=lblSize)
                array.push(allLabels, lb)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 15. SUPPORT / RESISTANCE ENGINE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var array<float> srLevels = array.new_float()
 
f_storeLevel(array<float> arr, float price) =>
    if not na(price)
        bool merged = false
        if array.size(arr) > 0
            for i = 0 to array.size(arr) - 1
                float oldPrice = array.get(arr, i)
                if math.abs(oldPrice - price) <= atr * mergeThreshold
                    array.set(arr, i, (oldPrice + price) / 2)
                    merged := true
                    break
        if not merged
            array.push(arr, price)
            if array.size(arr) > maxLevels
                array.shift(arr)
 
if not na(intPH)
    f_storeLevel(srLevels, intPH)
 
if not na(intPL)
    f_storeLevel(srLevels, intPL)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 16. CLOSE CONFIRMED BREAKOUT
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var int lastBreakBar = na
bool validBreak = false
float breakPrice = na
string breakText = ""
float distance = atr * breakDistance
 
if showSR and array.size(srLevels) > 0
    for i = 0 to array.size(srLevels) - 1
        float level = array.get(srLevels, i)
 
        if barstate.isconfirmed and close > level + distance and close[1] <= level + distance
            validBreak := true
            breakPrice := close
            breakText := "BREAK UP"
 
        if barstate.isconfirmed and close < level - distance and close[1] >= level - distance
            validBreak := true
            breakPrice := close
            breakText := "BREAK DOWN"
 
bool breakAllowed = validBreak and (na(lastBreakBar) or bar_index - lastBreakBar >= minBreakGap)
 
if breakAllowed
    lastBreakBar := bar_index
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 17. FINAL RENDERING
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if barstate.islast
    f_clear()
 
    // CAMARILLA
    f_cam("D", "D", showD, colD)
    f_cam("W", "W", showW, colW)
    f_cam("M", "M", showM, colM)
    f_cam("3M", "3M", show3M, col3M)
    f_cam("6M", "6M", show6M, col6M)
    f_cam("12M", "YEAR", showY, colY)
 
    // FIBONACCI
    f_fib("D FIB", dHigh, dLow, showDailyFib, dailyFibColor)
    f_fib("W FIB", wHigh, wLow, showWeeklyFib, weeklyFibColor)
    f_fib("M FIB", mHigh, mLow, showMonthlyFib, monthlyFibColor)
 
    // POC
    if showPOC
        f_draw(dailyPOC, "DAILY POC", pocColor, midWidth, line.style_solid)
 
    // ORDER BLOCKS
    if showOB
        f_draw(bullOB, "BULLISH OB", bullColor, midWidth, line.style_solid)
        f_draw(bearOB, "BEARISH OB", bearColor, midWidth, line.style_solid)
 
    // LIQUIDITY
    if showLiq
        f_draw(bslPrice, "BSL", bslColor, midWidth, line.style_dotted)
        f_draw(sslPrice, "SSL", sslColor, midWidth, line.style_dotted)
 
    // MAIN TRENDLINES
    if showMain
        f_trendDraw(mphx2, mph2, mphx1, mph1, "MAIN RESISTANCE", color.red, true)
        f_trendDraw(mplx2, mpl2, mplx1, mpl1, "MAIN SUPPORT", color.lime, false)
 
    // INTERNAL TRENDLINES
    if showInternal
        f_trendDraw(iphx2, iph2, iphx1, iph1, "INTERNAL RESISTANCE", color.orange, true)
        f_trendDraw(iplx2, ipl2, iplx1, ipl1, "INTERNAL SUPPORT", color.aqua, false)
 
    // SUPPORT / RESISTANCE
    if showSR and array.size(srLevels) > 0
        for i = 0 to array.size(srLevels) - 1
            float level = array.get(srLevels, i)
            f_draw(level, "S/R", color.silver, midWidth, line.style_dashed)
 
    // CONFIRMED BREAKOUT
    if showBreak and breakAllowed
        f_draw(breakPrice, breakText, breakText == "BREAK UP" ? color.lime : color.red, midWidth, line.style_solid)

← 返回列表