本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=5
//author: @kivancozbilgic
indicator(title='추세추종 4시간 특화', shorttitle='추세추종 4시간 특화', overlay=true, timeframe='')
//SS = input.bool(true, "L/S Short Term Signals ON/OFF")
//LS = input.bool(true, "L/S Long Term Signals ON/OFF")
ES = input.bool(true, "L/S Entry/Exit Signals ON/OFF")
length = 20
length2 = 55
len2 = 10
len2_2 = 20
showsignals = true
highlighting = true
lower = ta.lowest(length)
upper = ta.highest(length)
lower2 = ta.lowest(length2)
upper2 = ta.highest(length2)
u = plot(upper, 'Upper', color=color.new(#0094FF, 0), editable=false, display=display.none)
l = plot(lower, 'Lower', color=color.new(#0094FF, 0), editable=false, display=display.none)
u2 = plot(upper2, 'Upper2', color=color.new(#0094FF, 0), editable=false, display=display.none)
l2 = plot(lower2, 'Lower2', color=color.new(#0094FF, 0), editable=false, display=display.none)
up = ta.highest(high, length)
down = ta.lowest(low, length)
up2 = ta.highest(high, length2)
down2 = ta.lowest(low, length2)
sup = ta.highest(high, len2)
sdown = ta.lowest(low, len2)
sup2 = ta.highest(high, len2_2)
sdown2 = ta.lowest(low, len2_2)
K1 = ta.barssince(high >= up[1]) <= ta.barssince(low <= down[1]) ? down : up
barssince_1 = ta.barssince(high >= up[1])
barssince_2 = ta.barssince(low <= down[1])
K2 = barssince_1 <= barssince_2 ? sdown : sup
K3 = close > K1 ? down : na
K4 = close < K1 ? up : na
plot(K1, title='Trend Line', color=color.new(color.red, 0), linewidth=2, editable=false, display=display.none)
e = plot(K2, title='Exit Line', color=color.new(color.blue, 0), linewidth=1, style=plot.style_circles, editable=false, display=display.none)
K1_2 = ta.barssince(high >= up2[1]) <= ta.barssince(low <= down2[1]) ? down2 : up2
barssince_1_2 = ta.barssince(high >= up2[1])
barssince_2_2 = ta.barssince(low <= down2[1])
K2_2 = barssince_1_2 <= barssince_2_2 ? sdown2 : sup2
K3_2 = close > K2_2 ? down2 : na
K4_2 = close < K2_2 ? up2 : na
plot(K1_2, title='Trend Line', color=color.new(color.red, 0), linewidth=2, editable=false, display=display.none)
e2 = plot(K2_2, title='Exit Line', color=color.new(color.blue, 0), linewidth=1, style=plot.style_circles, editable=false, display=display.none)
buySignal = high == upper[1] or ta.crossover(high, upper[1])
sellSignal = low == lower[1] or ta.crossover(lower[1], low)
buyExit = low == sdown[1] or ta.crossover(sdown[1], low)
sellExit = high == sup[1] or ta.crossover(high, sup[1])
buySignal2 = high == upper2[1] or ta.crossover(high, upper2[1])
sellSignal2 = low == lower2[1] or ta.crossover(lower2[1], low)
buyExit2 = low == sdown2[1] or ta.crossover(sdown2[1], low)
sellExit2 = high == sup2[1] or ta.crossover(high, sup2[1])
O1 = ta.barssince(buySignal)
O2 = ta.barssince(sellSignal)
O3 = ta.barssince(buyExit)
O4 = ta.barssince(sellExit)
O1_2 = ta.barssince(buySignal2)
O2_2 = ta.barssince(sellSignal2)
O3_2 = ta.barssince(buyExit2)
O4_2 = ta.barssince(sellExit2)
E1 = ta.barssince(buySignal[1])
E2 = ta.barssince(sellSignal[1])
E3 = ta.barssince(buyExit[1])
E4 = ta.barssince(sellExit[1])
E1_2 = ta.barssince(buySignal2[1])
E2_2 = ta.barssince(sellSignal2[1])
E3_2 = ta.barssince(buyExit2[1])
E4_2 = ta.barssince(sellExit2[1])
//plotshape(buySignal and O3 < O1[1] ? down : na, title='Long Entry', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.green, 0))
//plotshape(SS and buySignal and showsignals and O3 < O1[1] ? down : na, title='#1 Long', text='🚀', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 100), textcolor=color.new(color.white, 0))
//plotshape(LS and buySignal2 and showsignals and O3_2 < O1_2[1] ? down2 : na, title='#2 Long', text='😇', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 100), textcolor=color.new(color.white, 0))
//plotshape(sellSignal and O4 < O2[1] ? up : na, title='Short Entry', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.red, 0))
//plotshape(SS and sellSignal and showsignals and O4 < O2[1] ? up : na, title='#1 Short', text='🔨', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 100), textcolor=color.new(color.white, 0))
//plotshape(LS and sellSignal2 and showsignals and O4_2 < O2_2[1] ? up2 : na, title='#2 Short', text='😈', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 100), textcolor=color.new(color.white, 0))
color1 = highlighting and math.min(O1, O2, O3) == O1 ? color.green : na
color2 = highlighting and math.min(O1, O2, O4) == O2 ? color.yellow : na
color1_2 = highlighting and math.min(O1_2, O2_2, O3_2) == O1_2 ? color.gray : na
color2_2 = highlighting and math.min(O1_2, O2_2, O4_2) == O2_2 ? color.red : na
fill(u, e, color=color1, title='#1 Background', transp=88)
fill(l, e, color=color2, title='#1 Background', transp=88)
fill(u2, e2, color=color1_2, title='#2 Background', transp=88)
fill(l2, e2, color=color2_2, title='#2 Background', transp=88)
lcon1 = math.min(O1, O2, O3) == O1
lcon2 = math.min(O1_2, O2_2, O3_2) == O1_2
lcon = lcon1 and lcon2
scon1 = math.min(O1, O2, O4) == O2
scon2 = math.min(O1_2, O2_2, O4_2) == O2_2
scon = scon1 and scon2
var con = 0
if lcon and not lcon[1]
con := 1
if scon and not scon[1]
con := -1
plotshape(ES and lcon and not lcon[1] ? down : na, title = "Long Entry",style = shape.labelup, location = location.absolute, color = color.green, text = "Long Entry", textcolor = color.white)
alertcondition(ES and lcon and not lcon[1], "Long Entry")
plotshape(ES and scon and not scon[1] ? up : na, title = "Short Entry",style = shape.labeldown, location = location.absolute, color = color.red, text = "Short Entry", textcolor = color.white)
alertcondition(ES and scon and not scon[1], "Short Entry")
lexit1 = con == 1 and math.min(O1, O2, O3) != O1 and ES
lexit2 = con == 1 and math.min(O1_2, O2_2, O3_2) != O1_2 and ES
lexit = lexit1 and lexit2
lwarning1 = lexit1 == true and lexit2 == false
lwarning2 = lexit2 == true and lexit1 == false
lwarning = lwarning1 or lwarning2
//plotshape(buyExit and O1 < O3[1] ? up : na, title='Long Exit', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.blue, 0))
plotshape(lexit and not lexit[1]? up : na, title='Long Exit', text='Exit Long', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.blue, 0), textcolor=color.new(color.white, 0))
alertcondition(lexit and not lexit[1], "Long Exit")
plotshape(lwarning and not lwarning[1]? up : na, title='Long Warning', text='⚠️', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.blue, 100), textcolor=color.new(color.white, 0))
alertcondition(lwarning and not lwarning[1], "Long Risk")
sexit1 = con == -1 and math.min(O1, O2, O4) != O2 and ES
sexit2 = con == -1 and math.min(O1_2, O2_2, O4_2) != O2_2 and ES
sexit = sexit1 and sexit2
swarning1 = sexit1 == true and sexit2 == false
swarning2 = sexit1 == false and sexit2 == true
swarning = swarning1 or swarning2
//plotshape(sellExit and O2 < O4[1] ? down : na, title='Short Exit', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.blue, 0))
plotshape(sexit and not sexit[1] ? down: na, title='Short Exit', text='Exit Short', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.blue, 0), textcolor=color.new(color.white, 0))
alertcondition(sexit and not sexit[1], "Short Exit")
plotshape(swarning and not swarning[1]? down : na, title='Short Warning', text='⚠️', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.blue, 100), textcolor=color.new(color.white, 0))
alertcondition(swarning and not swarning[1], "Short Risk")
if lexit or sexit
con := 0
D = input.bool(true,"Daily Open")
bool showPrev = true
bool showMore = false
bool showAvg = false
daily_open(x) =>
trigger = na(time('D')) or ta.change(time('D'))
ta.valuewhen(trigger, open, x)
plot(D ? daily_open(0) : na, 'Daily Open', color.new(color.blue, 0), 2, plot.style_circles)
// Combine all alert conditions into one
allAlerts = (ES and (lcon and not lcon[1])) or (ES and (scon and not scon[1])) or (lexit and not lexit[1]) or (lwarning and not lwarning[1]) or (sexit and not sexit[1]) or (swarning and not swarning[1])
alertcondition(allAlerts, title="ALL Alerts", message="An alert condition has been triggered.")