±×¸² 1
Ç×»ó ³ë°í¿¡ °¨»ç ÇÕ´Ï´Ù
º¯È¯ºÎŹµå¸³´Ï´Ù ÁÖ¸» Àߺ¸³»¼¼¿ä
indicator("AI-Powered Breakout with Advanced Features", shorttitle="Breakout AI", overlay=true, max_bars_back=500, max_lines_count=400)
// Inputs
length = input.int(20, minval=1, title="Lookback Length")
multiplier = input.float(1.5, title="Multiplier for Adaptive MA")
src = input(close, title="Source")
prd = input.int(defval=5, title="Period", minval=2)
bo_len = input.int(defval=200, title="Max Breakout Length", minval=30, maxval=300)
cwidthu = input.float(defval=3., title="Threshold Rate %", minval=1., maxval=10) / 100
mintest = input.int(defval=2, title="Minimum Number of Tests", minval=1)
bocolorup = input.color(defval=color.blue, title="Breakout Colors", inline="bocol")
bocolordown = input.color(defval=color.red, title="", inline="bocol")
lstyle = input.string(defval="line.style_solid", title="Line Style", options=["line.style_solid", "line.style_dashed", "line.style_dotted"])
// Convert line style from string to line style type
getLineStyle(style) =>
switch style
"line.style_solid" => line.style_solid
"line.style_dashed" => line.style_dashed
"line.style_dotted" => line.style_dotted
lineStyle = getLineStyle(lstyle)
// Calculate Highest High and Lowest Low
highestHigh = ta.highest(high, length)
lowestLow = ta.lowest(low, length)
// Calculate Breakout Levels
breakoutLevel = highestHigh
breakdownLevel = lowestLow
// AI Component: Adaptive Moving Average
fastMA = ta.ema(src, length)
slowMA = ta.ema(fastMA, length)
adaptiveMA = fastMA + multiplier * (fastMA - slowMA)
// Breakout Signals
breakoutSignal = ta.crossover(close, breakoutLevel) and close > adaptiveMA
breakdownSignal = ta.crossunder(close, breakdownLevel) and close < adaptiveMA
// Plot Breakout Levels using line.new
var line breakoutLine = na
var line breakdownLine = na
if na(breakoutLine)
breakoutLine := line.new(x1=bar_index[1], y1=breakoutLevel[1], x2=bar_index, y2=breakoutLevel, color=color.green, style=line.style_dotted)
else
line.set_xy1(breakoutLine, bar_index[1], breakoutLevel[1])
line.set_xy2(breakoutLine, bar_index, breakoutLevel)
if na(breakdownLine)
breakdownLine := line.new(x1=bar_index[1], y1=breakdownLevel[1], x2=bar_index, y2=breakdownLevel, color=color.red, style=line.style_dotted)
else
line.set_xy1(breakdownLine, bar_index[1], breakdownLevel[1])
line.set_xy2(breakdownLine, bar_index, breakdownLevel)
// Additional Breakout Finder Logic
lll = math.max(math.min(bar_index, 300), 1)
float h_ = ta.highest(lll)
float l_ = ta.lowest(lll)
float chwidth = (h_ - l_) * cwidthu
// Check if Pivot High/Low
ph = ta.pivothigh(prd, prd)
pl = ta.pivotlow(prd, prd)
// Keep Pivot Points and their locations in arrays
var phval = array.new_float(0)
var phloc = array.new_int(0)
var plval = array.new_float(0)
var plloc = array.new_int(0)
// Keep PH/PL levels and locations
if not na(ph)
array.unshift(phval, ph)
array.unshift(phloc, bar_index - prd)
if array.size(phval) > 1
for x = array.size(phloc) - 1 to 1
if bar_index - array.get(phloc, x) > bo_len
array.pop(phloc)
array.pop(phval)
if not na(pl)
array.unshift(plval, pl)
array.unshift(plloc, bar_index - prd)
if array.size(plval) > 1
for x = array.size(plloc) - 1 to 1
if bar_index - array.get(plloc, x) > bo_len
array.pop(plloc)
array.pop(plval)
// Check bullish cup
float bomax = na
int bostart = bar_index
num = 0
hgst = ta.highest(prd)[1]
if array.size(phval) >= mintest and close > open and close > hgst
bomax := array.get(phval, 0)
xx = 0
for x = 0 to array.size(phval) - 1
if array.get(phval, x) >= close
break
xx := x
bomax := math.max(bomax, array.get(phval, x))
if xx >= mintest and open <= bomax
for x = 0 to xx
if array.get(phval, x) <= bomax and array.get(phval, x) >= bomax - chwidth
num += 1
bostart := array.get(phloc, x)
if num < mintest or hgst >= bomax
bomax := na
if not na(bomax) and num >= mintest
line.new(x1=bar_index, y1=bomax, x2=bostart, y2=bomax, color=bocolorup, style=lineStyle)
line.new(x1=bar_index, y1=bomax - chwidth, x2=bostart, y2=bomax - chwidth, color=bocolorup, style=lineStyle)
line.new(x1=bostart, y1=bomax - chwidth, x2=bostart, y2=bomax, color=bocolorup, style=lineStyle)
line.new(x1=bar_index, y1=bomax - chwidth, x2=bar_index, y2=bomax, color=bocolorup, style=lineStyle)
plotshape(not na(bomax) and num >= mintest, location=location.belowbar, style=shape.triangleup, color=bocolorup, size=size.small)
alertcondition(not na(bomax) and num >= mintest, title="Breakout", message="Breakout")
// Check bearish cup
float bomin = na
bostart := bar_index
num1 = 0
lwst = ta.lowest(prd)[1]
if array.size(plval) >= mintest and close < open and close < lwst
bomin := array.get(plval, 0)
xx = 0
for x = 0 to array.size(plval) - 1
if array.get(plval, x) <= close
break
xx := x
bomin := math.min(bomin, array.get(plval, x))
if xx >= mintest and open >= bomin
for x = 0 to xx
if array.get(plval, x) >= bomin and array.get(plval, x) <= bomin + chwidth
num1 += 1
bostart := array.get(plloc, x)
if num1 < mintest or lwst <= bomin
bomin := na
if not na(bomin) and num1 >= mintest
line.new(x1=bar_index, y1=bomin, x2=bostart, y2=bomin, color=bocolordown, style=lineStyle)
line.new(x1=bar_index, y1=bomin + chwidth, x2=bostart, y2=bomin + chwidth, color=bocolordown, style=lineStyle)
line.new(x1=bostart, y1=bomin + chwidth, x2=bostart, y2=bomin, color=bocolordown, style=lineStyle)
line.new(x1=bar_index, y1=bomin + chwidth, x2=bar_index, y2=bomin, color=bocolordown, style=lineStyle)
plotshape(not na(bomin) and num1 >= mintest, location=location.abovebar, style=shape.triangledown, color=bocolordown, size=size.small)
alertcondition(not na(bomin) and num1 >= mintest, title="Breakdown", message="Breakdown")
alertcondition((not na(bomax) and num >= mintest) or (not na(bomin) and num1 >= mintest), title="Breakout or Breakdown", message="Breakout or Breakdown")