yedeklemeler....
PHP Code:
// //////////////////////trend hesaplama kısmı////////////////////
//@version=5
indicator('Average Interpercentile Range AIR Supertrend','---', overlay=true, max_labels_count = 500, format=format.price)
// Moving Averages Types
var string SMA = 'Simple Moving Average'
var string EMA = 'Exponential Moving Average'
var string WMA = 'Weighted Moving Average'
var string VWMA = 'Volume Weighted Moving average'
var string ALMA = 'Arnaud Legoux Moving Average'
var string JURIK = 'Jurik Moving Average'
var string T3 = 'Tillson T3 Moving Average'
var string RSIMA = 'RSI Moving Average'
var string MEDIAN = 'Median'
var string SS = 'Super Smoother Moving Average'
var string HANN = 'Ehlers Hann Moving Average'
src = input.source(hl2, title = 'Source', inline = '1')
period = input.int(title = 'Length', defval = 5, inline = '1')
multiplier = input.float(title = 'Multiplier', step = 0.1, defval = 3.3, inline = '1')
var string GRP_RF = '══════ Range mix ══════'
atrActive = input.bool(true, 'ATR,', inline='42', group=GRP_RF)
atrMult = input.float(0.3, 'Mult', step=0.1, inline='42', group=GRP_RF)
atr_move = input.string(T3, 'MA', options=[SMA, EMA, WMA, VWMA, ALMA, JURIK, T3, RSIMA, MEDIAN, SS, HANN], group=GRP_RF, inline='42')
airActive = input.bool(true, 'AIR,', inline='44', group=GRP_RF)
airMult = input.float(0.6, 'Mult', step=0.1, inline='44', group=GRP_RF)
air_move = input.string(T3, 'MA', options=[SMA, EMA, WMA, VWMA, ALMA, JURIK, T3, RSIMA, MEDIAN, SS, HANN], group=GRP_RF, inline='44')
spacer = input.int(16, '%', inline='44', group=GRP_RF)
var string GRP_MA = 'Global MA Settings'
inputAlmaOffset_T = input.float(defval = 0.86, title = "Alma Offset", step = 0.01, inline = '1a', group = GRP_MA)
inputAlmaSigma_T = input.int(defval = 3, title = "... Sigma", inline = '1a', group = GRP_MA)
phase_T = input.int(defval = 2, title = "Jurik Phase", step = 1, inline = '1j', group = GRP_MA)
power_T = input.float(defval = 0.9, title = "... Power", step = 0.1, inline = '1j', group = GRP_MA)
fac_t3_T = input.float(0, step = 0.1, title = 'Tillson T3 Volume Factor', inline = '1t', group = GRP_MA)
var string GRP_UI = '══════ UI ══════'
up_ = input.color(#4caf50, '', inline = '2a', group = GRP_UI)
dn_ = input.color(#ff5252, '', inline = '2a', group = GRP_UI)
bkgrnd = input.bool(title = 'Fill On/Off ?', defval = true, inline='f', group = GRP_UI)
fader = input.int(75, 'Fade', inline = 'f', group = GRP_UI)
bar_it = input.bool(true, 'Color candles On/Off ?', inline = 'f1', group = GRP_UI)
fader_c = input.int(39, 'Fade', inline = 'f1', group = GRP_UI)
// ===========================================================================================================
// Functions
// ===========================================================================================================
// @function Jurik Moving Average - TradingView: Moving Averages
Jurik(src, simple int len, jurik_phase, jurik_power) =>
phaseRatio_l = jurik_phase < -100 ? 0.5 : jurik_phase > 100 ? 2.5 : jurik_phase / 100 + 1.5
beta_l = 0.45 * (len - 1) / (0.45 * (len - 1) + 2)
alpha_l = math.pow(beta_l, jurik_power)
jma_l = 0.0
e0_l = 0.0
e0_l := (1 - alpha_l) * src + alpha_l * nz(e0_l[1])
e1_l = 0.0
e1_l := (src - e0_l) * (1 - beta_l) + beta_l * nz(e1_l[1])
e2_l = 0.0
e2_l := (e0_l + phaseRatio_l * e1_l - nz(jma_l[1])) * math.pow(1 - alpha_l, 2) + math.pow(alpha_l, 2) * nz(e2_l[1])
jma_l := e2_l + nz(jma_l[1])
// @function T3 MA from Tilson3Average © KioseffTrading
t(src, x, a1_t3) =>
y1 = ta.ema(src,x)
y2 = ta.ema(y1, x)
y3 = ta.ema(y2, x)
y4 = ta.ema(y3, x)
y5 = ta.ema(y4, x)
y6 = ta.ema(y5, x)
v = -a1_t3 * math.pow(a1_t3,2)
v2 = 3 * math.pow(a1_t3,2) + 3 * math.pow(a1_t3,3)
v3 = -6 * math.pow(a1_t3, 2) - 3 * a1_t3 - 3 * math.pow(a1_t3, 3)
v4 = 1 + 3 * a1_t3 + a1_t3 * math.pow(a1_t3, 2) + 3 * math.pow(a1_t3, 2)
v1 = v * y6 + v2 * y5 + v3 * y4 + v4 * y3
v1
// Super Smoother Function
ss(Series, Period) => // Super Smoother Function
var PI = 2.0 * math.asin(1.0)
var SQRT2 = math.sqrt(2.0)
lambda = PI * SQRT2 / Period
a1 = math.exp(-lambda)
coeff2 = 2.0 * a1 * math.cos(lambda)
coeff3 = -math.pow(a1, 2.0)
coeff1 = 1.0 - coeff2 - coeff3
filt1 = 0.0
filt1 := coeff1 * (Series + nz(Series[1])) * 0.5 + coeff2 * nz(filt1[1]) + coeff3 * nz(filt1[2])
filt1
// Hann Window Smoothing – Credits to @cheatcountry
doHannWindow(float _series, float _hannWindowLength) =>
sum = 0.0, coef = 0.0
for i = 1 to _hannWindowLength
cosine = 1 - math.cos(2 * math.pi * i / (_hannWindowLength + 1))
sum := sum + (cosine * nz(_series[i - 1]))
coef := coef + cosine
h = coef != 0 ? sum / coef : 0
// Choose MA type
MA_Calc(_data, _len, MAOption) =>
value =
MAOption == SMA ? ta.sma(_data, _len) :
MAOption == EMA ? ta.ema(_data, _len) :
MAOption == WMA ? ta.wma(_data, _len) :
MAOption == VWMA ? ta.vwma(_data, _len) :
MAOption == ALMA ? ta.alma(_data, _len, inputAlmaOffset_T, inputAlmaSigma_T) :
MAOption == JURIK ? Jurik(_data, _len, phase_T, power_T) :
MAOption == T3 ? t(_data, _len, fac_t3_T) :
MAOption == RSIMA ? ta.rma(_data, _len) :
MAOption == MEDIAN ? ta.median(_data, _len) :
MAOption == SS ? ss(_data, _len) :
MAOption == HANN ? doHannWindow(_data, _len) :
na
ipr_array(len, dnny, uppy) =>
float[] hiArray = array.new_float (0)
float[] loArray = array.new_float (0)
float[] cmArray = array.new_float (0)
for i = 0 to len - 1
array.push (hiArray, high[i])
array.push (loArray, low[i])
array.push (cmArray, hlcc4[i])
hlArray = array.concat (hiArray, loArray)
hlcmArray = array.concat (hlArray, cmArray)
q1 = array.percentile_linear_interpolation (hlcmArray, dnny)
q3 = array.percentile_linear_interpolation (hlcmArray, uppy)
iqr = (q3 - q1) / 2
// =================================================================================================
// Calculations
// =================================================================================================
atrFactor = atrActive ? atrMult * MA_Calc(ta.tr(true), period, atr_move) : 0
airFactor = airActive ? airMult * MA_Calc(ipr_array(period, spacer, 100 - spacer), period, air_move) : 0
blender = nz(atrFactor) + nz(airFactor)
ipr_supertrend(source, len, multi) =>
up = source - multi * blender
up1 = nz(up[1], up)
up := close[1] > up1 ? math.max(up, up1) : up
dn = source + multi * blender
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? math.min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
[up, dn, trend]
[upper, lower, supertrend] = ipr_supertrend(src, period, multiplier)
// =================================================================================================
// Plots
// =================================================================================================
upPlot = plot(supertrend == 1 ? upper : na, title='+++', style=plot.style_linebr, linewidth=2, color=color.new(up_, 100))
buySignal = supertrend == 1 and supertrend[1] == -1
dnPlot = plot(supertrend == 1 ? na : lower, title='---', style=plot.style_linebr, linewidth=2, color=color.new(dn_, 100))
sellSignal = supertrend == -1 and supertrend[1] == 1
plotshape(buySignal ? upper : na, title='Uptrend Begins', location=location.absolute, style=shape.circle, size=size.small, color=color.new(up_, 0))
plotshape(sellSignal ? lower : na, title='Downtrend Begins', location=location.absolute, style=shape.circle, size=size.small, color=color.new(dn_, 0))
midPlot = plot(ohlc4, title = '', style = plot.style_circles, display = display.none)
//fill(midPlot, upPlot, title = 'Uptrend Fill', color = bkgrnd ? color.new(up_, fader) : na)
//fill(midPlot, dnPlot, title = 'Downtrend Fill', color = bkgrnd ? color.new(dn_, fader) : na)
color_b = supertrend == 1 ? up_ : dn_
barcolor(bar_it ? color.new(color_b, fader_c) : na)
// =================================================================================================
// Alerts
// =================================================================================================
alertcondition(buySignal, title='.Supertrend Buy 🟢', message='Supertrend Buy 🟢')
alertcondition(sellSignal, title='.Supertrend Sell 🔴', message='Supertrend Sell 🔴')
changeCond = supertrend != supertrend[1]
alertcondition(changeCond, title='Supertrend Direction Change 🟢/🔴', message='Supertrend has changed direction 🟢/🔴')
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length88 = input.int(200, 'Length', minval = 2)
mult88 = input.float(6., 'Factor', minval = 0, step = .5)
tf = input.timeframe('', 'Timeframe')
src88 = input(close, 'Source')
//-----------------------------------------------------------------------------}
//Function
//-----------------------------------------------------------------------------{
pred_ranges(length88, mult88)=>
var avg = src88
var hold_atr = 0.
atr = nz(ta.atr(length88)) * mult88
avg := src88 - avg > atr ? avg + atr :
avg - src88 > 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(length88, mult88))
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
plot_pru2 = plot(prR2, '+2', avg != avg[1] ? na : #fa071b00)
plot_pru1 = plot(prR1, '+1', avg != avg[1] ? na : #fa071b00)
plot_pravg = plot(avg , '0', avg != avg[1] ? na : #f3f706)
plot_prl1 = plot(prS1, '-1', avg != avg[1] ? na : #04f8cf00)
plot_prl2 = plot(prS2, '-2', avg != avg[1] ? na : #05fcd300)
//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))
//-----------------------------------------------------------------------------}
// Custom cosh function
cosh(float x) =>
(math.exp(x) + math.exp(-x)) / 2
// Custom acosh function
acosh(float x) =>
x < 1 ? na : math.log(x + math.sqrt(x * x - 1))
// Custom sinh function
sinh(float x) =>
(math.exp(x) - math.exp(-x)) / 2
// Custom asinh function
asinh(float x) =>
math.log(x + math.sqrt(x * x + 1))
// Custom inverse tangent function
atan(float x) =>
math.pi / 2 - math.atan(1 / x)
// Chebyshev Type I Moving Average
chebyshevI(float src, int len, float ripple) =>
a = 0.
b = 0.
g = 0.
chebyshev = 0.
a := cosh(1 / len * acosh(1 / (1 - ripple)))
b := sinh(1 / len * asinh(1 / ripple))
g := (a - b) / (a + b)
chebyshev := (1 - g) * src + g * nz(chebyshev[1])
chebyshev
bool_to_float(bool source) =>
source ? 1 : 0
ema(source)=>
var float ema = 0.0
var int count = 0
count := nz(count[1]) + 1
ema := (1.0 - 2.0 / (count + 1.0)) * nz(ema[1]) + 2.0 / (count + 1.0) * source
ema
atan2(y, x) =>
var float angle = 0.0
if x > 0
angle := math.atan(y / x)
else
if x < 0 and y >= 0
angle := math.atan(y / x) + math.pi
else
if x < 0 and y < 0
angle := math.atan(y / x) - math.pi
else
if x == 0 and y > 0
angle := math.pi / 2
else
if x == 0 and y < 0
angle := -math.pi / 2
angle
degrees(float source) =>
source * 180 / math.pi
tra()=>
atr = ema(ta.tr)
slope = (close - close[10]) / (atr * 10)
angle_rad = atan2(slope, 1)
degrees = degrees(angle_rad)
source = ta.sma((degrees > 0 ? high : low), 2)
mats(source, length) =>
smooth = 0.
higher_high = math.max(math.sign(ta.change(ta.highest(length))), 0)
lower_low = math.max(math.sign(ta.change(ta.lowest(length)) * -1), 0)
time_constant = math.pow(ta.sma(bool_to_float(higher_high or lower_low), length), 2)
smooth := nz(smooth[1] + time_constant * (source - smooth[1]), source)
wilders_period = length * 4 - 1
atr = math.abs(nz(smooth[1]) - smooth)
ma_atr = ta.ema(atr, wilders_period)
delta_fast_atr = ta.ema(ma_atr, wilders_period) * length * 0.4
result = 0.0
if smooth > nz(result[1])
if smooth - delta_fast_atr < result[1]
result := result[1]
else
result := smooth - delta_fast_atr
else
if smooth + delta_fast_atr > result[1]
result := result[1]
else
result := smooth + delta_fast_atr
// Return
result
length = input.int(30, "Length", 2)
up_color = input.color(color.rgb(2, 139, 250), "", inline = "color")
down_color = input.color(color.rgb(214, 4, 252), "", inline = "color")
enable_glow = input.bool(true, "Enable Glow", inline = "color")
mats = mats(tra(), length)
atr = ta.atr(length)
colour = ta.sma(close, 2) > mats ? up_color : down_color
atr_10 = ema(ta.tr) / 2
alpha = color.new(color.black, 100)
max = mats + atr_10
min = mats - atr_10
center = plot(mats, "!!!", colour, editable = true)
//plot(mats, "Moving Average Trend Sniper", color.new(colour, 70), 2, editable = true)
//plot(mats, "Moving Average Trend Sniper", color.new(colour, 80), 3, editable = true)
//plot(mats, "Moving Average Trend Sniper", color.new(colour, 90), 4, editable = true)
//top = plot(enable_glow ? max : na, "Moving Average Trend Sniper", alpha)
//bottom = plot(enable_glow ? min : na, "Moving Average Trend Sniper", alpha)
//fill(top, center, top_value = max, bottom_value = mats, bottom_color = color.new(colour, 75), top_color = alpha, editable = true)
//fill(center, bottom, top_value = mats, bottom_value = min, bottom_color = alpha, top_color = color.new(colour, 75), editable = true)
PHP Code:
//@version=5
indicator("Z-Score", overlay= true, scale=scale.none)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Tooltips ///
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
t1 = "Determines the Length of Z-Score Assessment. Defaults to a 75 lookback period"
t2 = "Determines the length of the SMA if the user selects Show SMA. Default is 75, but for a more responsive SMA you can reduce it to 14. Optional."
t3 = "Shows the probability zones in colour."
t4 = "Will Display a summarized Z-Table."
t5 = "Display's the SMA."
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// User Inputs ///
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
len = input.int(75, "Lookback Length", tooltip=t1)
smalen = input.int(75, "SMA Length", tooltip=t2)
probfill = input.bool(false, "Distribution Probaiblity Fills", tooltip=t3)
showztable = input.bool(true, "Show Z-Table", tooltip=t4)
showsma = input.bool(false, "Show SMA", tooltip=t5)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Z-Score/SMA Calculations ///
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
z = (close - ta.sma(close, len)) / ta.stdev(close, len)
cl_sma = ta.sma(close, len)
cl_sd = ta.stdev(close, len)
// SMA
var float z_sma = 0.0
if showsma
z_sma := ta.sma(z, smalen)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Colours ///
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
color red = color.red
color green = color.green
color orange = color.orange
color yellow = color.yellow
color labelcolor = color.new(color.white, 100)
color gray = color.new(color.gray, 25)
color white = color.white
// Colour for Probability Distribution
color greenfill = color.new(color.green, 75)
color yellowfill = color.new(color.yellow, 75)
color redfill = color.new(color.red, 75)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Logical Assessments ///
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool zero_one = z >= 0 and z < 1
bool one_two = z >= 1 and z < 2.01
bool two_three = z >= 2 and z < 3.01
bool three = z >= 3
bool zero = z >= 0.99 and z <= -0.99
bool neg_zero_one = z < 0 and z > -1
bool neg_one_two = z <= -1 and z > -2
bool neg_two_three = z <= -2 and z > -3
bool neg_three = z <= -3
falling = ta.falling(z_sma, 3)
rising = ta.rising(z_sma, 3)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Plots ///
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//color z_color_plot = z > 0 ? green : z <= 0 ? red : orange
plot(z, "Z-Score", color=z > 0 ? color.rgb(76, 175, 79, 100) : z <= 0 ? color.rgb(255, 82, 82, 100) : orange, style=plot.style_line)
//plot(z_sma, "Z-SMA", color=showsma ? white : labelcolor, linewidth=2)
neutral = 0
onesd = 1
twosd = 2
threesd = 3
neg_onesd = -1
neg_twosd = -2
neg_threesd = -3
//a = plot(neutral, color=greenfill)
//b = plot(onesd, color=yellowfill)
//c = plot(twosd, color=redfill)
//d = plot(threesd, color=redfill)
//e = plot(neg_onesd, color=greenfill)
//f = plot(neg_twosd, color=yellowfill)
//g = plot(neg_threesd, color=redfill)
//fill(a, b, color=probfill ? greenfill : na)
//fill(b, c, color=probfill ? yellowfill : na)
//fill(c, d, color=probfill ? redfill : na)
//fill(a, e, color=probfill ? greenfill : na)
//fill(e, f, color=probfill ? yellowfill : na)
//fill(f, g, color=probfill ? redfill : na)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Price Level Calculations ///
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
neutral_price = (cl_sma) + (0 * cl_sd)
onesd_price = (cl_sma) + (1 * cl_sd)
twosd_price = (cl_sma) + (2 * cl_sd)
threesd_price = (cl_sma) + (3 * cl_sd)
neg_onesd_price = (cl_sma) + (-1 * cl_sd)
neg_twosd_price = (cl_sma) + (-2 * cl_sd)
neg_threesd_price = (cl_sma) + (-3 * cl_sd)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Line Plots ///
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var label neutral_price_line = na
var label onesd_price_line = na
var label twosd_price_line = na
var label threesd_price_line = na
var label neg_onesd_price_line = na
var label neg_twosd_price_line = na
var label neg_threesd_price_line = na
if bar_index >= 75
label.delete(neutral_price_line)
label.delete(onesd_price_line)
label.delete(twosd_price_line)
label.delete(threesd_price_line)
label.delete(neg_onesd_price_line)
label.delete(neg_twosd_price_line)
label.delete(neg_threesd_price_line)
neutral_price_line := label.new(bar_index, y=neutral, text=str.tostring(math.round(neutral_price,2)), color=labelcolor, style=label.style_label_left, textcolor = color.white, size=size.normal, textalign = text.align_right)
onesd_price_line := label.new(bar_index - 5, onesd, str.tostring(math.round(onesd_price,2)), color=labelcolor, style=label.style_label_left, textcolor = color.white, size=size.normal, textalign = text.align_right)
twosd_price_line := label.new(bar_index - 5, twosd, str.tostring(math.round(twosd_price,2)), color=labelcolor, style=label.style_label_left, textcolor = color.white, size=size.normal, textalign = text.align_right)
threesd_price_line := label.new(bar_index - 5, threesd, str.tostring(math.round(threesd_price,2)), color=labelcolor, style=label.style_label_left, textcolor = color.white, size=size.normal, textalign = text.align_right)
neg_onesd_price_line := label.new(bar_index - 5, neg_onesd, str.tostring(math.round(neg_onesd_price,2)), color=labelcolor, style=label.style_label_left, textcolor = color.white, size=size.normal, textalign = text.align_right)
neg_twosd_price_line := label.new(bar_index - 5, neg_twosd, str.tostring(math.round(neg_twosd_price,2)), color=labelcolor, style=label.style_label_left, textcolor = color.white, size=size.normal, textalign = text.align_right)
neg_threesd_price_line := label.new(bar_index - 5, neg_threesd, str.tostring(math.round(neg_threesd_price,2)), color=labelcolor, style=label.style_label_left, textcolor = color.white, size=size.normal, textalign = text.align_right)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Z-Table ///
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var ztable = table.new(position.bottom_center, 10, 3, bgcolor = color.white)
if showztable
// Z-Score / Columns
table.cell(ztable, 1, 1, text="Z-Score:", bgcolor = color.white, text_color = color.black)
table.cell(ztable, 2, 1, text = "-3", bgcolor = neg_three ? gray : white, text_color=color.black)
table.cell(ztable, 3, 1, text="-2", bgcolor = neg_two_three ? gray : white, text_color = color.black)
table.cell(ztable, 4, 1, text="-1", bgcolor = neg_zero_one ? gray : white, text_color=color.black)
table.cell(ztable, 5, 1, text="0", bgcolor= zero ? gray : white, text_color=color.black)
table.cell(ztable, 6, 1, text="1", bgcolor=zero_one ? gray : white, text_color=color.black)
table.cell(ztable, 7, 1, text="2", bgcolor=two_three ? gray : white, text_color=color.black)
table.cell(ztable, 8, 1, text="3", bgcolor=three ? gray : white, text_color=color.black)
// Probability / Rows
table.cell(ztable, 1, 2, text="Probability:", bgcolor = color.white, text_color = color.black)
table.cell(ztable, 2, 2, text = "0.0013", bgcolor = red, text_color=color.black)
table.cell(ztable, 3, 2, text="0.0228", bgcolor = yellow, text_color = color.black)
table.cell(ztable, 4, 2, text="0.1600", bgcolor = green, text_color=color.black)
table.cell(ztable, 5, 2, text="0.5000", bgcolor=green, text_color=color.black)
table.cell(ztable, 6, 2, text="0.8500", bgcolor=green, text_color=color.black)
table.cell(ztable, 7, 2, text="0.9800", bgcolor=yellow, text_color=color.black)
table.cell(ztable, 8, 2, text="0.9998", bgcolor=red, text_color=color.black)
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("Predictive Ranges [LuxAlgo]", "***", overlay = true)
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length = 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(length, mult)=>
var avg = src
var hold_atr = 0.
atr = nz(ta.atr(length)) * 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(length, mult))
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
plot_pru2 = plot(prR2, '+2', avg != avg[1] ? na : #fa071b)
plot_pru1 = plot(prR1, '+1', avg != avg[1] ? na : #fa071b)
plot_pravg = plot(avg , '0', avg != avg[1] ? na : #f3f706)
plot_prl1 = plot(prS1, '-1', avg != avg[1] ? na : #04f8d0)
plot_prl2 = plot(prS2, '-2', avg != avg[1] ? na : #05fcd2)
//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))
//-----------------------------------------------------------------------------}
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Steversteves
//@version=5
indicator("Z-Score", overlay=true, max_labels_count = 500)
lengthInput = input.int(50, "Length", minval = 2)
// Calculating High Z Score
a = ta.sma(close, lengthInput)
b = ta.stdev(close, lengthInput)
c = (close - a) / b
// Highest and Lowest
highz = ta.highest(c, lengthInput)
lowz = ta.lowest(c, lengthInput)
// Condition Alerts
var wait = 0
wait := wait + 1
if (c <= lowz) and (wait > 30)
wait := 10
label.new(x=bar_index, y=high, text="sat", size = size.tiny, color=color.rgb(247, 7, 7))
alert("sat tepe "+syminfo.ticker, alert.freq_once_per_bar)
if (c >= highz) and (wait > 30)
wait := 10
label.new(x=bar_index, y=high, text="al", size = size.tiny, color=color.rgb(66, 248, 11))
alert("al ralli "+syminfo.ticker, alert.freq_once_per_bar)
// Colors
color bear = color.new(color.orange, 0)
color bull = color.new(color.lime, 0)
bool overbought = c >= 2
bool oversold = c <= -2
brcolor = overbought ? bear : oversold ? bull : na
//barcolor(brcolor)
//////////////////////////
Length22 = input(50)
stddevs = input(1.69)
src22 = close
basis = ta.ema(src22, Length22)
zscore = (src22-basis)/ta.stdev(src22, Length22)
diff = math.abs(src22 - basis)
absZscore = math.abs(zscore)
bounds = diff / absZscore * stddevs
upper = basis + bounds
lower = basis - bounds
zscoreColor = zscore > 0.0 ? zscore >= zscore[1] ? zscore >= stddevs ? color.blue : color.green : color.new(color.green, 70) : zscore <= zscore[1] ? zscore <= -stddevs ? color.blue : color.red : color.new(color.red, 70)
plot(ta.ema(upper, 5), title="Upper ", linewidth=2)
//plot(ta.ema(basis, 5), title="Median", color=color.new(color.white, 60), linewidth=2)
plot(ta.ema(lower, 5), title="Lower ", linewidth=2)
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © carefulCode53358
//@version=5
indicator("*", overlay = true, max_boxes_count=100,max_lines_count = 100, max_labels_count = 100, format=format.price)
// Custom cosh function
cosh(float x) =>
(math.exp(x) + math.exp(-x)) / 2
// Custom acosh function
acosh(float x) =>
x < 1 ? na : math.log(x + math.sqrt(x * x - 1))
// Custom sinh function
sinh(float x) =>
(math.exp(x) - math.exp(-x)) / 2
// Custom asinh function
asinh(float x) =>
math.log(x + math.sqrt(x * x + 1))
// Custom inverse tangent function
atan(float x) =>
math.pi / 2 - math.atan(1 / x)
// Chebyshev Type I Moving Average
chebyshevI(float src, int len, float ripple) =>
a = 0.
b = 0.
g = 0.
chebyshev = 0.
a := cosh(1 / len * acosh(1 / (1 - ripple)))
b := sinh(1 / len * asinh(1 / ripple))
g := (a - b) / (a + b)
chebyshev := (1 - g) * src + g * nz(chebyshev[1])
chebyshev
bool_to_float(bool source) =>
source ? 1 : 0
ema(source)=>
var float ema = 0.0
var int count = 0
count := nz(count[1]) + 1
ema := (1.0 - 2.0 / (count + 1.0)) * nz(ema[1]) + 2.0 / (count + 1.0) * source
ema
atan2(y, x) =>
var float angle = 0.0
if x > 0
angle := math.atan(y / x)
else
if x < 0 and y >= 0
angle := math.atan(y / x) + math.pi
else
if x < 0 and y < 0
angle := math.atan(y / x) - math.pi
else
if x == 0 and y > 0
angle := math.pi / 2
else
if x == 0 and y < 0
angle := -math.pi / 2
angle
degrees(float source) =>
source * 180 / math.pi
tra()=>
atr = ema(ta.tr)
slope = (close - close[10]) / (atr * 10)
angle_rad = atan2(slope, 1)
degrees = degrees(angle_rad)
source = ta.sma((degrees > 0 ? high : low), 2)
mats(source, length) =>
smooth = 0.
higher_high = math.max(math.sign(ta.change(ta.highest(length))), 0)
lower_low = math.max(math.sign(ta.change(ta.lowest(length)) * -1), 0)
time_constant = math.pow(ta.sma(bool_to_float(higher_high or lower_low), length), 2)
smooth := nz(smooth[1] + time_constant * (source - smooth[1]), source)
wilders_period = length * 4 - 1
atr = math.abs(nz(smooth[1]) - smooth)
ma_atr = ta.ema(atr, wilders_period)
delta_fast_atr = ta.ema(ma_atr, wilders_period) * length * 0.4
result = 0.0
if smooth > nz(result[1])
if smooth - delta_fast_atr < result[1]
result := result[1]
else
result := smooth - delta_fast_atr
else
if smooth + delta_fast_atr > result[1]
result := result[1]
else
result := smooth + delta_fast_atr
// Return
result
length20 = input.int(5, "Length", 1)
up_color = input.color(color.lime, "", inline = "color")
down_color = input.color(color.red, "", inline = "color")
enable_glow = input.bool(true, "Enable Glow", inline = "color")
mats20 = mats(tra(), length20)
atr20 = ta.atr(length20)
colour20 = ta.sma(close, 1) > mats20 ? up_color : down_color
atr_10 = ema(ta.tr) / 2
alpha = color.new(color.black, 100)
max20 = mats20 + atr_10
min20 = mats20 - atr_10
center20 = plot(mats20, "T0", colour20, style=plot.style_stepline, editable = true)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// User inputs
prd22 = input.int(defval=2, title=' Period for Pivot Points', minval=1, maxval=50)
max_num_of_pivots = input.int(defval=5, title=' Maximum Number of Pivots', minval=5, maxval=10)
max_lines = input.int(defval=1, title=' Maximum number of trend lines', minval=1, maxval=10)
show_lines = input.bool(defval=true, title=' Show trend lines')
show_pivots = input.bool(defval=true, title=' Show Pivot Points')
float ph = ta.pivothigh(high, prd22, prd22)
float pl = ta.pivotlow(low, prd22, prd22)
//plotshape(ph and show_pivots, style=shape.triangledown, location=location.abovebar, offset=-prd22, size=size.small)
//plotshape(pl and show_pivots, style=shape.triangleup, location=location.belowbar, offset=-prd22, size=size.small)
// Creating array of pivots
var pivots_high = array.new_float(0)
var pivots_low = array.new_float(0)
var high_ind = array.new_int(0)
var low_ind = array.new_int(0)
if ph
array.push(pivots_high, ph)
array.push(high_ind, bar_index - prd22)
if array.size(pivots_high) > max_num_of_pivots // limit the array size
array.shift(pivots_high)
array.shift(high_ind)
if pl
array.push(pivots_low, pl)
array.push(low_ind, bar_index - prd22)
if array.size(pivots_low) > max_num_of_pivots // limit the array size
array.shift(pivots_low)
array.shift(low_ind)
// Create arrays to store slopes and lines
var res_lines = array.new_line()
var res_slopes = array.new_float()
len_lines = array.size(res_lines)
if (len_lines >= 1)
for ind = 0 to len_lines - 1
to_delete = array.pop(res_lines)
array.pop(res_slopes)
line.delete(to_delete)
// line.set_extend(to_delete, extend=extend.none)
count_slope(ph1, ph2, pos1, pos2) => (ph2 - ph1) / (pos2 - pos1)
if array.size(pivots_high) == max_num_of_pivots
index_of_biggest_slope = 0
for ind1 = 0 to max_num_of_pivots - 2
for ind2 = ind1 + 1 to max_num_of_pivots - 1
p1 = array.get(pivots_high, ind1)
p2 = array.get(pivots_high, ind2)
pos1 = array.get(high_ind, ind1)
pos2 = array.get(high_ind, ind2)
k = count_slope(p1, p2, pos1, pos2)
b = p1 - k * pos1
// ok = k * bar_index + b > high
ok = true
// label.new(pos1, p1, str.tostring(ok))
for ind3 = ind2 to max_num_of_pivots - 1
p3 = array.get(pivots_high, ind3)
pos3 = array.get(high_ind, ind3)
if p3 > k * pos3 + b
ok := false
// label.new(pos3, p3, 'cross')
break
if ind2 - ind1 >= 1
for ind3 = ind1 + 1 to ind2 - 1
p3 = array.get(pivots_high, ind3)
pos3 = array.get(high_ind, ind3)
if p3 > k * pos3 + b
ok := false
// label.new(pos3, p3, 'cross')
break
for ind = 0 to prd22 - 1
if high[ind] * 0.996 > k * bar_index[ind] + b
ok := false
break
if ok //and not (high > k * bar_index + b) // 'and not' for the last line to check if the crosses the price action
if array.size(res_slopes) < max_lines // max_lines // for now only 1 lines is to be shown
line = line.new(pos1, p1, pos2, p2, extend=extend.right)
array.push(res_lines, line)
array.push(res_slopes, k)
else
max_slope = array.max(res_slopes)
max_slope_ind = array.indexof(res_slopes, max_slope)
if max_lines == 1
max_slope_ind := 0
if k < max_slope
line_to_delete = array.get(res_lines, max_slope_ind)
line.delete(line_to_delete)
new_line = line.new(pos1, p1, pos2, p2, extend=extend.right)
array.insert(res_lines, max_slope_ind, new_line)
array.insert(res_slopes, max_slope_ind, k)
array.remove(res_lines, max_slope_ind + 1)
array.remove(res_slopes, max_slope_ind + 1)
// label.new(pos1, p1, str.tostring(res_slopes))
// if barstate.islast
// label.new(bar_index, high, str.tostring(array.size(res_lines)))
if array.size(res_lines) >= 1 and barstate.islast
for ind=0 to array.size(res_lines) - 1
l = array.get(res_lines, ind)
s = array.get(res_slopes, ind)
x1 = line.get_x1(l)
x2 = line.get_x2(l)
prev_lable_ind = 0//x2 + prd - 5
for ind1=x2 to bar_index
p = line.get_price(l, ind1)
if (math.abs(p - high[bar_index - ind1]) < p * 0.005)
if ind1 - prev_lable_ind > 10 and ind1 - x2 >= prd22
//label.new(ind1, high[bar_index - ind1], text='S', style=label.style_label_down, color=color.red)
prev_lable_ind := ind1
if not show_lines
len_l = array.size(res_lines)
if (len_l >= 1)
for ind = 0 to len_l - 1
to_delete = array.pop(res_lines)
array.pop(res_slopes)
line.delete(to_delete)
var sup_lines = array.new_line()
var sup_slopes = array.new_float()
len_lines1 = array.size(sup_lines)
if (len_lines1 >= 1)
for ind = 0 to len_lines1 - 1
to_delete = array.pop(sup_lines)
array.pop(sup_slopes)
line.delete(to_delete)
if array.size(pivots_low) == max_num_of_pivots
for ind1 = 0 to max_num_of_pivots - 2
for ind2 = ind1 + 1 to max_num_of_pivots - 1
p1 = array.get(pivots_low, ind1)
p2 = array.get(pivots_low, ind2)
pos1 = array.get(low_ind, ind1)
pos2 = array.get(low_ind, ind2)
k = count_slope(p1, p2, pos1, pos2)
b = p1 - k * pos1
// check if pivot points in the future are lower than the line between two points
ok = true
for ind3 = ind2 to max_num_of_pivots - 1
p3 = array.get(pivots_low, ind3)
pos3 = array.get(low_ind, ind3)
if p3 < k * pos3 + b
ok := false
// label.new(pos3, p3, 'cross')
break
// check if pivot points in the middle of two points is lower
if ind2 - ind1 >= 1
for ind3 = ind1 + 1 to ind2 - 1
p3 = array.get(pivots_low, ind3)
pos3 = array.get(low_ind, ind3)
if p3 < k * pos3 + b
ok := false
// label.new(pos3, p3, 'cross')
break
for ind = 0 to prd22 - 2
if low[ind] * 1.008 < k * bar_index[ind] + b
ok := false
break
if ok //and not (low < k * bar_index + b) // 'and not' for the last line to check if the it crosses the price action
if array.size(sup_slopes) < max_lines // max_lines // for now only 1 lines is to be shown
line = line.new(pos1, p1, pos2, p2, extend=extend.right)
// label.new(pos1, p1, 'ok to print')
array.push(sup_lines, line)
array.push(sup_slopes, k)
else
max_slope = array.min(sup_slopes)
max_slope_ind = array.indexof(sup_slopes, max_slope)
if max_lines == 1
max_slope_ind := 0
if k > max_slope
line_to_delete = array.get(sup_lines, max_slope_ind)
line.delete(line_to_delete)
new_line = line.new(pos1, p1, pos2, p2, extend=extend.right)
array.insert(sup_lines, max_slope_ind, new_line)
array.insert(sup_slopes, max_slope_ind, k)
array.remove(sup_lines, max_slope_ind + 1)
array.remove(sup_slopes, max_slope_ind + 1)
// label.new(pos1, p1, str.tostring(sup_slopes))
if array.size(sup_lines) >= 1 and barstate.islast
for ind=0 to array.size(sup_lines) - 1
l = array.get(sup_lines, ind)
s = array.get(sup_slopes, ind)
x1 = line.get_x1(l)
x2 = line.get_x2(l)
prev_lable_ind = 0//x2 + prd - 5
for ind1=x2 to bar_index
p = line.get_price(l, ind1)
if (math.abs(p - low[bar_index - ind1]) < p * 0.005)
if ind1 - prev_lable_ind > 10 and ind1 - x2 >= prd22
//label.new(ind1, low[bar_index - ind1], text='A', style=label.style_label_up, color=color.green)
prev_lable_ind := ind1
if not show_lines
len_l = array.size(sup_lines)
if (len_l >= 1)
for ind = 0 to len_l - 1
to_delete = array.pop(sup_lines)
array.pop(sup_slopes)
line.delete(to_delete)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Settings
//-----------------------------------------------------------------------------{
length = 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(length, mult)=>
var avg = src
var hold_atr = 0.
atr = nz(ta.atr(length)) * 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(length, mult))
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
plot_pru2 = plot(prR2, '+RH2', avg != avg[1] ? na : #f2364600)
plot_pru1 = plot(prR1, '+RH1', avg != avg[1] ? na : #f2364600)
plot_pravg = plot(avg , 'RH0', avg != avg[1] ? na : #f3f70700)
plot_prl1 = plot(prS1, '-RH1', avg != avg[1] ? na : #08998100)
plot_prl2 = plot(prS2, '-RH2', avg != avg[1] ? na : #08998100)
//Fills
fill(plot_pru2, plot_pru1, avg != avg[1] ? na : color.new(#f23645,55))
fill(plot_prl1, plot_prl2, avg != avg[1] ? na : color.new(#089981, 55))
//-----------------------------------------------------------------------------}
//Settings
//-----------------------------------------------------------------------------{
length33 = input.int(70
, minval = 0)
extrapolate = input.int(10
, minval = 0)
degree = input.int(3, 'Polynomial Degree'
, minval = 0
, maxval = 8)
src33 = input(close)
lock = input(false, 'Lock Forecast')
//Style
up_css = input.color(#0cb51a, 'Upward Color'
, group = 'Style')
dn_css = input.color(#ff1100, 'Downward Color'
, group = 'Style')
ex_css = input.color(#ea00ff, 'Extrapolation Color'
, group = 'Style')
width = input(3, 'Width'
, group = 'Style')
//-----------------------------------------------------------------------------}
//Fill lines array
//-----------------------------------------------------------------------------{
var lines = array.new_line(0)
if barstate.isfirst
for i = -extrapolate to length33-1
array.push(lines, line.new(na, na, na, na))
//-----------------------------------------------------------------------------}
//Get design matrix & partially solve system
//-----------------------------------------------------------------------------{
n33 = bar_index
var design = matrix.new<float>(0, 0)
var response = matrix.new<float>(0, 0)
if barstate.isfirst
for i = 0 to degree
column = array.new_float(0)
for j = 0 to length33-1
array.push(column, math.pow(j,i))
matrix.add_col(design, i, column)
var a = matrix.inv(matrix.mult(matrix.transpose(design), design))
var b = matrix.mult(a, matrix.transpose(design))
//-----------------------------------------------------------------------------}
//Get response matrix and compute roling polynomial regression
//-----------------------------------------------------------------------------{
var pass = 1
var matrix<float> coefficients = na
var x = -extrapolate
var float forecast = na
if barstate.islast
if pass
prices = array.new_float(0)
for i = 0 to length33-1
array.push(prices, src33[i])
matrix.add_col(response, 0, prices)
coefficients := matrix.mult(b, response)
float y1 = na
idx = 0
for i = -extrapolate to length33-1
y2 = 0.
for j = 0 to degree
y2 += math.pow(i, j)*matrix.get(coefficients, j, 0)
if idx == 0
forecast := y2
//------------------------------------------------------------------
//Set lines
//------------------------------------------------------------------
css33 = y2 < y1 ? up_css : dn_css
get_line = array.get(lines, idx)
line.set_xy1(get_line, n33 - i + 1, y1)
line.set_xy2(get_line, n33 - i, y2)
line.set_color(get_line, i <= 0 ? ex_css : css33)
line.set_width(get_line, width)
y1 := y2
idx += 1
if lock
pass := 0
else
y2 = 0.
x -= 1
for j = 0 to degree
y2 += math.pow(x, j)*matrix.get(coefficients, j, 0)
forecast := y2
plot(pass == 0 ? forecast : na, 'Extrapolation'
, color = ex_css
, offset = extrapolate
, linewidth = width)
//-----------------------
PHP Code:
// //////////////////////trend hesaplama kısmı////////////////////
//@version=5
indicator('Average Interpercentile Range AIR Supertrend','---', overlay=true, format=format.price)
// Moving Averages Types
var string SMA = 'Simple Moving Average'
var string EMA = 'Exponential Moving Average'
var string WMA = 'Weighted Moving Average'
var string VWMA = 'Volume Weighted Moving average'
var string ALMA = 'Arnaud Legoux Moving Average'
var string JURIK = 'Jurik Moving Average'
var string T3 = 'Tillson T3 Moving Average'
var string RSIMA = 'RSI Moving Average'
var string MEDIAN = 'Median'
var string SS = 'Super Smoother Moving Average'
var string HANN = 'Ehlers Hann Moving Average'
src = input.source(hl2, title = 'Source', inline = '1')
period = input.int(title = 'Length', defval = 5, inline = '1')
multiplier = input.float(title = 'Multiplier', step = 0.1, defval = 3.3, inline = '1')
var string GRP_RF = '══════ Range mix ══════'
atrActive = input.bool(true, 'ATR,', inline='42', group=GRP_RF)
atrMult = input.float(0.3, 'Mult', step=0.1, inline='42', group=GRP_RF)
atr_move = input.string(T3, 'MA', options=[SMA, EMA, WMA, VWMA, ALMA, JURIK, T3, RSIMA, MEDIAN, SS, HANN], group=GRP_RF, inline='42')
airActive = input.bool(true, 'AIR,', inline='44', group=GRP_RF)
airMult = input.float(0.6, 'Mult', step=0.1, inline='44', group=GRP_RF)
air_move = input.string(T3, 'MA', options=[SMA, EMA, WMA, VWMA, ALMA, JURIK, T3, RSIMA, MEDIAN, SS, HANN], group=GRP_RF, inline='44')
spacer = input.int(16, '%', inline='44', group=GRP_RF)
var string GRP_MA = 'Global MA Settings'
inputAlmaOffset_T = input.float(defval = 0.86, title = "Alma Offset", step = 0.01, inline = '1a', group = GRP_MA)
inputAlmaSigma_T = input.int(defval = 3, title = "... Sigma", inline = '1a', group = GRP_MA)
phase_T = input.int(defval = 2, title = "Jurik Phase", step = 1, inline = '1j', group = GRP_MA)
power_T = input.float(defval = 0.9, title = "... Power", step = 0.1, inline = '1j', group = GRP_MA)
fac_t3_T = input.float(0, step = 0.1, title = 'Tillson T3 Volume Factor', inline = '1t', group = GRP_MA)
var string GRP_UI = '══════ UI ══════'
up_ = input.color(#4caf50, '', inline = '2a', group = GRP_UI)
dn_ = input.color(#ff5252, '', inline = '2a', group = GRP_UI)
bkgrnd = input.bool(title = 'Fill On/Off ?', defval = true, inline='f', group = GRP_UI)
fader = input.int(75, 'Fade', inline = 'f', group = GRP_UI)
bar_it = input.bool(true, 'Color candles On/Off ?', inline = 'f1', group = GRP_UI)
fader_c = input.int(39, 'Fade', inline = 'f1', group = GRP_UI)
// ===========================================================================================================
// Functions
// ===========================================================================================================
// @function Jurik Moving Average - TradingView: Moving Averages
Jurik(src, simple int len, jurik_phase, jurik_power) =>
phaseRatio_l = jurik_phase < -100 ? 0.5 : jurik_phase > 100 ? 2.5 : jurik_phase / 100 + 1.5
beta_l = 0.45 * (len - 1) / (0.45 * (len - 1) + 2)
alpha_l = math.pow(beta_l, jurik_power)
jma_l = 0.0
e0_l = 0.0
e0_l := (1 - alpha_l) * src + alpha_l * nz(e0_l[1])
e1_l = 0.0
e1_l := (src - e0_l) * (1 - beta_l) + beta_l * nz(e1_l[1])
e2_l = 0.0
e2_l := (e0_l + phaseRatio_l * e1_l - nz(jma_l[1])) * math.pow(1 - alpha_l, 2) + math.pow(alpha_l, 2) * nz(e2_l[1])
jma_l := e2_l + nz(jma_l[1])
// @function T3 MA from Tilson3Average © KioseffTrading
t(src, x, a1_t3) =>
y1 = ta.ema(src,x)
y2 = ta.ema(y1, x)
y3 = ta.ema(y2, x)
y4 = ta.ema(y3, x)
y5 = ta.ema(y4, x)
y6 = ta.ema(y5, x)
v = -a1_t3 * math.pow(a1_t3,2)
v2 = 3 * math.pow(a1_t3,2) + 3 * math.pow(a1_t3,3)
v3 = -6 * math.pow(a1_t3, 2) - 3 * a1_t3 - 3 * math.pow(a1_t3, 3)
v4 = 1 + 3 * a1_t3 + a1_t3 * math.pow(a1_t3, 2) + 3 * math.pow(a1_t3, 2)
v1 = v * y6 + v2 * y5 + v3 * y4 + v4 * y3
v1
// Super Smoother Function
ss(Series, Period) => // Super Smoother Function
var PI = 2.0 * math.asin(1.0)
var SQRT2 = math.sqrt(2.0)
lambda = PI * SQRT2 / Period
a1 = math.exp(-lambda)
coeff2 = 2.0 * a1 * math.cos(lambda)
coeff3 = -math.pow(a1, 2.0)
coeff1 = 1.0 - coeff2 - coeff3
filt1 = 0.0
filt1 := coeff1 * (Series + nz(Series[1])) * 0.5 + coeff2 * nz(filt1[1]) + coeff3 * nz(filt1[2])
filt1
// Hann Window Smoothing – Credits to @cheatcountry
doHannWindow(float _series, float _hannWindowLength) =>
sum = 0.0, coef = 0.0
for i = 1 to _hannWindowLength
cosine = 1 - math.cos(2 * math.pi * i / (_hannWindowLength + 1))
sum := sum + (cosine * nz(_series[i - 1]))
coef := coef + cosine
h = coef != 0 ? sum / coef : 0
// Choose MA type
MA_Calc(_data, _len, MAOption) =>
value =
MAOption == SMA ? ta.sma(_data, _len) :
MAOption == EMA ? ta.ema(_data, _len) :
MAOption == WMA ? ta.wma(_data, _len) :
MAOption == VWMA ? ta.vwma(_data, _len) :
MAOption == ALMA ? ta.alma(_data, _len, inputAlmaOffset_T, inputAlmaSigma_T) :
MAOption == JURIK ? Jurik(_data, _len, phase_T, power_T) :
MAOption == T3 ? t(_data, _len, fac_t3_T) :
MAOption == RSIMA ? ta.rma(_data, _len) :
MAOption == MEDIAN ? ta.median(_data, _len) :
MAOption == SS ? ss(_data, _len) :
MAOption == HANN ? doHannWindow(_data, _len) :
na
ipr_array(len, dnny, uppy) =>
float[] hiArray = array.new_float (0)
float[] loArray = array.new_float (0)
float[] cmArray = array.new_float (0)
for i = 0 to len - 1
array.push (hiArray, high[i])
array.push (loArray, low[i])
array.push (cmArray, hlcc4[i])
hlArray = array.concat (hiArray, loArray)
hlcmArray = array.concat (hlArray, cmArray)
q1 = array.percentile_linear_interpolation (hlcmArray, dnny)
q3 = array.percentile_linear_interpolation (hlcmArray, uppy)
iqr = (q3 - q1) / 2
// =================================================================================================
// Calculations
// =================================================================================================
atrFactor = atrActive ? atrMult * MA_Calc(ta.tr(true), period, atr_move) : 0
airFactor = airActive ? airMult * MA_Calc(ipr_array(period, spacer, 100 - spacer), period, air_move) : 0
blender = nz(atrFactor) + nz(airFactor)
ipr_supertrend(source, len, multi) =>
up = source - multi * blender
up1 = nz(up[1], up)
up := close[1] > up1 ? math.max(up, up1) : up
dn = source + multi * blender
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? math.min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
[up, dn, trend]
[upper, lower, supertrend] = ipr_supertrend(src, period, multiplier)
// =================================================================================================
// Plots
// =================================================================================================
upPlot = plot(supertrend == 1 ? upper : na, title='Uptrend', style=plot.style_linebr, linewidth=2, color=color.new(up_, 100))
buySignal = supertrend == 1 and supertrend[1] == -1
dnPlot = plot(supertrend == 1 ? na : lower, title='Downtrend', style=plot.style_linebr, linewidth=2, color=color.new(dn_, 100))
sellSignal = supertrend == -1 and supertrend[1] == 1
plotshape(buySignal ? upper : na, title='Uptrend Begins', location=location.absolute, style=shape.circle, size=size.small, color=color.new(up_, 0))
plotshape(sellSignal ? lower : na, title='Downtrend Begins', location=location.absolute, style=shape.circle, size=size.small, color=color.new(dn_, 0))
midPlot = plot(ohlc4, title = '', style = plot.style_circles, display = display.none)
//fill(midPlot, upPlot, title = 'Uptrend Fill', color = bkgrnd ? color.new(up_, fader) : na)
//fill(midPlot, dnPlot, title = 'Downtrend Fill', color = bkgrnd ? color.new(dn_, fader) : na)
color_b = supertrend == 1 ? up_ : dn_
barcolor(bar_it ? color.new(color_b, fader_c) : na)
// =================================================================================================
// Alerts
// =================================================================================================
alertcondition(buySignal, title='.Supertrend Buy 🟢', message='Supertrend Buy 🟢')
alertcondition(sellSignal, title='.Supertrend Sell 🔴', message='Supertrend Sell 🔴')
changeCond = supertrend != supertrend[1]
alertcondition(changeCond, title='Supertrend Direction Change 🟢/🔴', message='Supertrend has changed direction 🟢/🔴')
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Settings//////////////////////ma hesaplama kısmı///////////////////////
//-----------------------------------------------------------------------------{
length22 = input(100)
incr = input(10, "Increment")
fast = input(10)
src22 = input(close)
//-----------------------------------------------------------------------------}
//Calculations
//-----------------------------------------------------------------------------{
var ma22 = 0.
var fma = 0.
var alpha = 0.
var k = 1 / incr
upper22 = ta.highest(length22)
lower22 = ta.lowest(length22)
init_ma = ta.sma(src22, length22)
cross = ta.cross(src22,ma22)
alpha := cross ? 2 / (length22 + 1)
: src22 > ma22 and upper22 > upper22[1] ? alpha + k
: src22 < ma22 and lower22 < lower22[1] ? alpha + k
: alpha
ma22 := nz(ma22[1] + alpha[1] * (src22 - ma22[1]), init_ma)
fma := nz(cross ? math.avg(src22, fma[1])
: src22 > ma22 ? math.max(src22, fma[1]) + (src22 - fma[1]) / fast
: math.min(src22, fma[1]) + (src22 - fma[1]) / fast,src22)
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
css22 = fma > ma22 ? color.rgb(46, 245, 6) : color.red
plot122 = plot(ma22, "Stop", style=plot.style_circles, linewidth=2
, color = css22)
///////////////////////////////////////dinamik range hesaplama kısmı/////////////////////
string reversal_type = input.string(defval='ATR', options=['ATR', 'Traditional'], title='Reversal Type:', inline='rt')
float reversal_modifier = input.float(defval=14, title='', inline='rt')
float reversal_multiplier = input.float(defval=3, title='', inline='rt', tooltip='-The type of range to use for the width of the channel. \n-Price modifier or atr length parameter depending on type. \n-Multiplier to apply to range.')
string ALT_TF = input.string(defval='D', title='Timeframe:', inline='itf')
bool USE_ALT_TF = input.bool(defval=true, title='Use Alternative Timeframe?', inline='itf')
float expansion_rate = input.float(defval=0.25, title='Expansion Rate:', inline='er')
bool expand_range = input.bool(defval=true, title='Expand Range', inline='er', tooltip='Expand Channel by rate when price touches extremes.')
float atr_1 = ta.atr(math.max(1, math.round(reversal_modifier)))
float reversal_block =
switch (reversal_type)
('ATR') => reversal_multiplier * atr_1
('Traditional') => reversal_multiplier * reversal_modifier
=> 0.0
bot_function() =>
float _bot_base = high - reversal_block
float _previous = nz(_bot_base[1], _bot_base)
if _previous + reversal_block < high
_bot_base := high - reversal_block
else if low < _previous
if expand_range
_bot_base := low - reversal_block * expansion_rate
else
_bot_base := low
else
_bot_base := _previous
top_function() =>
float _top_base = low + reversal_block
float _previous = nz(_top_base[1], _top_base)
if _previous - reversal_block > low
_top_base := low + reversal_block
else if high > _previous
if expand_range
_top_base := high + reversal_block * expansion_rate
else
_top_base := high
else
_top_base := _previous
bot_function_1 = bot_function()
security_1 = request.security(syminfo.tickerid, ALT_TF, bot_function_1)
bot_function_2 = bot_function()
bot = USE_ALT_TF ? security_1 : bot_function_2
top_function_1 = top_function()
security_2 = request.security(syminfo.tickerid, ALT_TF, top_function_1)
top_function_2 = top_function()
top = USE_ALT_TF ? security_2 : top_function_2
top_f = ta.change(bot) < 0 or ta.change(top) < 0 ? top : na
bot_f = ta.change(bot) < 0 or ta.change(top) < 0 ? bot : na
top_r = ta.change(bot) > 0 or ta.change(top) > 0 ? top : na
bot_r = ta.change(bot) > 0 or ta.change(top) > 0 ? bot : na
top_border = top - (top - bot) * 0.25
bot_border = bot + (top - bot) * 0.25
mid_border = bot + (top - bot) * 0.50
p_top_f = plot(series=top_f, title='0', color=color.new(color.lime, 0), style=plot.style_linebr)
//p_bot_f = plot(series=bot_f, title='tf', color=color.new(color.lime, 0), style=plot.style_linebr)
p_top_r = plot(series=top_r, title='1', color=color.new(color.red, 0), style=plot.style_linebr)
//p_bot_r = plot(series=bot_r, title='tr', color=color.new(color.red, 0), style=plot.style_linebr)
//fill(p_top_f, p_bot_f, color.new(color.lime, 90), title='direction fill')
//fill(p_top_r, p_bot_r, color.new(color.red, 90), title='direction fill')
plot(title='0', series=bot, color=color.new(color.lime, 0))
plot(title='1', series=top, color=color.new(color.red, 0))
plot(title='1', series=top_border, style=plot.style_circles, color=color.new(color.red, 0))
plot(title='0', series=bot_border, style=plot.style_circles, color=color.new(color.lime, 0))
plot(title='01', series=mid_border, style=plot.style_circles, color=color.new(#537cee, 0))
///////////////////////////////
//------------------------------------------------------------------------------
//Tooltips
//-----------------------------------------------------------------------------{
widthTooltip = "Bin width percentage. Determine the length of the returned profile bin as a percentage of the Length setting"
offsetTooltip = "Determine the amount of bars each graphical elements are shifted by"
//-----------------------------------------------------------------------------}
//Settings
//-----------------------------------------------------------------------------{
length69 = input.int(200, minval = 2)
rows = input.int(2, minval = 2)
useIb = input(false, 'Use Intrabar', inline = 'intrabar')
tf = input.timeframe('1', '' , inline = 'intrabar')
//Style
width69 = input.float(10, 'Width %', minval = 0, maxval = 100, group = 'Style', tooltip = widthTooltip)
showRange = input(false, 'Show Range Levels', inline = 'range', group = 'Style')
rangeCss = input(color.gray, '' , inline = 'range', group = 'Style')
bullBin = input(#f321f3, 'Bullish Bin', inline = 'bull', group = 'Style')
bullMax = input(true, 'Maximum' , inline = 'bull', group = 'Style')
bearBin = input(#fbff00, 'Bearish Bin', inline = 'bear', group = 'Style')
bearMax = input(true, 'Minimum' , inline = 'bear', group = 'Style')
showFill = input(false, 'Show Fill' , inline = 'fill', group = 'Style')
bullFill = input(color.new(#2157f3, 90), '' , inline = 'fill', group = 'Style')
bearFill = input(color.new(#ff5d00, 90), '' , inline = 'fill', group = 'Style')
offset = input.int(8, group = 'Style', tooltip = offsetTooltip)
//-----------------------------------------------------------------------------}
//Function
//-----------------------------------------------------------------------------{
get_data() => [close, open]
//-----------------------------------------------------------------------------}
//Main variables
//-----------------------------------------------------------------------------{
var boxes69 = array.new<box>(0)
//Populate bins array
if barstate.isfirst
for i = 0 to rows-1
boxes69.push(box.new(na,na,na,na,na
, text_valign = text.align_center
, text_color = color.white))
n69 = bar_index
upper69 = ta.highest(length69)
lower69 = ta.lowest(length69)
sumad = math.sum(math.abs(close - open), length69)
//Get intrabar data
[get_close, get_open] = request.security_lower_tf(syminfo.tickerid, tf, get_data())
//-----------------------------------------------------------------------------}
//Set profile
//-----------------------------------------------------------------------------{
//Range levels
var ltop = line.new(na,na,na,na, color = rangeCss)
var l75 = line.new(na,na,na,na, color = rangeCss, style = line.style_dashed)
var l50 = line.new(na,na,na,na, color = rangeCss)
var l25 = line.new(na,na,na,na, color = rangeCss, style = line.style_dashed)
var lbtm = line.new(na,na,na,na, color = rangeCss)
var fill = linefill.new(ltop, lbtm, na)
//Max / Min levels
var bull_max = line.new(na,na,na,na, color = bullBin)
var bear_min = line.new(na,na,na,na, color = bearBin)
//Set profile
if barstate.islast
avg = math.avg(upper69, lower69)
avg75 = math.avg(upper69, avg)
avg25 = math.avg(lower69, avg)
//Set lines coordinates
ltop.set_xy1(n69 - length69, upper69), ltop.set_xy2(n69 + offset, upper69)
lbtm.set_xy1(n69 - length69, lower69), lbtm.set_xy2(n69 + offset, lower69)
//Display range levels
if showRange
l75.set_xy1(n69 - length69, avg75) , l75.set_xy2(n69 + offset, avg75)
l50.set_xy1(n69 - length69, avg) , l50.set_xy2(n69 + offset, avg)
l25.set_xy1(n69 - length69, avg25) , l25.set_xy2(n69 + offset, avg25)
else
ltop.set_color(na)
lbtm.set_color(na)
//Get bullish/absolute delta sums for each row
up69 = upper69
dn69 = upper69
sums = array.new_float(0)
sums_abs = array.new_float(0)
//Loop trough each rows
for i = 0 to rows-1
dn69 -= (upper69 - lower69) / rows
sum = 0.
den = 0.
//Loop trough most recent bars
for j = 0 to length69-1
if useIb //Loop trough intrabar prices
for k = 0 to (get_close[j]).size()-1
c = (get_close[j]).get(k)
o = (get_open[j]).get(k)
sum += math.max(c, o) <= up69 and math.min(c, o) >= dn69 ? c - o : 0
else
sum += high[j] > dn69 and low[j] < up69 ? close[j] - open[j] : 0
sums.push(sum)
sums_abs.push(math.abs(sum))
up69 := dn69
//Set profile bins
max = sums_abs.max()
up69 := upper69
dn69 := upper69
for [index, element] in sums
dn69 -= (upper69 - lower69) / rows
x2 = n69 + int(element / max * length69 * (width69 / 100))
css = element > 0 ? color.new(bullBin, 50) : color.new(bearBin, 50)
//Set box coordinates
get_bx = boxes69.get(index)
get_bx.set_lefttop(n69 + offset, .9 * up69 + .1 * dn69)
get_bx.set_rightbottom(x2 + offset, .9 * dn69 + .1 * up69)
get_bx.set_bgcolor(css)
get_bx.set_text(str.tostring(element / sumad * 100, format.percent))
//Set area MAX/MIN levels
if element == sums.max() and bullMax
bull_max_val = math.avg(up69, dn69)
bull_max.set_xy1(n69 + offset, bull_max_val)
bull_max.set_xy2(n69 - length69, bull_max_val)
if element == sums.min() and bearMax
bear_min_val = math.avg(up69, dn69)
bear_min.set_xy1(x2 + offset, bear_min_val)
bear_min.set_xy2(n69 - length69, bear_min_val)
up69 := dn69
//Fill Area
if showFill
fill.set_color(sums.sum() > 0 ? color.new(bullBin, 90) : color.new(bearBin, 90))
//-----------------------------------------------------------------------------}
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("Predictive Ranges [LuxAlgo]", "*", overlay = true,max_boxes_count = 500, max_lines_count = 500, max_bars_back = 500)
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length = input.int(200, 'Length', minval = 2)
mult55 = input.float(6., 'Factor', minval = 0, step = .5)
tf = input.timeframe('', 'Timeframe')
src = input(close, 'Source')
//-----------------------------------------------------------------------------}
//Function
//-----------------------------------------------------------------------------{
pred_ranges(length, mult55)=>
var avg = src
var hold_atr = 0.
atr = nz(ta.atr(length)) * mult55
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(length, mult55))
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
plot_pru2 = plot(prR2, 'Direnç2', avg != avg[1] ? na : #f2364600)
plot_pru1 = plot(prR1, 'Direnç1', avg != avg[1] ? na : #f2364600)
plot_pravg = plot(avg , 'Ortalama', avg != avg[1] ? na : #f1ce0b)
plot_prl1 = plot(prS1, 'Destek1', avg != avg[1] ? na : #08998100)
plot_prl2 = plot(prS2, 'Destek2', avg != avg[1] ? na : #08998100)
//Fills
fill(plot_pru2, plot_pru1, avg != avg[1] ? na : color.new(#f23645, 65))
fill(plot_prl1, plot_prl2, avg != avg[1] ? na : color.new(#089981, 65))
//-----------------------------------------------------------------------------}
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length11 = input(20)
src11 = input(close)
//------------------------------------------------------------------------------
//Signal moving average
//-----------------------------------------------------------------------------{
var ma = 0.
var os = 0.
target = ta.sma(src11, length11)
abs_diff = math.abs(target - target[1])
r2 = math.pow(ta.correlation(close, bar_index, length11), 2)
os := r2 > 0.5 ? math.sign(src11[1] - target[1]) : os
ma := r2 > 0.5 ? r2 * target + (1 - r2) * nz(ma[1], target)
: ma[1] - abs_diff * os
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
plot0 = plot(src11, display = display.none, editable = false)
css = os == 1 ? #0cb51a : #ff1100
plot1 = plot(ma, 'MA0'
, css)
fill_css = src > ma ? color.new(#0cb51a, 80) : color.new(#ff1100, 80)
//fill(plot0, plot1, fill_css, 'Fill')
//-----------------------------------------------------------------------------}
//Settings
//-----------------------------------------------------------------------------{
length22 = input(100)
incr = input(10, "Increment")
fast = input(10)
src22 = input(close)
//-----------------------------------------------------------------------------}
//Calculations
//-----------------------------------------------------------------------------{
var ma22 = 0.
var fma = 0.
var alpha = 0.
var k = 1 / incr
upper = ta.highest(length22)
lower = ta.lowest(length22)
init_ma = ta.sma(src22, length22)
cross = ta.cross(src22,ma22)
alpha := cross ? 2 / (length + 1)
: src22 > ma22 and upper > upper[1] ? alpha + k
: src22 < ma22 and lower < lower[1] ? alpha + k
: alpha
ma22 := nz(ma22[1] + alpha[1] * (src22 - ma22[1]), init_ma)
fma := nz(cross ? math.avg(src22, fma[1])
: src22 > ma22 ? math.max(src22, fma[1]) + (src22 - fma[1]) / fast
: math.min(src22, fma[1]) + (src22 - fma[1]) / fast,src22)
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
css22 = fma > ma22 ? color.rgb(46, 245, 6) : color.red
plot122 = plot(ma22, "MA1"
, color = css22)
//-----------------------------------------------------------------------------}
Yer İmleri