PHP Code:
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=5
indicator("Master Pattern [LuxAlgo]", "LuxAlgo - Master Pattern Indicator", overlay = true, max_boxes_count = 500, max_lines_count = 500)
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length = input.int(3, 'Contraction Detection Lookback', minval = 1)
liqLength = input.int(20, 'Liquidity Levels', minval = 1)
showMajor = input(true, 'Show Major Pattern')
showMinor = input(true, 'Show Minor Pattern')
//Style
bullCss = input.color(color.teal, 'Bullish Pattern', inline = 'bull', group = 'Pattern Style')
showBullBox = input(true, 'Area', inline = 'bull', group = 'Pattern Style')
showBullLvl = input(true, 'Line', inline = 'bull', group = 'Pattern Style')
bearCss = input.color(color.red, 'Bearish Pattern', inline = 'bear', group = 'Pattern Style')
showBearBox = input(true, 'Area', inline = 'bear', group = 'Pattern Style')
showBearLvl = input(true, 'Line', inline = 'bear', group = 'Pattern Style')
//Liquidity Style
showLiq = input(true, 'Show Liquidity Levels', group = 'Liquidity')
bullLiqCss = input.color(color.teal, 'Upper Liquidity', group = 'Liquidity')
bearLiqCss = input.color(color.red, 'Lower Liquidity', group = 'Liquidity')
//-----------------------------------------------------------------------------}
//UDT
//-----------------------------------------------------------------------------{
type mp
box area
line avg
bool breakup
bool breakdn
//-----------------------------------------------------------------------------}
//Detect contraction
//-----------------------------------------------------------------------------{
var phy = 0., var phx = 0, var pht = 0.
var ply = 0., var plx = 0, var plt = 0.
var float top = na
var float btm = na
n = bar_index
ph = ta.pivothigh(length, length)
pl = ta.pivotlow(length, length)
if ph
pht := math.sign(ph - phy)
phy := ph
if pht == -1 and plt == 1
top := ph
btm := ply
phx := n-length
if pl
plt := math.sign(pl - ply)
ply := pl
if pht == -1 and plt == 1
top := phy
btm := pl
plx := n-length
//-----------------------------------------------------------------------------}
//Set pattern
//-----------------------------------------------------------------------------{
var mp master = mp.new()
//Detect master pattern
isbull = high[length] > top and top > btm
isbear = low[length] < btm and top > btm
if isbull or isbear
css = isbull ? bullCss : bearCss
master.avg.set_x2(n-length)
val = math.avg(top, btm)
//Create new master pattern object
master := mp.new(
(isbull and showBullBox) or (isbear and showBearBox) ? box.new(math.max(phx, plx), top, n-length, btm, na, bgcolor = showMinor ? color.new(css, 50) : na) : na
, (isbull and showBullLvl) or (isbear and showBearLvl) ? line.new(n-length, val, n, val, color = showMinor ? css : na) : na
, isbull
, isbear)
top := na
btm := na
//Determine if pattern switch to major
if master.breakup
if low < master.area.get_bottom()
if not showMajor
master.area.delete()
master.avg.delete()
else
master.area.set_border_color(bullCss)
if not showMinor
master.area.set_bgcolor(color.new(bullCss, 50))
master.avg.set_color(bullCss)
else if master.breakdn
if high > master.area.get_top()
if not showMajor
master.area.delete()
master.avg.delete()
else
master.area.set_border_color(bearCss)
if not showMinor
master.area.set_bgcolor(color.new(bearCss, 50))
master.avg.set_color(bearCss)
//Set friction level x2 coordinate to current bar
if not na(master.avg)
master.avg.set_x2(n)
//-----------------------------------------------------------------------------}
//Liquidity levels
//-----------------------------------------------------------------------------{
var line liqup = na, var liqup_reach = false
var line liqdn = na, var liqdn_reach = false
liqph = ta.pivothigh(liqLength, liqLength)
liqpl = ta.pivotlow(liqLength, liqLength)
//Set upper liquidity
if liqph and showLiq
if not liqup_reach
liqup.set_x2(n-liqLength)
liqup := line.new(n-liqLength, liqph, n, liqph, color = bullLiqCss, style = line.style_dotted)
liqup_reach := false
else if not liqup_reach and showLiq
liqup.set_x2(n)
if high > liqup.get_y1()
liqup_reach := true
//Set lower liquidity
if liqpl and showLiq
if not liqdn_reach
liqdn.set_x2(n-liqLength)
liqdn := line.new(n-liqLength, liqpl, n, liqpl, color = bearLiqCss, style = line.style_dotted)
liqdn_reach := false
else if not liqdn_reach and showLiq
liqdn.set_x2(n)
if low < liqdn.get_y1()
liqdn_reach := true
//-----------------------------------------------------------------------------}
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=5
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length1 = input.int(200, 'Length', minval = 2)
mult = input.float(6., 'Factor', minval = 0, step = .5)
tf = input.timeframe('', 'Timeframe')
src = input(close, 'Source')
//-----------------------------------------------------------------------------}
//Function
//-----------------------------------------------------------------------------{
pred_ranges(length1, mult)=>
var avg = src
var hold_atr = 0.
atr = nz(ta.atr(length1)) * mult
avg := src - avg > atr ? avg + atr :
avg - src > atr ? avg - atr :
avg
hold_atr := avg != avg[1] ? atr / 2 : hold_atr
[avg + hold_atr * 2, avg + hold_atr, avg, avg - hold_atr, avg - hold_atr * 2]
//-----------------------------------------------------------------------------}
//Calculation
//-----------------------------------------------------------------------------{
[prR2
, prR1
, avg
, prS1
, prS2] = request.security(syminfo.tickerid, tf, pred_ranges(length1, mult))
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
//plot_pru2 = plot(prR2, 'PR Upper 2', avg != avg[1] ? na : #f23645)
plot_pru1 = plot(prR1, 'PR Upper 1', avg != avg[1] ? na : #f23645)
plot_pravg = plot(avg , 'PR Average', avg != avg[1] ? na : #5b9cf6)
plot_prl1 = plot(prS1, 'PR Lower 1', avg != avg[1] ? na : #089981)
//plot_prl2 = plot(prS2, 'PR Lower 2', avg != avg[1] ? na : #089981)
//Fills
//fill(plot_pru2, plot_pru1, avg != avg[1] ? na : color.new(#f23645, 95))
//fill(plot_prl1, plot_prl2, avg != avg[1] ? na : color.new(#089981, 95))
//-----------------------------------------------------------------------------}
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=5
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
mult1 = input.float(5, 'Multiplicative Factor', minval = 0)
slope = input.float(14, 'Slope', minval = 0)
width = input.float(80, 'Width %', minval = 0, maxval = 100) / 100
//Style
bullCss1 = input.color(color.teal, 'Average Color', inline = 'avg', group = 'Style')
bearCss1 = input.color(color.red, '' , inline = 'avg', group = 'Style')
area = input.string('Gradient', 'Area', options = ['Gradient', 'Solid'], group = 'Style')
upperCss = input.color(color.new(color.red, 70), 'Upper Area', group = 'Style')
lowerCss = input.color(color.new(color.teal, 70) , 'Lower Area', group = 'Style')
//-----------------------------------------------------------------------------}
//Calculation
//-----------------------------------------------------------------------------{
var float upper = na
var float lower = na
var float avg1 = close
var hold = 0.
var os = 1.
atr = nz(ta.atr(200)) * mult1
avg1 := math.abs(close - avg1) > atr ?
math.avg(close, avg1)
: avg1 + os * (hold / mult1 / slope)
os := math.sign(avg1 - avg1[1])
hold := os != os[1] ? atr : hold
upper := avg1 + width * hold
lower := avg1 - width * hold
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
css = os == 1 ? bullCss1 : bearCss1
plot_upper = plot(upper, 'Upper', na)
plot_avg = plot(avg1, 'Average', os != os[1] ? na : css)
plot_lower = plot(lower, 'Lower', na)
var color upper_topcol = na
var color upper_btmcol = na
var color lower_topcol = na
var color lower_btmcol = na
//Fill
if area == 'Gradient'
upper_topcol := upperCss
upper_btmcol := color.new(chart.bg_color, 100)
lower_topcol := color.new(chart.bg_color, 100)
lower_btmcol := lowerCss
else
upper_topcol := upperCss
upper_btmcol := upperCss
lower_topcol := lowerCss
lower_btmcol := lowerCss
//Upper Area
fill(plot_upper, plot_avg
, top_color = os != os[1] ? na : upper_topcol
, bottom_color = os != os[1] ? na : upper_btmcol
, top_value = upper
, bottom_value = avg1)
//Lower Area
fill(plot_avg, plot_lower
, top_color = os != os[1] ? na : lower_topcol
, bottom_color = os != os[1] ? na : lower_btmcol
, top_value = avg1
, bottom_value = lower)
//-----------------------------------------------------------------------------}
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=5
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
tf1 = input.timeframe('D', 'Timeframe')
//Dashboard
showDash = input(false, 'Show Dashboard', group = 'Dashboard')
dashLoc = input.string('Top Right', 'Location', options = ['Top Right', 'Bottom Right', 'Bottom Left'], group = 'Dashboard')
textSize = input.string('Small', 'Size' , options = ['Tiny', 'Small', 'Normal'] , group = 'Dashboard')
//-----------------------------------------------------------------------------}
//Compute previous day trend
//-----------------------------------------------------------------------------{
//Hold variables
var y = array.new<float>(0)
var x = array.new<int>(0)
var float a = na
var float b = na
var color css1 = na
var up_per = 0
var up_den = 0
var dn_per = 0
var dn_den = 0
n1 = bar_index
dtf = timeframe.change(tf1)
//Test for timeframe change
if dtf
if y.size() > 0
//Calculate regression coefficients
slope = x.covariance(y) / x.variance()
up_per += slope > 0 and a > 0 ? 1 : 0
up_den += a > 0 ? 1 : 0
dn_per += slope < 0 and a < 0 ? 1 : 0
dn_den += a < 0 ? 1 : 0
a := slope
b := y.avg() - a * x.avg()
css1 := a > 0 ? #00897B : #FF5252
//Clear arrays and push data
y.clear(), x.clear()
y.push(close), x.push(n1)
else
y.push(close)
x.push(n1)
//output
epdt = a * n1 + b
//-----------------------------------------------------------------------------}
//Dashboard
//-----------------------------------------------------------------------------{
var table_position = dashLoc == 'Bottom Left' ? position.bottom_left
: dashLoc == 'Top Right' ? position.top_right
: position.bottom_right
var table_size = textSize == 'Tiny' ? size.tiny
: textSize == 'Small' ? size.small
: size.normal
var tb = table.new(table_position, 2, 3
, bgcolor = #1e222d
, border_color = #373a46
, border_width = 1
, frame_color = #373a46
, frame_width = 1)
if showDash
if barstate.isfirst
tb.cell(0, 0, 'Trend Persistence', text_color = color.white, text_size = table_size)
tb.merge_cells(0,0,1,0)
tb.cell(0, 1, 'Uptrend', text_color = #089981, text_size = table_size)
tb.cell(1, 1, 'Downtrend', text_color = #f23645, text_size = table_size)
if barstate.islast
tb.cell(0, 2, str.tostring(up_per / up_den * 100, format.percent), text_color = #089981, text_size = table_size)
tb.cell(1, 2, str.tostring(dn_per / dn_den * 100, format.percent), text_color = #f23645, text_size = table_size)
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
plot(epdt, 'Extrapolated Previous Trend', dtf ? na : css1)
//barcolor(a > 0 ? #00897b80 : #ff525280)
//bgcolor(dtf ? #787b8680 : na, title = 'Timeframe Change')
//-----------------------------------------------------------------------------}
Yer İmleri