本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("KABIR AUTO CAMARILLA SYSTEM PRO", overlay=true, max_lines_count=100, max_labels_count=100)
//━━━━━━━━━━ CAMARILLA SETTINGS ━━━━━━━━━━
g1 = "CAMARILLA TIMEFRAMES"
showD = input.bool(true, "Daily", group=g1)
showW = input.bool(true, "Weekly", group=g1)
showM = input.bool(true, "Monthly", group=g1)
show6M = input.bool(true, "6 Months", group=g1)
showY = input.bool(true, "Yearly", group=g1)
camBack = input.int(100, "Camarilla Line Length", minval=20, maxval=300, group=g1)
//━━━━━━━━━━ MOVING AVERAGES ━━━━━━━━━━
g2 = "MOVING AVERAGES"
show30 = input.bool(true, "MA 30", group=g2)
show50 = input.bool(true, "MA 50", group=g2)
show100 = input.bool(true, "MA 100", group=g2)
show200 = input.bool(true, "MA 200", group=g2)
show369 = input.bool(true, "MA 369", group=g2)
//━━━━━━━━━━ OTHER SYSTEMS ━━━━━━━━━━
g3 = "OTHER SYSTEMS"
showVWAP = input.bool(true, "VWAP", group=g3)
showCPR = input.bool(true, "CPR", group=g3)
showOB = input.bool(true, "OB Bull / OB Bear", group=g3)
showLiquidity = input.bool(true, "Liquidity Bull / Sell", group=g3)
//━━━━━━━━━━ OB AND LIQUIDITY ━━━━━━━━━━
g4 = "OB AND LIQUIDITY"
swingLength = input.int(8, "Liquidity Swing Length", minval=3, maxval=20, group=g4)
obLookback = input.int(8, "OB Search Length", minval=2, maxval=20, group=g4)
shortLength = input.int(12, "OB / Liquidity Short Lines", minval=3, maxval=30, group=g4)
//━━━━━━━━━━ STRONG MOVEMENT FILTER ━━━━━━━━━━
g5 = "STRONG MOVEMENT FILTER"
atrLength = input.int(14, "ATR Length", group=g5)
bodyFactor = input.float(0.50, "Body / ATR Strength", minval=0.1, step=0.05, group=g5)
volumeFactor = input.float(1.20, "Volume Strength", minval=0.5, step=0.1, group=g5)
//━━━━━━━━━━ TREND AI - SMART TRENDLINES ━━━━━━━━━━
g6 = "TREND AI - SMART TRENDLINES"
trendAtrLength = input.int(14, "ATR Length", minval=1, group=g6)
atrFilter = input.float(0.8, "ATR Filter Multiplier", minval=0.1, step=0.1, group=g6)
showMainTrend = input.bool(true, "Show Main Trendline", group=g6)
showInternalTrend = input.bool(true, "Show Internal Trendline", group=g6)
internalPivotFactor = input.float(0.8, "Internal Pivot Factor", minval=0.2, maxval=2.0, step=0.1, group=g6)
touchTolerance = input.float(0.35, "Trendline Touch Tolerance (ATR)", minval=0.05, step=0.05, group=g6)
maxTrendSlope = input.float(0.35, "Maximum Trendline Slope (ATR/Bar)", minval=0.05, step=0.05, group=g6)
showSR = input.bool(true, "Show Support / Resistance", group=g6)
srMergeThreshold = input.float(0.5, "Level Merge Threshold (ATR)", minval=0.1, step=0.1, group=g6)
maxActiveLevels = input.int(3, "Maximum Active Levels", minval=1, maxval=10, group=g6)
breakMode = input.string("Close", "Break Mode", options=["Close"], group=g6)
breakPlacement = input.string("Candle", "Break Label Placement Mode", options=["Candle"], group=g6)
// Main pivot engine is independent of the old trendline sensitivity.
mainPivotLength = 10
//━━━━━━━━━━ CAMARILLA CALCULATION ━━━━━━━━━━
f_cam() =>
h = high[1]
l = low[1]
c = close[1]
r = h - l
r1 = c + r * 1.1 / 12
r2 = c + r * 1.1 / 6
r3 = c + r * 1.1 / 4
r4 = c + r * 1.1 / 2
s1 = c - r * 1.1 / 12
s2 = c - r * 1.1 / 6
s3 = c - r * 1.1 / 4
s4 = c - r * 1.1 / 2
[r1,r2,r3,r4,s1,s2,s3,s4]
[dR1,dR2,dR3,dR4,dS1,dS2,dS3,dS4] = request.security(syminfo.tickerid,"D",f_cam(),lookahead=barmerge.lookahead_on)
[wR1,wR2,wR3,wR4,wS1,wS2,wS3,wS4] = request.security(syminfo.tickerid,"W",f_cam(),lookahead=barmerge.lookahead_on)
[mR1,mR2,mR3,mR4,mS1,mS2,mS3,mS4] = request.security(syminfo.tickerid,"M",f_cam(),lookahead=barmerge.lookahead_on)
[hR1,hR2,hR3,hR4,hS1,hS2,hS3,hS4] = request.security(syminfo.tickerid,"6M",f_cam(),lookahead=barmerge.lookahead_on)
[yR1,yR2,yR3,yR4,yS1,yS2,yS3,yS4] = request.security(syminfo.tickerid,"12M",f_cam(),lookahead=barmerge.lookahead_on)
//━━━━━━━━━━ PIVOT POINTS ━━━━━━━━━━
dPP = request.security(syminfo.tickerid,"D",(high[1]+low[1]+close[1])/3,lookahead=barmerge.lookahead_on)
wPP = request.security(syminfo.tickerid,"W",(high[1]+low[1]+close[1])/3,lookahead=barmerge.lookahead_on)
mPP = request.security(syminfo.tickerid,"M",(high[1]+low[1]+close[1])/3,lookahead=barmerge.lookahead_on)
hPP = request.security(syminfo.tickerid,"6M",(high[1]+low[1]+close[1])/3,lookahead=barmerge.lookahead_on)
yPP = request.security(syminfo.tickerid,"12M",(high[1]+low[1]+close[1])/3,lookahead=barmerge.lookahead_on)
//━━━━━━━━━━ CAMARILLA LINES AND LABELS ━━━━━━━━━━
var array<line> camLines = array.new_line(45,na)
var array<label> camLabels = array.new_label(45,na)
f_level(int idx,float price,string txt,color clr,bool enabled) =>
line ln = array.get(camLines,idx)
label lb = array.get(camLabels,idx)
if enabled and not na(price)
if na(ln)
ln := line.new(bar_index-camBack,price,bar_index+5,price,xloc=xloc.bar_index,color=clr,width=3)
array.set(camLines,idx,ln)
else
line.set_xy1(ln,bar_index-camBack,price)
line.set_xy2(ln,bar_index+5,price)
line.set_color(ln,clr)
if na(lb)
lb := label.new(bar_index+6,price,"KABIR "+txt,xloc=xloc.bar_index,style=label.style_label_left,color=clr,textcolor=color.white,size=size.small)
array.set(camLabels,idx,lb)
else
label.set_xy(lb,bar_index+6,price)
label.set_text(lb,"KABIR "+txt)
label.set_color(lb,clr)
else
if not na(ln)
line.delete(ln)
array.set(camLines,idx,na)
if not na(lb)
label.delete(lb)
array.set(camLabels,idx,na)
if barstate.islast
f_level(0,dR1,"D R1",color.orange,showD)
f_level(1,dR2,"D R2",color.orange,showD)
f_level(2,dR3,"D R3",color.orange,showD)
f_level(3,dR4,"D R4",color.orange,showD)
f_level(4,dS1,"D S1",color.lime,showD)
f_level(5,dS2,"D S2",color.lime,showD)
f_level(6,dS3,"D S3",color.lime,showD)
f_level(7,dS4,"D S4",color.lime,showD)
f_level(8,wR1,"W R1",color.aqua,showW)
f_level(9,wR2,"W R2",color.aqua,showW)
f_level(10,wR3,"W R3",color.aqua,showW)
f_level(11,wR4,"W R4",color.aqua,showW)
f_level(12,wS1,"W S1",color.green,showW)
f_level(13,wS2,"W S2",color.green,showW)
f_level(14,wS3,"W S3",color.green,showW)
f_level(15,wS4,"W S4",color.green,showW)
f_level(16,mR1,"M R1",color.fuchsia,showM)
f_level(17,mR2,"M R2",color.fuchsia,showM)
f_level(18,mR3,"M R3",color.fuchsia,showM)
f_level(19,mR4,"M R4",color.fuchsia,showM)
f_level(20,mS1,"M S1",color.teal,showM)
f_level(21,mS2,"M S2",color.teal,showM)
f_level(22,mS3,"M S3",color.teal,showM)
f_level(23,mS4,"M S4",color.teal,showM)
f_level(24,hR1,"6M R1",color.yellow,show6M)
f_level(25,hR2,"6M R2",color.yellow,show6M)
f_level(26,hR3,"6M R3",color.yellow,show6M)
f_level(27,hR4,"6M R4",color.yellow,show6M)
f_level(28,hS1,"6M S1",color.blue,show6M)
f_level(29,hS2,"6M S2",color.blue,show6M)
f_level(30,hS3,"6M S3",color.blue,show6M)
f_level(31,hS4,"6M S4",color.blue,show6M)
f_level(32,yR1,"Y R1",color.white,showY)
f_level(33,yR2,"Y R2",color.white,showY)
f_level(34,yR3,"Y R3",color.white,showY)
f_level(35,yR4,"Y R4",color.white,showY)
f_level(36,yS1,"Y S1",color.silver,showY)
f_level(37,yS2,"Y S2",color.silver,showY)
f_level(38,yS3,"Y S3",color.silver,showY)
f_level(39,yS4,"Y S4",color.silver,showY)
f_level(41,wPP,"WEEKLY CAM / STANDARD P",color.aqua,showW)
f_level(42,mPP,"MONTHLY CAM / STANDARD P",color.fuchsia,showM)
f_level(43,hPP,"6 MONTH CAM / STANDARD P",color.orange,show6M)
f_level(44,yPP,"YEARLY CAM / STANDARD P",color.white,showY)
//━━━━━━━━━━ MOVING AVERAGES ━━━━━━━━━━
ma30 = ta.sma(close,30)
ma50 = ta.sma(close,50)
ma100 = ta.sma(close,100)
ma200 = ta.sma(close,200)
ma369 = ta.sma(close,369)
plot(show30?ma30:na,"MA 30",color=color.white,linewidth=3)
plot(show50?ma50:na,"MA 50",color=color.orange,linewidth=3)
plot(show100?ma100:na,"MA 100",color=color.aqua,linewidth=3)
plot(show200?ma200:na,"MA 200",color=color.fuchsia,linewidth=3)
plot(show369?ma369:na,"MA 369",color=color.blue,linewidth=3)
//━━━━━━━━━━ VWAP ━━━━━━━━━━
vwapValue = ta.vwap(hlc3)
plot(showVWAP?vwapValue:na,"VWAP",color=color.yellow,linewidth=3)
//━━━━━━━━━━ CPR ━━━━━━━━━━
[dh,dl,dc] = request.security(syminfo.tickerid,"D",[high[1],low[1],close[1]],lookahead=barmerge.lookahead_on)
cprP = (dh+dl+dc)/3
cprBC = (dh+dl)/2
cprTC = 2*cprP-cprBC
cprTop = math.max(cprBC,cprTC)
cprBottom = math.min(cprBC,cprTC)
cprT = plot(showCPR?cprTop:na,"CPR Top",color=color.teal,linewidth=3)
cprB = plot(showCPR?cprBottom:na,"CPR Bottom",color=color.teal,linewidth=3)
plot(showCPR?cprP:na,"CPR Pivot",color=color.yellow,linewidth=3)
fill(cprT,cprB,color=showCPR?color.new(color.teal,88):na)
var label cprPivotLabel = na
if barstate.islast
if showCPR and not na(cprP)
if na(cprPivotLabel)
cprPivotLabel := label.new(bar_index+6,cprP,"KABIR DAILY CAM / CPR / STANDARD P",xloc=xloc.bar_index,style=label.style_label_left,color=color.yellow,textcolor=color.black,size=size.small)
else
label.set_xy(cprPivotLabel,bar_index+6,cprP)
label.set_text(cprPivotLabel,"KABIR DAILY CAM / CPR / STANDARD P")
else
if not na(cprPivotLabel)
label.delete(cprPivotLabel)
cprPivotLabel := na
//━━━━━━━━━━ VOLUME CONFIRMATION ━━━━━━━━━━
atr = ta.atr(atrLength)
volAvg = ta.sma(volume,20)
volumeStrong = na(volume) or na(volAvg) or volAvg==0 or volume>volAvg*volumeFactor
bodyStrong = math.abs(close-open)>=atr*bodyFactor
strongBull = close>open and bodyStrong and volumeStrong
strongBear = close<open and bodyStrong and volumeStrong
//━━━━━━━━━━ TREND AI ENGINE ━━━━━━━━━━
trendATR = ta.atr(trendAtrLength)
internalLength = math.max(2,int(math.round(mainPivotLength*internalPivotFactor)))
mainPH = ta.pivothigh(high,mainPivotLength,mainPivotLength)
mainPL = ta.pivotlow(low,mainPivotLength,mainPivotLength)
internalPH = ta.pivothigh(high,internalLength,internalLength)
internalPL = ta.pivotlow(low,internalLength,internalLength)
// Main pivot memory
var int mainHighBar1 = na
var int mainHighBar2 = na
var float mainHigh1 = na
var float mainHigh2 = na
var int mainLowBar1 = na
var int mainLowBar2 = na
var float mainLow1 = na
var float mainLow2 = na
var line mainUpperLine = na
var line mainLowerLine = na
// Internal pivot memory
var int intHighBar1 = na
var int intHighBar2 = na
var float intHigh1 = na
var float intHigh2 = na
var int intLowBar1 = na
var int intLowBar2 = na
var float intLow1 = na
var float intLow2 = na
var line internalUpperLine = na
var line internalLowerLine = na
//━━━━━━━━━━ SUPPORT / RESISTANCE STORAGE ━━━━━━━━━━
var array<float> srPrices = array.new_float()
var array<bool> srResistance = array.new_bool()
var array<line> srLines = array.new_line()
var array<label> srLabels = array.new_label()
f_add_sr(float price,bool resistance,int pivotBar) =>
int matched = -1
float mergeDistance = trendATR*srMergeThreshold
if array.size(srPrices)>0
for i=0 to array.size(srPrices)-1
if math.abs(array.get(srPrices,i)-price)<=mergeDistance
matched := i
break
if matched>=0
float oldPrice = array.get(srPrices,matched)
float newPrice = (oldPrice+price)/2
array.set(srPrices,matched,newPrice)
line oldLine = array.get(srLines,matched)
label oldLabel = array.get(srLabels,matched)
line.set_y1(oldLine,newPrice)
line.set_y2(oldLine,newPrice)
label.set_y(oldLabel,newPrice)
else
if array.size(srPrices)>=maxActiveLevels
line.delete(array.shift(srLines))
label.delete(array.shift(srLabels))
array.shift(srPrices)
array.shift(srResistance)
color levelColor = resistance?color.red:color.lime
string levelText = resistance?"TREND AI RESISTANCE":"TREND AI SUPPORT"
line newLine = line.new(pivotBar,price,bar_index+5,price,xloc=xloc.bar_index,color=levelColor,width=2)
label newLabel = label.new(bar_index+6,price,levelText,xloc=xloc.bar_index,style=label.style_label_left,color=levelColor,textcolor=color.white,size=size.small)
array.push(srPrices,price)
array.push(srResistance,resistance)
array.push(srLines,newLine)
array.push(srLabels,newLabel)
//━━━━━━━━━━ MAIN TRENDLINE PIVOTS ━━━━━━━━━━
if not na(mainPH)
float pATR = nz(trendATR[mainPivotLength],trendATR)
bool valid = na(mainHigh2) or math.abs(mainPH-mainHigh2)>=pATR*atrFilter
if valid
mainHighBar1 := mainHighBar2
mainHigh1 := mainHigh2
mainHighBar2 := bar_index-mainPivotLength
mainHigh2 := mainPH
if showMainTrend and not na(mainHighBar1) and mainHighBar2!=mainHighBar1
float slope = math.abs((mainHigh2-mainHigh1)/(mainHighBar2-mainHighBar1))
if slope<=pATR*maxTrendSlope
if not na(mainUpperLine)
line.delete(mainUpperLine)
mainUpperLine := line.new(mainHighBar1,mainHigh1,mainHighBar2,mainHigh2,xloc=xloc.bar_index,extend=extend.right,color=color.red,width=3)
if showSR
f_add_sr(mainPH,true,bar_index-mainPivotLength)
if not na(mainPL)
float pATR = nz(trendATR[mainPivotLength],trendATR)
bool valid = na(mainLow2) or math.abs(mainPL-mainLow2)>=pATR*atrFilter
if valid
mainLowBar1 := mainLowBar2
mainLow1 := mainLow2
mainLowBar2 := bar_index-mainPivotLength
mainLow2 := mainPL
if showMainTrend and not na(mainLowBar1) and mainLowBar2!=mainLowBar1
float slope = math.abs((mainLow2-mainLow1)/(mainLowBar2-mainLowBar1))
if slope<=pATR*maxTrendSlope
if not na(mainLowerLine)
line.delete(mainLowerLine)
mainLowerLine := line.new(mainLowBar1,mainLow1,mainLowBar2,mainLow2,xloc=xloc.bar_index,extend=extend.right,color=color.lime,width=3)
if showSR
f_add_sr(mainPL,false,bar_index-mainPivotLength)
//━━━━━━━━━━ INTERNAL TRENDLINE PIVOTS ━━━━━━━━━━
if not na(internalPH)
float pATR = nz(trendATR[internalLength],trendATR)
bool valid = na(intHigh2) or math.abs(internalPH-intHigh2)>=pATR*atrFilter
if valid
intHighBar1 := intHighBar2
intHigh1 := intHigh2
intHighBar2 := bar_index-internalLength
intHigh2 := internalPH
if showInternalTrend and not na(intHighBar1) and intHighBar2!=intHighBar1
float slope = math.abs((intHigh2-intHigh1)/(intHighBar2-intHighBar1))
if slope<=pATR*maxTrendSlope
if not na(internalUpperLine)
line.delete(internalUpperLine)
internalUpperLine := line.new(intHighBar1,intHigh1,intHighBar2,intHigh2,xloc=xloc.bar_index,extend=extend.right,color=color.new(color.red,45),width=2,style=line.style_dashed)
if not na(internalPL)
float pATR = nz(trendATR[internalLength],trendATR)
bool valid = na(intLow2) or math.abs(internalPL-intLow2)>=pATR*atrFilter
if valid
intLowBar1 := intLowBar2
intLow1 := intLow2
intLowBar2 := bar_index-internalLength
intLow2 := internalPL
if showInternalTrend and not na(intLowBar1) and intLowBar2!=intLowBar1
float slope = math.abs((intLow2-intLow1)/(intLowBar2-intLowBar1))
if slope<=pATR*maxTrendSlope
if not na(internalLowerLine)
line.delete(internalLowerLine)
internalLowerLine := line.new(intLowBar1,intLow1,intLowBar2,intLow2,xloc=xloc.bar_index,extend=extend.right,color=color.new(color.lime,45),width=2,style=line.style_dashed)
//━━━━━━━━━━ TREND AI BREAKOUTS ━━━━━━━━━━
float mainUpperNow = na
float mainLowerNow = na
float internalUpperNow = na
float internalLowerNow = na
if showMainTrend and not na(mainUpperLine)
mainUpperNow := line.get_price(mainUpperLine,bar_index)
if showMainTrend and not na(mainLowerLine)
mainLowerNow := line.get_price(mainLowerLine,bar_index)
if showInternalTrend and not na(internalUpperLine)
internalUpperNow := line.get_price(internalUpperLine,bar_index)
if showInternalTrend and not na(internalLowerLine)
internalLowerNow := line.get_price(internalLowerLine,bar_index)
breakBuffer = trendATR*touchTolerance
mainTrendUp = not na(mainUpperNow) and ta.crossover(close,mainUpperNow+breakBuffer)
mainTrendDown = not na(mainLowerNow) and ta.crossunder(close,mainLowerNow-breakBuffer)
internalTrendUp = not na(internalUpperNow) and ta.crossover(close,internalUpperNow+breakBuffer)
internalTrendDown = not na(internalLowerNow) and ta.crossunder(close,internalLowerNow-breakBuffer)
trendUp = mainTrendUp or internalTrendUp
trendDown = mainTrendDown or internalTrendDown
if barstate.isconfirmed and breakMode=="Close" and breakPlacement=="Candle"
if mainTrendUp
label.new(bar_index,low,"TREND AI BREAK UP",xloc=xloc.bar_index,style=label.style_label_up,color=color.green,textcolor=color.white,size=size.small)
if mainTrendDown
label.new(bar_index,high,"TREND AI BREAK DOWN",xloc=xloc.bar_index,style=label.style_label_down,color=color.red,textcolor=color.white,size=size.small)
if internalTrendUp
label.new(bar_index,low,"INTERNAL BREAK UP",xloc=xloc.bar_index,style=label.style_label_up,color=color.new(color.green,20),textcolor=color.white,size=size.tiny)
if internalTrendDown
label.new(bar_index,high,"INTERNAL BREAK DOWN",xloc=xloc.bar_index,style=label.style_label_down,color=color.new(color.red,20),textcolor=color.white,size=size.tiny)
//━━━━━━━━━━ TREND AI VISIBILITY ━━━━━━━━━━
if barstate.islast
if not showMainTrend
if not na(mainUpperLine)
line.delete(mainUpperLine)
mainUpperLine := na
if not na(mainLowerLine)
line.delete(mainLowerLine)
mainLowerLine := na
if not showInternalTrend
if not na(internalUpperLine)
line.delete(internalUpperLine)
internalUpperLine := na
if not na(internalLowerLine)
line.delete(internalLowerLine)
internalLowerLine := na
if not showSR
while array.size(srLines)>0
line.delete(array.pop(srLines))
label.delete(array.pop(srLabels))
array.pop(srPrices)
array.pop(srResistance)
else if array.size(srLines)>0
for i=0 to array.size(srLines)-1
float price = array.get(srPrices,i)
line.set_xy2(array.get(srLines,i),bar_index+5,price)
label.set_xy(array.get(srLabels,i),bar_index+6,price)
//━━━━━━━━━━ LIQUIDITY BULL / SELL ━━━━━━━━━━
swingLow = ta.pivotlow(low,swingLength,swingLength)
swingHigh = ta.pivothigh(high,swingLength,swingLength)
var float lastLow = na
var float lastHigh = na
var line liqBullLine = na
var line liqBearLine = na
var label liqBullLabel = na
var label liqBearLabel = na
if not na(swingLow)
lastLow := swingLow
if showLiquidity
if not na(liqBullLine)
line.delete(liqBullLine)
if not na(liqBullLabel)
label.delete(liqBullLabel)
liqBullLine := line.new(bar_index-swingLength,lastLow,bar_index+shortLength,lastLow,xloc=xloc.bar_index,color=color.lime,width=3)
liqBullLabel := label.new(bar_index+shortLength+1,lastLow,"KABIR LIQ BULL",xloc=xloc.bar_index,style=label.style_label_left,color=color.green,textcolor=color.white,size=size.small)
if not na(swingHigh)
lastHigh := swingHigh
if showLiquidity
if not na(liqBearLine)
line.delete(liqBearLine)
if not na(liqBearLabel)
label.delete(liqBearLabel)
liqBearLine := line.new(bar_index-swingLength,lastHigh,bar_index+shortLength,lastHigh,xloc=xloc.bar_index,color=color.red,width=3)
liqBearLabel := label.new(bar_index+shortLength+1,lastHigh,"KABIR LIQ SELL",xloc=xloc.bar_index,style=label.style_label_left,color=color.red,textcolor=color.white,size=size.small)
//━━━━━━━━━━ OB BULL / OB BEAR ━━━━━━━━━━
var float bullTop = na
var float bullBottom = na
var float bearTop = na
var float bearBottom = na
var line bullTopLine = na
var line bullBottomLine = na
var line bearTopLine = na
var line bearBottomLine = na
var label bullLabel = na
var label bearLabel = na
if showOB and barstate.isconfirmed and strongBull and close>high[1]
int bullOffset = na
for i=1 to obLookback
if na(bullOffset) and close[i]<open[i]
bullOffset := i
if not na(bullOffset)
bullTop := open[bullOffset]
bullBottom := low[bullOffset]
if not na(bullTopLine)
line.delete(bullTopLine)
if not na(bullBottomLine)
line.delete(bullBottomLine)
if not na(bullLabel)
label.delete(bullLabel)
bullTopLine := line.new(bar_index,bullTop,bar_index+shortLength,bullTop,xloc=xloc.bar_index,color=color.lime,width=3)
bullBottomLine := line.new(bar_index,bullBottom,bar_index+shortLength,bullBottom,xloc=xloc.bar_index,color=color.new(color.lime,25),width=3)
bullLabel := label.new(bar_index+shortLength+1,bullTop,"KABIR OB BULL",xloc=xloc.bar_index,style=label.style_label_left,color=color.green,textcolor=color.white,size=size.small)
if showOB and barstate.isconfirmed and strongBear and close<low[1]
int bearOffset = na
for i=1 to obLookback
if na(bearOffset) and close[i]>open[i]
bearOffset := i
if not na(bearOffset)
bearTop := high[bearOffset]
bearBottom := open[bearOffset]
if not na(bearTopLine)
line.delete(bearTopLine)
if not na(bearBottomLine)
line.delete(bearBottomLine)
if not na(bearLabel)
label.delete(bearLabel)
bearTopLine := line.new(bar_index,bearTop,bar_index+shortLength,bearTop,xloc=xloc.bar_index,color=color.red,width=3)
bearBottomLine := line.new(bar_index,bearBottom,bar_index+shortLength,bearBottom,xloc=xloc.bar_index,color=color.new(color.red,25),width=3)
bearLabel := label.new(bar_index+shortLength+1,bearTop,"KABIR OB BEAR",xloc=xloc.bar_index,style=label.style_label_left,color=color.red,textcolor=color.white,size=size.small)
//━━━━━━━━━━ RIGHT LABEL POSITION ━━━━━━━━━━
if barstate.islast
if showOB and not na(bullLabel)
label.set_x(bullLabel,bar_index+shortLength+1)
if showOB and not na(bearLabel)
label.set_x(bearLabel,bar_index+shortLength+1)
if showLiquidity and not na(liqBullLabel)
label.set_x(liqBullLabel,bar_index+shortLength+1)
if showLiquidity and not na(liqBearLabel)
label.set_x(liqBearLabel,bar_index+shortLength+1)
//━━━━━━━━━━ CONFIRMED MOVEMENT ━━━━━━━━━━
bullThreshold = not na(bullTop) and not na(lastLow)?math.max(bullTop,lastLow):na
bearThreshold = not na(bearBottom) and not na(lastHigh)?math.min(bearBottom,lastHigh):na
bullCross = not na(bullThreshold) and ta.crossover(close,bullThreshold)
bearCross = not na(bearThreshold) and ta.crossunder(close,bearThreshold)
confirmedBullMove = barstate.isconfirmed and strongBull and bullCross
confirmedBearMove = barstate.isconfirmed and strongBear and bearCross
//━━━━━━━━━━ ALERTS ━━━━━━━━━━
alertcondition(confirmedBullMove,"KABIR BULL MOVEMENT","KABIR: Confirmed bullish OB and liquidity breakout")
alertcondition(confirmedBearMove,"KABIR BEAR MOVEMENT","KABIR: Confirmed bearish OB and liquidity breakdown")
alertcondition(mainTrendUp and barstate.isconfirmed,"TREND AI MAIN UP","TREND AI: Main trendline close breakout")
alertcondition(mainTrendDown and barstate.isconfirmed,"TREND AI MAIN DOWN","TREND AI: Main trendline close breakdown")
alertcondition(internalTrendUp and barstate.isconfirmed,"TREND AI INTERNAL UP","TREND AI: Internal trendline close breakout")
alertcondition(internalTrendDown and barstate.isconfirmed,"TREND AI INTERNAL DOWN","TREND AI: Internal trendline close breakdown")
alertcondition(trendUp and barstate.isconfirmed,"KABIR TREND UP","KABIR: Confirmed Trend AI upside breakout")
alertcondition(trendDown and barstate.isconfirmed,"KABIR TREND DOWN","KABIR: Confirmed Trend AI downside breakdown")