https://www.tradingview.com/x/4TwTJzap/
Printable View
PHP Code:
//@version=5
type bar
float o = open
float h = high
float l = low
float c = close
int i = bar_index
type trend
float h = na
float l = na
type scythe
polyline a = na
line b = na
type target
float u = na
float l = na
float p = na
int d = 0
bool r = false
line v = na
line h = na
label e = na
type alerts
bool u = na
bool d = na
bool b = na
bool s = na
type prompt
string s = ''
bool c = false
method notify(prompt p) =>
if p.c
alert(p.s, alert.freq_once_per_bar_close)
method any(alerts a) =>
string s = switch
a.s => 'Target Reached '
a.b => 'Target Invalidated'
a.u => 'Breakout '
a.d => 'Breakdown'
=> na
prompt.new(s, not na(s))
method atr(bar b, simple int len = 1) =>
float tr =
na(b.h[1]) ?
b.h - b.l :
math.max(
math.max(
b.h - b.l,
math.abs(b.h - b.c[1])),
math.abs (b.l - b.c[1]))
len == 1 ? tr : ta.rma(tr, len)
method piv(trend t) =>
bool b = switch
na(t.h) and na(t.l) => false
=> true
b
method blade(array<chart.point> a, bool p, simple color u, simple color d) =>
polyline.new(a, false, true, xloc.bar_index, p ? d : u, p ? color.new(d, 80) : color.new(u, 80))
method handle(bar b, trend t, float s) =>
line l = switch
not na(t.l) =>
line.new(b.i, b.h + s, b.i, b.l , xloc.bar_index, extend.none, #9c4b11, line.style_solid, 3)
not na(t.h) =>
line.new(b.i, b.h , b.i, b.l - s, xloc.bar_index, extend.none, #9c4b11, line.style_solid, 3)
l
method goal(target t, bar b, simple int len) =>
t.v := line .new(b.i, b.c, b.i , t.p, xloc.bar_index, extend.none, chart.fg_color, line.style_dashed)
t.h := line .new(b.i, t.p, b.i + len, t.p, xloc.bar_index, extend.none, chart.fg_color, line.style_dashed)
//t.e := label.new(b.i + len, t.p, "HEDEF", xloc.bar_index, yloc.price, #f0a71f78, label.style_label_left, chart.fg_color, size.normal)
method cu(target t, bar b) =>
t.l[1] < b.c[1] and t.l > b.c
method co(target t, bar b) =>
t.u[1] > b.c[1] and t.u < b.c
method cr(target t, bar b) =>
((t.d == 1 and b.c > t.p) or
(t.d == -1 and b.c < t.p))
method reached(target t, bar b) =>
t.h.set_xy2(b.i, t.h.get_y2())
t.e.set_xy (b.i, t.h.get_y2())
t.e.set_color(#4caf4f78)
t.e.set_text ('KAR-AL' )
method failed(target t, bar b) =>
t.h.set_xy2(b.i, t.h.get_y2())
t.e.set_xy (b.i, t.h.get_y2())
t.e.set_color(#a53a3a78)
t.e.set_text ('GEÇERSİZ' )
const string ts = 'Controls how restrained the target calculation is, higher values will result in tighter targets.'
const string tb = 'Adjusts the length of the scythes blade'
const string tp = 'Swing detection length'
const string gs = 'Scythes', const string gt = 'Targets', const string gu = 'UI Options'
len = input.int (20 , "Pivot Length" , 20, 100, 1 , tp, group = gs)
ext = input.int (40 , "Scythe Length" , 20, 200, 1 , tb, group = gs)
sen = input.int (50 , "Sensitivity %", 0 , 100, 10, ts, group = gt)
bts = input.bool (true , "Display" , group = gt)
bbs = input.bool (true , "Breakouts" , group = gu)
colu = input.color(#eee7df, "" , inline = '1', group = gu)
cold = input.color(#c71313, "" , inline = '1', group = gu)
bar b = bar .new( )
float s = b .atr( len) / len
trend t = trend.new(
ta.pivothigh(len, len),
ta.pivotlow (len, len))
var target g = target.new ()
var map<int, float> u = map .new<int, float>()
var map<int, float> l = map .new<int, float>()
if t.piv()
array<chart.point> a = array.new<chart.point>()
bar z = b[len]
bool p = na(t.l)
for i = 0 to ext - 1
float c = s * i + s * math.pow(i, 2) / ext
a.push(chart.point.from_index(z.i + i, (p ? (z.h - c) : (z.l + c))))
a.push(chart.point.from_index(z.i, (p ? (z.h - s * ext / 5) : (z.l + s * ext / 5))))
switch
not na(t.l) =>
l.clear()
for point in a
l.put(point.index, point.price)
not na(t.h) =>
u.clear()
for point in a
u.put(point.index, point.price)
scythe n = scythe.new(a.blade(p, colu, cold), z.handle(t, s * len))
g.u := u.contains(b.i) ? u.get(b.i) : na
g.l := l.contains(b.i) ? l.get(b.i) : na
bool ucon = false
bool dcon = false
bool bcon = false
bool scon = false
if g.cr(b) and not g.r and bts
g.reached(b)
g.r := true
scon := true
if g.co(b) and bts
if not g.r
g.failed(b)
bcon := true
else
ucon := true
g.r := false
g.d := 1
g.p := b.c + s * ext * (2 - sen / 100)
g.goal(b, len)
if g.cu(b) and bts
if not g.r
g.failed(b)
bcon := true
else
dcon := true
g.r := false
g.d := -1
g.p := b.c - s * ext * (2 - sen / 100)
g.goal(b, len)
alerts a = alerts.new(
ucon,
dcon,
bcon,
scon)
plotshape(not na(t.l) ? (b[len]).l + s * len / 5 : na, "ÇIPA", shape.diamond, location.absolute, colu, -len, size = size.normal)
plotshape(not na(t.h) ? (b[len]).h - s * len / 5 : na, "TIRPAN", shape.diamond, location.absolute, cold, -len, size = size.normal)
//plotshape(bbs and a.d, "KIRILIM", shape.labeldown, location.abovebar, color.new(cold, 60), 0, 'AK', chart.fg_color, size = size.normal)
//plotshape(bbs and a.u, "KIRILIM", shape.labelup , location.belowbar, color.new(colu, 60), 0, 'YK', chart.fg_color, size = size.normal)
//alertcondition(a.b, 'Target Reached ', 'Target Reached ')
//alertcondition(a.s, 'Target Invalidated', 'Target Invalidated')
//alertcondition(a.u, 'Breakout ' , 'Breakout ' )
//alertcondition(a.d, 'Breakdown' , 'Breakdown' )
a.any().notify()
///////////////////////////////
PHP Code:
//@version=5
dual_color=false
var bar_value= 1 //(1-16)
currentHigh = high
previousHigh = high[1]
currentClose = close
previousClose = close[1]
currentLow = low
previousLow = low[1]
//
condition1 = currentHigh > previousHigh and currentClose > previousClose and currentLow > previousLow
condition2 = currentHigh < previousHigh and currentClose > previousClose and currentLow > previousLow
condition3 = currentHigh > previousHigh and currentClose > previousClose and currentLow < previousLow
condition4 = currentHigh < previousHigh and currentClose > previousClose and currentLow < previousLow
//--------------------------------------------------------
condition5 = currentHigh > previousHigh and currentClose < previousClose and currentLow > previousLow
condition6 = currentHigh < previousHigh and currentClose < previousClose and currentLow > previousLow
condition7 = currentHigh > previousHigh and currentClose < previousClose and currentLow < previousLow
condition8 = currentHigh < previousHigh and currentClose < previousClose and currentLow < previousLow
open_up = close > open[1]
open_down = close < open[1]
switch
condition1 and open_up => bar_value:=16
condition1 and open_down => bar_value:=15
condition2 and open_up => bar_value:=14
condition2 and open_down => bar_value:=13
condition3 and open_up => bar_value:=12
condition3 and open_down => bar_value:=11
condition4 and open_up => bar_value:=10
condition4 and open_down => bar_value:=9
condition5 and open_up => bar_value:=8
condition5 and open_down => bar_value:=7
condition6 and open_up => bar_value:=6
condition6 and open_down => bar_value:=5
condition7 and open_up => bar_value:=4
condition7 and open_down => bar_value:=3
condition8 and open_up => bar_value:=2
condition8 and open_down => bar_value:=1
//plot(bar_value,display = display.none,title="Bar Value")
barcolor(condition1 and not dual_color ? color.rgb(247, 223, 2) : na, title="C+L+H+")
barcolor(condition2 and not dual_color ? color.rgb(247, 223, 2) : na, title="C+L+H-")
barcolor(condition3 and not dual_color ? color.rgb(247, 223, 2) : na, title="C+L-H+")
barcolor(condition4 and not dual_color ? color.rgb(252, 223, 2) : na, title="C+L-H-")
//--------------------------------------------------------------------------
barcolor(condition5 and not dual_color ? color.rgb(213, 4, 250) : na, title="C-L+H+")
barcolor(condition6 and not dual_color ? color.rgb(213, 4, 250) : na, title="C-L+H-")
barcolor(condition7 and not dual_color ? color.rgb(213, 4, 250) : na, title="C-L-H+")
barcolor(condition8 and not dual_color ? color.rgb(213, 4, 250) : na, title="C-L-H-")
PHP Code:
greencolor = #2DD204
redcolor = #D2042D
_jfract(count)=>
window = math.ceil(count/2)
_hl1 = (ta.highest(high[window], window) - ta.lowest(low[window], window)) / window
_hl2 = (ta.highest(high, window) - ta.lowest(low, window)) / window
_hl = (ta.highest(high, count) - ta.lowest(low, count)) / count
_d = (math.log(_hl1 + _hl2) - math.log(_hl)) / math.log(2)
dim = _d < 1 ? 1 : _d > 2 ? 2 : _d
_kama(src, len, fast, slow, jcount, efratiocalc) =>
fastend = (2.0 /(fast + 1))
slowend = (2.0 /(slow + 1))
mom = math.abs(ta.change(src, len))
vola = math.sum(math.abs(ta.change(src)), len)
efratio = efratiocalc == "Regular" ? (vola != 0 ? mom / vola : 0) : math.min(2.0-_jfract(jcount), 1.0)
alpha = math.pow(efratio * (fastend - slowend) + slowend, 2)
kama = 0.0
kama := alpha * src + (1 - alpha) * nz(kama[1], src)
kama
blsrc = input.source(hl2, "Source", group = "Kaufman AMA Settings")
period = input.int(10, "Period", minval = 0, group = "Kaufman AMA Settings")
kama_fastend = input.float(2, "Kaufman AMA Fast-end Period", minval = 0.0, group = "Kaufman AMA Settings")
kama_slowend = input.float(30, "Kaufman AMA Slow-end Period", minval = 0.0, group = "Kaufman AMA Settings")
efratiocalc = input.string("Regular", "Efficiency Ratio Type", options = ["Regular", "Jurik Fractal Dimension Adaptive"], group = "Kaufman AMA Settings")
jcount = input.int(defval=2, title="Jurik Fractal Dimension Count ", group = "Kaufman AMA Settings")
start = input.float(0, "Start", minval = 0.0, step = 0.01, group = "Parabolic SAR")
accel = input.float(0.1, "Acceleration", minval = 0.0, step = 0.01, group = "Parabolic SAR")
finish = input.float(0.2, "Maximum", minval = 0.0, step = 0.01, group = "Parabolic SAR")
showSar = input.bool(true, "Show PSAR of Kaufman AMA?", group = "UI Options")
showBl = input.bool(true, "Show Kaufman AMA Baseline?", group = "UI Options")
trendmatch = input.bool(true, "Activate Trend Confluence?", group = "UI Options")
colorbars55 = input.bool(true, "Color bars?", group = "UI Options")
kamaHi = _kama(high, period, kama_fastend, kama_slowend, jcount, efratiocalc)
kamaLo = _kama(low, period, kama_fastend, kama_slowend, jcount, efratiocalc)
kamaMid = (kamaHi + kamaLo) * 0.5
pine_sar(start, inc, max, cutoff, _high, _low, _close) =>
var float result = na
var float maxMin = na
var float acceleration = na
var bool isBelow = na
bool isFirstTrendBar = false
if bar_index < cutoff + cutoff * 0.2
if _close > _close[1]
isBelow := true
maxMin := _high
result := _low[1]
else
isBelow := false
maxMin := _low
result := 0
isFirstTrendBar := true
acceleration := start
result := result + acceleration * (maxMin - result)
if isBelow
if result > _low
isFirstTrendBar := true
isBelow := false
result := math.max(_high, maxMin)
maxMin := _low
acceleration := start
else
if result < _high
isFirstTrendBar := true
isBelow := true
result := math.min(_low, maxMin)
maxMin := _high
acceleration := start
if not isFirstTrendBar
if isBelow
if _high > maxMin
maxMin := _high
acceleration := math.min(acceleration + inc, max)
else
if _low < maxMin
maxMin := _low
acceleration := math.min(acceleration + inc, max)
if isBelow
result := math.min(result, _low[1])
if bar_index > 1
result := math.min(result, _low[2])
else
result := math.max(result, _high[1])
if bar_index > 1
result := math.max(result, _high[2])
[result, isBelow]
[sar, isbelow] = pine_sar(start, accel, finish, math.max(period, kama_fastend, kama_slowend), kamaHi, kamaLo, kamaMid)
kamaClose = _kama(blsrc, period, kama_fastend, kama_slowend, jcount, efratiocalc)
trendMatchColor = blsrc > kamaClose and isbelow ? greencolor : blsrc < kamaClose and not isbelow ? redcolor : color.white
regSarColor = isbelow ? greencolor : redcolor
regBlColor = blsrc > kamaClose ? greencolor : redcolor
//plot(showSar ? sar : na, "PSAR", style = plot.style_circles, linewidth = 3, color = trendmatch ? trendMatchColor : regSarColor)
//plot(showBl ? kamaClose : na, "Kaufman AMA Baseline", color = trendmatch ? trendMatchColor : regBlColor, linewidth = 2)
//barcolor(colorbars55 ? trendMatchColor : na)
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © loxx
//@version=5
indicator("..",
shorttitle='.',
overlay = true,
timeframe="",
timeframe_gaps = true,
max_polylines_count = 100,
max_lines_count = 500,
max_labels_count = 500,
precision=2)
//@version=5
multiplier = input.float(title='M', defval=0.5, minval=0.5, maxval=1.9)
timeframe = input.timeframe(title='Timeframe', defval='720')
barsc = input(title='BarsColor', defval=true)
o = request.security(syminfo.tickerid, timeframe, open)
c = request.security(syminfo.tickerid, timeframe, close)
atr33 = request.security(syminfo.tickerid, timeframe, ta.sma(ta.tr, 5))
anomalia = math.abs(o - c) > multiplier * atr33 ? 1 : 0
//barcolor(anomalia == 1 and barsc == 1 ? color.blue : na, 0)
dot = anomalia == 1 and c < o ? o + atr33 : anomalia == 1 and c > o ? o - atr33 : na
plotshape(dot, style=shape.square, color=color.new(color.blue, 0), location=location.absolute)
///////////////////////
//@version=5
// ATR
atrLength = input.int(title="ATR Length", defval=12, minval=1, tooltip="ATR period", group = "Average True Range -ATR-")
lookback = input.int(title="Lookback", defval=14, minval=1, tooltip="How many bars to look back for highs/lows", group = "Average True Range -ATR-")
ATRSizeInput = input.int(title="ATR percentage to use", defval=150, minval=0, tooltip="Stop loss distance times ATR multiplier. Must use full percentage number", group = "Average True Range -ATR-") / 100
atrValue = ta.atr(atrLength)
stopSize = atrValue * ATRSizeInput
lowStop = close - ta.lowest(low, lookback)
highStop = ta.highest(low, lookback) - close
// SUPERTREND
factor = input.float(3.0, "Factor", minval = 0.01, step = 0.01, group = "SuperTrend", tooltip = "The multiplier by which the ATR will get multiplied")
[supertrend, direction] = ta.supertrend(factor, atrLength)
supertrend := barstate.isfirst ? na : supertrend
// Get conditional Stop Loss DISTANCE from current price as ATR multiplier
long_stop_distance = close - stopSize < ta.lowest(low, lookback) ? stopSize : lowStop
short_stop_distance = close + stopSize > ta.lowest(low, lookback) ? stopSize : highStop
long_stop_level = close - long_stop_distance
short_stop_level = close + long_stop_distance
// BOLLINGER BANDS
lengthbb = input.int(20, minval=1, group = "Bollinger Bands")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev", group = "Bollinger Bands")
offset = input.int(0, "Offset", minval = -500, maxval = 500)
[middle, upper, lower] = ta.bb(close, lengthbb, mult)
avg_stop = direction < 0 ? (supertrend + long_stop_level + lower) / 3 : (supertrend + short_stop_level + upper) / 3
plot(avg_stop, title = "Stop ", color = color.rgb(255, 255, 255, 00), style = plot.style_stepline, linewidth = 1, trackprice = true, precision = 2)
//////////////////////
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/
// ~~ © Zeiierman {
//@version=5
indicator("TrendCylinder (Expo)", overlay = true)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ ToolTips {
t1 = "Volatility Period defines the length of the look-back period for calculating volatility. Higher values make the bands adapt more slowly to volatility changes. Lower values make them adapt more quickly."
t2 = "Trend Factor adjusts the sensitivity of the trend line to price movements. A higher value makes the trend line less sensitive and smoother. Lower values make it more sensitive and reactive to price changes."
t3 = "Trend Step controls how quickly the trend line adjusts to sudden price changes. Higher values cause slower adjustments, leading to smoother trend lines. Lower values result in quicker adjustments to sudden changes."
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Inputs {
volatilityPeriod = input.int(100, title="Period", step=10, minval=2, maxval=1000, inline="vol", group="Volatility Settings", tooltip=t1)
trendFactor = input.float(9, step=0.1, title='Factor', minval = 0.1, inline="", group="Trend Settings", tooltip=t2)
trendStep = input.float(0.7, "Step", step=0.1,minval = 0.5, maxval = 5.0, inline="", group="Trend Settings", tooltip=t3)
color_trend = input.color(color.navy, title="Trend Line ", inline="trend", group="Style")
colorForUpperBand = input.color(color.new(#862458, 10), title="Upper Band", inline="band", group="Style")
colorForLowerBand = input.color(color.new(#493893, 10), title="Lower Band", inline="band", group="Style")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Initialize Variables
var float currentTrend = 0.0
var int trendDirection = 0
averageTrueRange = ta.atr(200)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Function to determine the trend direction
determineTrendDirection(direction) => direction - direction[1] > 0 ? 1 : (direction - direction[1] < 0 ? -1 : 0)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Calculate Trend Direction
closingPrice = close
scaledStandardDev = (nz(averageTrueRange) * trendFactor)
trendDirection := determineTrendDirection(currentTrend) * int(scaledStandardDev)
priceTrendDiff = closingPrice - currentTrend > 0 ? closingPrice - currentTrend : currentTrend - closingPrice
reciprocalFactor = (scaledStandardDev * (1 / trendFactor)) * 1 / math.pow(2, 100)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Calculate the Current Trend
trendAdjustment = priceTrendDiff > scaledStandardDev * trendStep ? math.avg(closingPrice, currentTrend) : trendDirection * reciprocalFactor + currentTrend
currentTrend := trendAdjustment
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Calculate Upper and Lower Bands
upperBand = currentTrend + scaledStandardDev - averageTrueRange - ta.ema(ta.stdev(closingPrice, volatilityPeriod), 200)
lowerBand = currentTrend - scaledStandardDev + averageTrueRange + ta.ema(ta.stdev(closingPrice, volatilityPeriod), 200)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Plot
isTrendConsistent = trendDirection == trendDirection[1]
colorForPlot = trendDirection == 1 ? color_trend : color_trend
plotTrend = plot(isTrendConsistent ? currentTrend : na, title="Trend Line", color=colorForPlot)
plotUpper = plot(isTrendConsistent ? upperBand : na, title="Upper Band", color = color.new(color.black, 100))
plotLower = plot(isTrendConsistent ? lowerBand : na, title="Lower Band", color = color.new(color.black, 100))
fill(plotUpper, plotTrend, top_color = colorForLowerBand, bottom_color =color.new(na,100), top_value = upperBand, bottom_value = currentTrend, title="Background Upper")
fill(plotTrend, plotLower, top_color = color.new(na,100), bottom_color = colorForUpperBand, top_value = currentTrend, bottom_value = lowerBand, title="Background Lower")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
PHP Code:
//@version=5
indicator(".",overlay=true,max_boxes_count=50,max_labels_count=50,max_lines_count=144,max_bars_back=1000)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
////////////
greencolor = #2dd204
redcolor = #f80435
_jfract(count)=>
window = math.ceil(count/2)
_hl1 = (ta.highest(high[window], window) - ta.lowest(low[window], window)) / window
_hl2 = (ta.highest(high, window) - ta.lowest(low, window)) / window
_hl = (ta.highest(high, count) - ta.lowest(low, count)) / count
_d = (math.log(_hl1 + _hl2) - math.log(_hl)) / math.log(2)
dim = _d < 1 ? 1 : _d > 2 ? 2 : _d
_kama(src, len, fast, slow, jcount, efratiocalc) =>
fastend = (2.0 /(fast + 1))
slowend = (2.0 /(slow + 1))
mom = math.abs(ta.change(src, len))
vola = math.sum(math.abs(ta.change(src)), len)
efratio = efratiocalc == "Regular" ? (vola != 0 ? mom / vola : 0) : math.min(2.0-_jfract(jcount), 1.0)
alpha = math.pow(efratio * (fastend - slowend) + slowend, 2)
kama = 0.0
kama := alpha * src + (1 - alpha) * nz(kama[1], src)
kama
blsrc = input.source(hl2, "Source", group = "Kaufman AMA Settings")
period = input.int(10, "Period", minval = 0, group = "Kaufman AMA Settings")
kama_fastend = input.float(2, "Kaufman AMA Fast-end Period", minval = 0.0, group = "Kaufman AMA Settings")
kama_slowend = input.float(30, "Kaufman AMA Slow-end Period", minval = 0.0, group = "Kaufman AMA Settings")
efratiocalc = input.string("Regular", "Efficiency Ratio Type", options = ["Regular", "Jurik Fractal Dimension Adaptive"], group = "Kaufman AMA Settings")
jcount = input.int(defval=2, title="Jurik Fractal Dimension Count ", group = "Kaufman AMA Settings")
start = input.float(0, "Start", minval = 0.0, step = 0.01, group = "Parabolic SAR")
accel = input.float(0.1, "Acceleration", minval = 0.0, step = 0.01, group = "Parabolic SAR")
finish = input.float(0.3, "Maximum", minval = 0.0, step = 0.01, group = "Parabolic SAR")
showSar = input.bool(true, "Show PSAR of Kaufman AMA?", group = "UI Options")
showBl = input.bool(true, "Show Kaufman AMA Baseline?", group = "UI Options")
trendmatch = input.bool(true, "Activate Trend Confluence?", group = "UI Options")
colorbars55 = input.bool(true, "Color bars?", group = "UI Options")
kamaHi = _kama(high, period, kama_fastend, kama_slowend, jcount, efratiocalc)
kamaLo = _kama(low, period, kama_fastend, kama_slowend, jcount, efratiocalc)
kamaMid = (kamaHi + kamaLo) * 0.5
pine_sar(start, inc, max, cutoff, _high, _low, _close) =>
var float result = na
var float maxMin = na
var float acceleration = na
var bool isBelow = na
bool isFirstTrendBar = false
if bar_index < cutoff + cutoff * 0.2
if _close > _close[1]
isBelow := true
maxMin := _high
result := _low[1]
else
isBelow := false
maxMin := _low
result := 0
isFirstTrendBar := true
acceleration := start
result := result + acceleration * (maxMin - result)
if isBelow
if result > _low
isFirstTrendBar := true
isBelow := false
result := math.max(_high, maxMin)
maxMin := _low
acceleration := start
else
if result < _high
isFirstTrendBar := true
isBelow := true
result := math.min(_low, maxMin)
maxMin := _high
acceleration := start
if not isFirstTrendBar
if isBelow
if _high > maxMin
maxMin := _high
acceleration := math.min(acceleration + inc, max)
else
if _low < maxMin
maxMin := _low
acceleration := math.min(acceleration + inc, max)
if isBelow
result := math.min(result, _low[1])
if bar_index > 1
result := math.min(result, _low[2])
else
result := math.max(result, _high[1])
if bar_index > 1
result := math.max(result, _high[2])
[result, isBelow]
[sar, isbelow] = pine_sar(start, accel, finish, math.max(period, kama_fastend, kama_slowend), kamaHi, kamaLo, kamaMid)
kamaClose = _kama(blsrc, period, kama_fastend, kama_slowend, jcount, efratiocalc)
trendMatchColor = blsrc > kamaClose and isbelow ? greencolor : blsrc < kamaClose and not isbelow ? redcolor : color.rgb(255, 255, 255, 00)
regSarColor = isbelow ? greencolor : redcolor
regBlColor = blsrc > kamaClose ? greencolor : redcolor
plot(showSar ? sar : na, "Trend", style = plot.style_stepline, linewidth = 2, color = trendmatch ? trendMatchColor : regSarColor)
barcolor(colorbars55 ? trendMatchColor : na)
/////////////////////
s = input.source(ohlc4)
lp = math.log(s)
n = input.int(3)
rollingMean(src,length) =>
mean = 0.00
mean := (nz(mean[1]) * (length-1) + src)/length
stdev(src,length)=>
sd=math.sqrt(rollingMean(src*src,length)-rollingMean(src,length)*rollingMean(src,length))
bandwidth(sd,length) =>
h = 0.00
h := 1.06*sd*math.pow(length,-float(1)/5)
rsd = stdev(lp,n)
rm = rollingMean(lp,n)
plot(math.exp(rm),color=color.rgb(255, 255, 255, 100), title="Stop")
PHP Code:
//@version=5
indicator('.', shorttitle='.', overlay=true, max_polylines_count = 100, max_lines_count = 100, max_labels_count = 100, precision=2)
length = input.int(20, "TTM Squeeze Length")
//BOLLINGER BANDS
BB_mult = input.float(2.0, "Bollinger Band STD Multiplier")
BB_basis = ta.sma(close, length)
dev = BB_mult * ta.stdev(close, length)
BB_upper = BB_basis + dev
BB_lower = BB_basis - dev
atr = ta.atr(14)
//KELTNER CHANNELS
KC_mult_high = input.float(1.0, "Keltner Channel #1")
KC_mult_mid = input.float(1.5, "Keltner Channel #2")
KC_mult_low = input.float(2.0, "Keltner Channel #3")
KC_basis = ta.sma(close, length)
devKC = ta.sma(ta.tr, length)
KC_upper_high = KC_basis + devKC * KC_mult_high
KC_lower_high = KC_basis - devKC * KC_mult_high
KC_upper_mid = KC_basis + devKC * KC_mult_mid
KC_lower_mid = KC_basis - devKC * KC_mult_mid
KC_upper_low = KC_basis + devKC * KC_mult_low
KC_lower_low = KC_basis - devKC * KC_mult_low
//SQUEEZE CONDITIONS
NoSqz = BB_lower < KC_lower_low or BB_upper > KC_upper_low //NO SQUEEZE: GREEN
LowSqz = BB_lower >= KC_lower_low or BB_upper <= KC_upper_low //LOW COMPRESSION: BLACK
MidSqz = BB_lower >= KC_lower_mid or BB_upper <= KC_upper_mid //MID COMPRESSION: RED
HighSqz = BB_lower >= KC_lower_high or BB_upper <= KC_upper_high //HIGH COMPRESSION: ORANGE
//MOMENTUM OSCILLATOR
mom = ta.linreg(close - math.avg(math.avg(ta.highest(high, length), ta.lowest(low, length)), ta.sma(close, length)), length, 0)
//MOMENTUM HISTOGRAM COLOR
iff_1 = mom > nz(mom[1]) ? color.new(color.aqua, 0) : color.new(#2962ff, 0)
iff_2 = mom < nz(mom[1]) ? color.new(color.red, 0) : color.new(color.yellow, 0)
mom_color = mom > 0 ? iff_1 : iff_2
// Bullsqueeze and Bearsqueeze Conditions
bullsqueeze = ((NoSqz and mom_color == color.new(color.aqua, 0)) or (mom_color == color.new(color.aqua, 0) and mom_color[1] == color.new(color.red, 0)))
bearsqueeze = ((NoSqz and mom_color == color.new(color.red, 0)) or (mom_color == color.new(color.red, 0) and mom_color[1] == color.new(color.aqua, 0)))
// BULL AND BEAR WATCH OUT Conditions
buyConf = (mom_color == color.new(color.aqua, 0) and mom_color[1] == color.new(color.yellow, 0)) and not bullsqueeze
sellConf = (mom_color == color.new(color.red, 0) and mom_color[1] == color.new(#2962ff, 0)) and not bearsqueeze
// User inputs for colors and widths related to the BAND
userColorBullish = input.color(color.rgb(247, 223, 2), "Bullish Band Color", group= "Customize BAND")
userColorBearish = input.color(color.black, "Bearish Band Color",group= "Customize BAND")
bandWidthMultiplier = input.float(2.0, "Band Width Multiplier", minval=1.0,group= "Customize BAND")
userWidth = input.int(2, "Band Width", minval=1,group= "Customize BAND")
// Adjusted band calculations
upperBand = high + (atr * bandWidthMultiplier)
lowerBand = low - (atr * bandWidthMultiplier)
// Initialize a color variable for the band
var color bandColor = na
// Initialize a variable to store the previous band color
var color prevBandColor = na
// Update the previous band color for the next bar
prevBandColor := bandColor[1]
// Create variables to store the previous squeeze state
var bool prevBullSqueeze = false
var bool prevBearSqueeze = false
// Update the previous squeeze state at the beginning of each new bar
if (barstate.isnew)
prevBullSqueeze := bandColor == color.new(userColorBullish, 0)
prevBearSqueeze := bandColor == color.new(userColorBearish, 100)
// Determine the band color based on custom conditions
if (bullsqueeze)
bandColor := color.new(userColorBullish, 0)
else if (bearsqueeze)
bandColor := color.new(userColorBearish, 100)
else if (sellConf and prevBullSqueeze)
bandColor := color.new(userColorBullish, 50)
else if (sellConf)
bandColor := color.new(userColorBearish, 100)
else if (buyConf and prevBearSqueeze)
bandColor := color.new(userColorBearish, 100)
else if (buyConf)
bandColor := color.new(userColorBullish, 50)
// Plot the bands and store the plot references
upperBandPlot = plot(upperBand, "H", color=bandColor, linewidth=userWidth)
lowerBandPlot = plot(lowerBand, "L", color=bandColor, linewidth=userWidth)
///////////////////////////////
//@version=5
dual_color=false
var bar_value= 1 //(1-16)
currentHigh = high
previousHigh = high[1]
currentClose = close
previousClose = close[1]
currentLow = low
previousLow = low[1]
//
condition1 = currentHigh > previousHigh and currentClose > previousClose and currentLow > previousLow
condition2 = currentHigh < previousHigh and currentClose > previousClose and currentLow > previousLow
condition3 = currentHigh > previousHigh and currentClose > previousClose and currentLow < previousLow
condition4 = currentHigh < previousHigh and currentClose > previousClose and currentLow < previousLow
//--------------------------------------------------------
condition5 = currentHigh > previousHigh and currentClose < previousClose and currentLow > previousLow
condition6 = currentHigh < previousHigh and currentClose < previousClose and currentLow > previousLow
condition7 = currentHigh > previousHigh and currentClose < previousClose and currentLow < previousLow
condition8 = currentHigh < previousHigh and currentClose < previousClose and currentLow < previousLow
open_up = close > open[1]
open_down = close < open[1]
switch
condition1 and open_up => bar_value:=16
condition1 and open_down => bar_value:=15
condition2 and open_up => bar_value:=14
condition2 and open_down => bar_value:=13
condition3 and open_up => bar_value:=12
condition3 and open_down => bar_value:=11
condition4 and open_up => bar_value:=10
condition4 and open_down => bar_value:=9
condition5 and open_up => bar_value:=8
condition5 and open_down => bar_value:=7
condition6 and open_up => bar_value:=6
condition6 and open_down => bar_value:=5
condition7 and open_up => bar_value:=4
condition7 and open_down => bar_value:=3
condition8 and open_up => bar_value:=2
condition8 and open_down => bar_value:=1
//plot(bar_value,display = display.none,title="Bar Value")
barcolor(condition1 and not dual_color ? color.rgb(247, 223, 2) : na, title="C+L+H+")
barcolor(condition2 and not dual_color ? color.rgb(247, 223, 2) : na, title="C+L+H-")
barcolor(condition3 and not dual_color ? color.rgb(247, 223, 2) : na, title="C+L-H+")
barcolor(condition4 and not dual_color ? color.rgb(252, 223, 2) : na, title="C+L-H-")
//--------------------------------------------------------------------------
barcolor(condition5 and not dual_color ? color.rgb(213, 4, 250) : na, title="C-L+H+")
barcolor(condition6 and not dual_color ? color.rgb(213, 4, 250) : na, title="C-L+H-")
barcolor(condition7 and not dual_color ? color.rgb(213, 4, 250) : na, title="C-L-H+")
barcolor(condition8 and not dual_color ? color.rgb(213, 4, 250) : na, title="C-L-H-")
///////////////////////
//@version=5
type bar
float o = open
float h = high
float l = low
float c = close
int i = bar_index
type trend
float h = na
float l = na
type scythe
polyline a = na
line b = na
type target
float u = na
float l = na
float p = na
int d = 0
bool r = false
line v = na
line h = na
label e = na
type alerts
bool u = na
bool d = na
bool b = na
bool s = na
type prompt
string s = ''
bool c = false
method notify(prompt p) =>
if p.c
alert(p.s, alert.freq_once_per_bar_close)
method any(alerts a) =>
string s = switch
a.s => 'Target Reached '
a.b => 'Target Invalidated'
a.u => 'Breakout '
a.d => 'Breakdown'
=> na
prompt.new(s, not na(s))
method atr(bar b, simple int len = 1) =>
float tr =
na(b.h[1]) ?
b.h - b.l :
math.max(
math.max(
b.h - b.l,
math.abs(b.h - b.c[1])),
math.abs (b.l - b.c[1]))
len == 1 ? tr : ta.rma(tr, len)
method piv(trend t) =>
bool b = switch
na(t.h) and na(t.l) => false
=> true
b
method blade(array<chart.point> a, bool p, simple color u, simple color d) =>
polyline.new(a, false, true, xloc.bar_index, p ? d : u, p ? color.new(d, 80) : color.new(u, 80))
method handle(bar b, trend t, float s) =>
line l = switch
not na(t.l) =>
line.new(b.i, b.h + s, b.i, b.l , xloc.bar_index, extend.none, #9c4b11, line.style_solid, 3)
not na(t.h) =>
line.new(b.i, b.h , b.i, b.l - s, xloc.bar_index, extend.none, #9c4b11, line.style_solid, 3)
l
method goal(target t, bar b, simple int len) =>
t.v := line .new(b.i, b.c, b.i , t.p, xloc.bar_index, extend.none, chart.fg_color, line.style_dashed)
t.h := line .new(b.i, t.p, b.i + len, t.p, xloc.bar_index, extend.none, chart.fg_color, line.style_dashed)
//t.e := label.new(b.i + len, t.p, "HEDEF", xloc.bar_index, yloc.price, #f0a71f78, label.style_label_left, chart.fg_color, size.normal)
method cu(target t, bar b) =>
t.l[1] < b.c[1] and t.l > b.c
method co(target t, bar b) =>
t.u[1] > b.c[1] and t.u < b.c
method cr(target t, bar b) =>
((t.d == 1 and b.c > t.p) or
(t.d == -1 and b.c < t.p))
method reached(target t, bar b) =>
t.h.set_xy2(b.i, t.h.get_y2())
t.e.set_xy (b.i, t.h.get_y2())
t.e.set_color(#4caf4f78)
t.e.set_text ('KAR-AL' )
method failed(target t, bar b) =>
t.h.set_xy2(b.i, t.h.get_y2())
t.e.set_xy (b.i, t.h.get_y2())
t.e.set_color(#a53a3a78)
t.e.set_text ('GEÇERSİZ' )
const string ts = 'Controls how restrained the target calculation is, higher values will result in tighter targets.'
const string tb = 'Adjusts the length of the scythes blade'
const string tp = 'Swing detection length'
const string gs = 'Scythes', const string gt = 'Targets', const string gu = 'UI Options'
len = input.int (20 , "Pivot Length" , 20, 100, 1 , tp, group = gs)
ext = input.int (40 , "Scythe Length" , 20, 200, 1 , tb, group = gs)
sen = input.int (50 , "Sensitivity %", 0 , 100, 10, ts, group = gt)
bts = input.bool (true , "Display" , group = gt)
bbs = input.bool (true , "Breakouts" , group = gu)
colu = input.color(#eee7df, "" , inline = '1', group = gu)
cold = input.color(#c71313, "" , inline = '1', group = gu)
bar b = bar .new( )
float s = b .atr( len) / len
trend t = trend.new(
ta.pivothigh(len, len),
ta.pivotlow (len, len))
var target g = target.new ()
var map<int, float> u = map .new<int, float>()
var map<int, float> l = map .new<int, float>()
if t.piv()
array<chart.point> a = array.new<chart.point>()
bar z = b[len]
bool p = na(t.l)
for i = 0 to ext - 1
float c = s * i + s * math.pow(i, 2) / ext
a.push(chart.point.from_index(z.i + i, (p ? (z.h - c) : (z.l + c))))
a.push(chart.point.from_index(z.i, (p ? (z.h - s * ext / 5) : (z.l + s * ext / 5))))
switch
not na(t.l) =>
l.clear()
for point in a
l.put(point.index, point.price)
not na(t.h) =>
u.clear()
for point in a
u.put(point.index, point.price)
scythe n = scythe.new(a.blade(p, colu, cold), z.handle(t, s * len))
g.u := u.contains(b.i) ? u.get(b.i) : na
g.l := l.contains(b.i) ? l.get(b.i) : na
bool ucon = false
bool dcon = false
bool bcon = false
bool scon = false
if g.cr(b) and not g.r and bts
g.reached(b)
g.r := true
scon := true
if g.co(b) and bts
if not g.r
g.failed(b)
bcon := true
else
ucon := true
g.r := false
g.d := 1
g.p := b.c + s * ext * (2 - sen / 100)
g.goal(b, len)
if g.cu(b) and bts
if not g.r
g.failed(b)
bcon := true
else
dcon := true
g.r := false
g.d := -1
g.p := b.c - s * ext * (2 - sen / 100)
g.goal(b, len)
alerts a = alerts.new(
ucon,
dcon,
bcon,
scon)
plotshape(not na(t.l) ? (b[len]).l + s * len / 5 : na, "ÇIPA", shape.diamond, location.absolute, colu, -len, size = size.normal)
plotshape(not na(t.h) ? (b[len]).h - s * len / 5 : na, "TIRPAN", shape.diamond, location.absolute, cold, -len, size = size.normal)
//plotshape(bbs and a.d, "KIRILIM", shape.labeldown, location.abovebar, color.new(cold, 60), 0, 'AK', chart.fg_color, size = size.normal)
//plotshape(bbs and a.u, "KIRILIM", shape.labelup , location.belowbar, color.new(colu, 60), 0, 'YK', chart.fg_color, size = size.normal)
//alertcondition(a.b, 'Target Reached ', 'Target Reached ')
//alertcondition(a.s, 'Target Invalidated', 'Target Invalidated')
//alertcondition(a.u, 'Breakout ' , 'Breakout ' )
//alertcondition(a.d, 'Breakdown' , 'Breakdown' )
a.any().notify()
///////////////////////////////
//@version=5
OPEN = request.security(syminfo.tickerid, '60', open)
//ADR L
dayrange = high - low
r1 = request.security(syminfo.tickerid, '60', dayrange[1])
r2 = request.security(syminfo.tickerid, '60', dayrange[2])
r3 = request.security(syminfo.tickerid, '60', dayrange[3])
r4 = request.security(syminfo.tickerid, '60', dayrange[4])
r5 = request.security(syminfo.tickerid, '60', dayrange[5])
r6 = request.security(syminfo.tickerid, '60', dayrange[6])
r7 = request.security(syminfo.tickerid, '60', dayrange[7])
r8 = request.security(syminfo.tickerid, '60', dayrange[8])
r9 = request.security(syminfo.tickerid, '60', dayrange[9])
r10 = request.security(syminfo.tickerid, '60', dayrange[10])
adr_10 = (r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9 + r10) / 10
adr_9 = (r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9) / 9
adr_8 = (r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8) / 8
adr_7 = (r1 + r2 + r3 + r4 + r5 + r6 + r7) / 7
adr_6 = (r1 + r2 + r3 + r4 + r5 + r6) / 6
adr_5 = (r1 + r2 + r3 + r4 + r5) / 5
adr_4 = (r1 + r2 + r3 + r4) / 4
adr_3 = (r1 + r2 + r3) / 3
adr_2 = (r1 + r2) / 2
adr_1 = r1
//plot
adrhigh10 = plot(OPEN + adr_10 / 2, title='HH', style=plot.style_linebr, color=color.new(#ff9900, 100), linewidth=1)
adrlow10 = plot(OPEN - adr_10 / 2, title='HL', style=plot.style_linebr, color=color.new(#ff9900, 100), linewidth=1)
////////////////////////
// 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/
// ~~ © Zeiierman {
//@version=5
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ ToolTips {
t1 = "Volatility Period defines the length of the look-back period for calculating volatility. Higher values make the bands adapt more slowly to volatility changes. Lower values make them adapt more quickly."
t2 = "Trend Factor adjusts the sensitivity of the trend line to price movements. A higher value makes the trend line less sensitive and smoother. Lower values make it more sensitive and reactive to price changes."
t3 = "Trend Step controls how quickly the trend line adjusts to sudden price changes. Higher values cause slower adjustments, leading to smoother trend lines. Lower values result in quicker adjustments to sudden changes."
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Inputs {
volatilityPeriod = input.int(100, title="Period", step=10, minval=2, maxval=1000, inline="vol", group="Volatility Settings", tooltip=t1)
trendFactor = input.float(9, step=0.1, title='Factor', minval = 0.1, inline="", group="Trend Settings", tooltip=t2)
trendStep = input.float(0.7, "Step", step=0.1,minval = 0.5, maxval = 5.0, inline="", group="Trend Settings", tooltip=t3)
color_trend = input.color(color.navy, title="Trend Line ", inline="trend", group="Style")
colorForUpperBand = input.color(color.new(#862458, 10), title="Upper Band", inline="band", group="Style")
colorForLowerBand = input.color(color.new(#493893, 10), title="Lower Band", inline="band", group="Style")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Initialize Variables
var float currentTrend = 0.0
var int trendDirection = 0
averageTrueRange = ta.atr(200)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Function to determine the trend direction
determineTrendDirection(direction) => direction - direction[1] > 0 ? 1 : (direction - direction[1] < 0 ? -1 : 0)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Calculate Trend Direction
closingPrice = close
scaledStandardDev = (nz(averageTrueRange) * trendFactor)
trendDirection := determineTrendDirection(currentTrend) * int(scaledStandardDev)
priceTrendDiff = closingPrice - currentTrend > 0 ? closingPrice - currentTrend : currentTrend - closingPrice
reciprocalFactor = (scaledStandardDev * (1 / trendFactor)) * 1 / math.pow(2, 100)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Calculate the Current Trend
trendAdjustment = priceTrendDiff > scaledStandardDev * trendStep ? math.avg(closingPrice, currentTrend) : trendDirection * reciprocalFactor + currentTrend
currentTrend := trendAdjustment
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Calculate Upper and Lower Bands
upperBand88 = currentTrend + scaledStandardDev - averageTrueRange - ta.ema(ta.stdev(closingPrice, volatilityPeriod), 200)
lowerBand88 = currentTrend - scaledStandardDev + averageTrueRange + ta.ema(ta.stdev(closingPrice, volatilityPeriod), 200)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Plot
isTrendConsistent = trendDirection == trendDirection[1]
colorForPlot = trendDirection == 1 ? color_trend : color_trend
plotTrend = plot(isTrendConsistent ? currentTrend : na, title="Trend ", color = color.new(na, 00))
plotUpper = plot(isTrendConsistent ? upperBand88 : na, title="Upper ", color = color.new(color.black, 00))
plotLower = plot(isTrendConsistent ? lowerBand88 : na, title="Lower ", color = color.new(color.black, 00))
fill(plotUpper, plotTrend, top_color = colorForLowerBand, bottom_color =color.new(na,100), top_value = upperBand88, bottom_value = currentTrend, title="Background Upper")
fill(plotTrend, plotLower, top_color = color.new(na,100), bottom_color = colorForUpperBand, top_value = currentTrend, bottom_value = lowerBand88, title="Background Lower")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
//@version=5
interval_to_len = timeframe.multiplier * (timeframe.isdaily ? 1440 : timeframe.isweekly ? 1440 * 7 : timeframe.ismonthly ? 1440 * 30 : 1)
ep_interval = 60 * input.int(5, minval=1, title='Extreme Point Interval (hours)')
len99 = input.int(5, minval=1, title='Length')
MA_type = input.string('Exponential', title='Moving Average Type', options=['Simple', 'Exponential', 'Smoothed'])
src = close
ep_len = math.ceil(ep_interval / interval_to_len)
_highest = ta.highest(high, ep_len)
_lowest = ta.lowest(low, ep_len)
MA = if MA_type == 'Simple'
ta.sma(src, len99)
else
if MA_type == 'Smoothed'
ta.rma(src, len99)
else
ta.ema(src, len99)
SR = src
trend = math.sign(nz(src[1]) - nz(SR[1]))
SR := nz(SR[1], SR) + trend * math.abs(nz(MA, src) - nz(MA[1], MA))
SR := src < SR and trend > 0 ? _highest : src > SR and trend < 0 ? _lowest : SR
trend := math.sign(src - SR)
plot(SR, color=trend != trend[1] ? na : trend > 0 ? #65D25BFF : #FE6B69FF,linewidth = 4, title='.')
////////////////////
//@version=5
// inputs
sdLength = input.int(3, title = 'Price-Action Length', minval = 2, maxval = 100)
labelType = input.string('Repaint', title = 'Label Type', options = ['Repaint', 'No-Repaint'])
candleType = input.string('Fill Only', title = 'Candle Color Type', options = ['Entire Candle', 'Fill Only'])
bullCSS = input.color(color.lime, title = 'Bull')
bearCSS = input.color(color.rgb(255, 0, 0), title = 'Bear')
neutCSS = input.color(color.yellow, title = 'Neutral')
useTrendTable = input.bool(true, title = 'Enabled', group = 'MTF Trend')
use_mtf1 = input.bool(true, title = 'MTF 1', group = 'MTF Trend', inline = '1')
mtf_1 = input.timeframe("1", title = '', group = 'MTF Trend', inline = '1')
use_mtf2 = input.bool(true, title = 'MTF 2', group = 'MTF Trend', inline = '2')
mtf_2 = input.timeframe("3", title = '', group = 'MTF Trend', inline = '2')
use_mtf3 = input.bool(true, title = 'MTF 3', group = 'MTF Trend', inline = '3')
mtf_3 = input.timeframe("5", title = '', group = 'MTF Trend', inline = '3')
use_mtf4 = input.bool(true, title = 'MTF 4', group = 'MTF Trend', inline = '4')
mtf_4 = input.timeframe("15", title = '', group = 'MTF Trend', inline = '4')
use_mtf5 = input.bool(true, title = 'MTF 5', group = 'MTF Trend', inline = '5')
mtf_5 = input.timeframe("60", title = '', group = 'MTF Trend', inline = '5')
// functions
f_getSwingValues(sdLength, offset) =>
sh = ta.pivothigh(high, sdLength, sdLength)
sl = ta.pivotlow(low, sdLength, sdLength)
csh = ta.valuewhen(not na(sh), high[sdLength], 0)
csl = ta.valuewhen(not na(sl), low[sdLength], 0)
psh = ta.valuewhen(not na(sh), high[sdLength], 1)
psl = ta.valuewhen(not na(sl), low[sdLength], 1)
hh = sh >= psh
lh = sh < psh
ll = sl <= psl
hl = sl > psl
var int trend = na
trend := ((hh and high >= psh) or close > csh) ? 1 : ((ll and low <= psl) or close < csl) ? -1 : lh or hl ? 0 : trend[1]
var int last_signal = na
last_signal := hh ? 2 : lh ? -1 : ll ? -2 : hl ? 1 : last_signal[1]
[sh[offset], sl[offset], psh[offset], psl[offset], csh[offset], csl[offset], hh[offset], lh[offset], ll[offset], hl[offset], trend[offset], last_signal[offset]]
// calculate chart tf
[sh, sl, psh, psl, csh, csl, hh, lh, ll, hl, trend45, last_signal] =
request.security(syminfo.tickerid, "", f_getSwingValues(sdLength, 0))
plotshape(ll and not na(sl), text="LL", title="Lower Low", style=shape.labelup, display = display.none,
color=bearCSS, textcolor=color.black, location=location.belowbar, offset = labelType == 'Repaint' ? -sdLength : 0)
plotshape(hl and not na(sl), text="HL", title="Higher Low", style=shape.labelup, display = display.none,
color=neutCSS, textcolor=color.black, location=location.belowbar, offset = labelType == 'Repaint' ? -sdLength : 0)
plotshape(hh and not na(sh), text="HH", title="Higher High", style=shape.labeldown, display = display.none,
color=bullCSS, textcolor=color.black, location=location.abovebar, offset = labelType == 'Repaint' ? -sdLength : 0)
plotshape(lh and not na(sh), text="LH", title="Lower High", style=shape.labeldown, display = display.none,
color=neutCSS, textcolor=color.black, location=location.abovebar, offset = labelType == 'Repaint' ? -sdLength : 0)
barCSS = trend45 == 1 ? bullCSS
: trend45 == -1 ? bearCSS
: neutCSS
barcolor(candleType != 'Fill Only' ? na
: barCSS, editable = false)
plotcandle(open, high, low, close, title = 'Price Action Candles',
color = barCSS, wickcolor = barCSS, bordercolor = barCSS,
display = candleType == 'Entire Candle' ? display.all : display.none, editable = false)
// calculate mtf
f_ltf_values(tf) =>
var int returnTrend = na
adjusted_timeframe = timeframe.in_seconds(tf) >= timeframe.in_seconds() ? '' : tf
[ltf_sh, ltf_sl, ltf_psh, ltf_psl, ltf_csh, ltf_csl, ltf_hh, ltf_lh, ltf_ll, ltf_hl, ltf_trend, ltf_last_signal] =
request.security_lower_tf(syminfo.tickerid, adjusted_timeframe, f_getSwingValues(sdLength, 0))
if array.size(ltf_trend) > 0
returnTrend := array.last(ltf_trend)
else
returnTrend := 0
returnTrend
f_htf_values(tf) =>
[htf_sh, htf_sl, htf_psh, htf_psl, htf_csh, htf_csl, htf_hh, htf_lh, htf_ll, htf_hl, htf_trend, htf_last_signal] =
request.security(syminfo.tickerid, tf, f_getSwingValues(sdLength, 1), lookahead = barmerge.lookahead_on)
htf_trend
f_sametf_values() =>
[sametf_sh, sametf_sl, sametf_psh, sametf_psl, sametf_csh, sametf_csl, sametf_hh, sametf_lh, sametf_ll, sametf_hl, sametf_trend, sametf_last_signal] =
f_getSwingValues(sdLength, 0)
sametf_trend
var int mtf1_trend = na
var int mtf2_trend = na
var int mtf3_trend = na
var int mtf4_trend = na
var int mtf5_trend = na
if barstate.islast
if use_mtf1
if timeframe.in_seconds() == timeframe.in_seconds(mtf_1)
mtf1_trend := f_sametf_values()
else if timeframe.in_seconds() > timeframe.in_seconds(mtf_1)
mtf1_trend := f_ltf_values(mtf_1)
else
mtf1_trend := f_htf_values(mtf_1)
if use_mtf2
if timeframe.in_seconds() == timeframe.in_seconds(mtf_2)
mtf2_trend := f_sametf_values()
else if timeframe.in_seconds() > timeframe.in_seconds(mtf_2)
mtf2_trend := f_ltf_values(mtf_2)
else
mtf2_trend := f_htf_values(mtf_2)
if use_mtf3
if timeframe.in_seconds() == timeframe.in_seconds(mtf_3)
mtf3_trend := f_sametf_values()
else if timeframe.in_seconds() > timeframe.in_seconds(mtf_3)
mtf3_trend := f_ltf_values(mtf_3)
else
mtf3_trend := f_htf_values(mtf_3)
if use_mtf4
if timeframe.in_seconds() == timeframe.in_seconds(mtf_4)
mtf4_trend := f_sametf_values()
else if timeframe.in_seconds() > timeframe.in_seconds(mtf_4)
mtf4_trend := f_ltf_values(mtf_4)
else
mtf4_trend := f_htf_values(mtf_4)
if use_mtf5
if timeframe.in_seconds() == timeframe.in_seconds(mtf_5)
mtf5_trend := f_sametf_values()
else if timeframe.in_seconds() > timeframe.in_seconds(mtf_5)
mtf5_trend := f_ltf_values(mtf_5)
else
mtf5_trend := f_htf_values(mtf_5)
// table
if barstate.islast and useTrendTable
var trendTable = table.new(position = position.bottom_right, columns = 5, rows = 1, border_width = 1, border_color = color.black, frame_width = 2, frame_color = color.black)
if use_mtf1
table.cell(trendTable, 0, 0, text = str.tostring(mtf_1), text_color = color.black,
bgcolor = color.new(mtf1_trend == 1 ? bullCSS : mtf1_trend == -1 ? bearCSS : neutCSS, 0))
if use_mtf2
table.cell(trendTable, 1, 0, text = str.tostring(mtf_2), text_color = color.black,
bgcolor = color.new(mtf2_trend == 1 ? bullCSS : mtf2_trend == -1 ? bearCSS : neutCSS, 0))
if use_mtf3
table.cell(trendTable, 2, 0, text = str.tostring(mtf_3), text_color = color.black,
bgcolor = color.new(mtf3_trend == 1 ? bullCSS : mtf3_trend == -1 ? bearCSS : neutCSS, 0))
if use_mtf4
table.cell(trendTable, 3, 0, text = str.tostring(mtf_4), text_color = color.black,
bgcolor = color.new(mtf4_trend == 1 ? bullCSS : mtf4_trend == -1 ? bearCSS : neutCSS, 0))
if use_mtf5
table.cell(trendTable, 4, 0, text = str.tostring(mtf_5), text_color = color.black,
bgcolor = color.new(mtf5_trend == 1 ? bullCSS : mtf5_trend == -1 ? bearCSS : neutCSS, 0))
/////////////////////////////////////////