DZS 2
DZS 2
0 at
https://mozilla.org/MPL/2.0/
// © nucapadvisoryservices
//@version=5
indicator(title = "NU Code - Dynamic Zones (April 2023)", shorttitle = "DZS 2",
overlay = true, precision = 2, max_bars_back = 500)
S = allslopes(len, src)
if method == 'Random'
S := rndslopes(S, numpairs)
S
mslope = array.median(S)
I = intercepts(src, len, mslope)
minter = array.median(I)
// apply estimator
x = bar_index
x1 = x - len
x2 = x
y1 = minter
y2 = minter + mslope * (len - 1)
//estimate prediction interval (as \pm mult*RMSD)
float rmse = 0.0
if len > 0
for j = 0 to len - 1 by 1
rmse += math.pow(src[j] - (minter + mslope * (len - j)), 2) / len
rmse
dev = mult * math.sqrt(rmse)
// plot results
line a1 = line.new(x1, y1, x2, y2, xloc.bar_index, extend=extendln ? extend.right :
extend.none, color=isbroken ? colbr : mslope > 0 ? colup : coldw, width=lw)
line.delete(a1[1])
if showinterval
line ap = line.new(x1, y1 + dev, x2, y2 + dev, xloc.bar_index,
extend=extendln ? extend.right : extend.none, color=isbroken ? colbr : mslope > 0 ?
colup : coldw, width=1, style=line.style_dashed)
line am = line.new(x1, y1 - dev, x2, y2 - dev, xloc.bar_index,
extend=extendln ? extend.right : extend.none, color=isbroken ? colbr : mslope > 0 ?
colup : coldw, width=1, style=line.style_dashed)
line.delete(ap[1])
line.delete(am[1])
if showresult and barstate.islast
label b = label.new(bar_index - (len - 1), mslope > 0 ? y1 - dev : y1 + dev,
style=mslope > 0 ? label.style_label_up : label.style_label_down, text=' Intercept
' + str.tostring(truncate(minter, 2)), color=mslope > 0 ? colup : coldw,
textcolor=color.new(color.white,0))
label.delete(b[1])
// End
// Resolution Inputs
CurrentRes_DZ = input(false, title='Use Current Chart Resolution?', group =
"Dynamic Zone Settings")
CustomRes_DZ = input.timeframe('15', title='Custom Timeframe?', group = "Dynamic
Zone Settings")
// Calculation
res_DZ = CurrentRes_DZ ? timeframe.period : CustomRes_DZ
oscSrc = request.security(syminfo.tickerid, res_DZ, oscSrc_DZ)
smplAbove = ta.percentile_nearest_rank(oscSrc, dataSmple, pcntAbove)
smplBelow = ta.percentile_nearest_rank(oscSrc, dataSmple, 100 - pcntBelow)
smplMid = (smplAbove + smplBelow) / 2
oscRange = ta.highest(oscSrc, dataSmple) - ta.lowest(oscSrc, dataSmple)
rangeWidthPct = (smplAbove - smplBelow) / oscRange * 100
//@version=5
//indicator("EMA Suite", overlay=true)
// EMA Suite
source = input(close, "EMA Source", group="EMA Inputs")
ema_short_len = input.int(9, minval=1, title='Short EMA Length', group="EMA
Inputs")
ema_long_len = input.int(21, minval=1, title='Long EMA Length', group="EMA Inputs")
ema_longest_len = input.int(72, title = "Longest EMA Length", group = "EMA Inputs")
// Resolution Inputs
CurrentRes_EMA = input(false, title='Use Current Chart Resolution?', group = "EMA
Inputs")
CustomRes_EMA = input.timeframe('15', title='Custom Timeframe?', group = "EMA
Inputs")
// End
tf_1H = input.timeframe('180', title='For 1-hour chart, show EMA of: ', group =
"Alt EMA Inputs")
tf_15 = input.timeframe('60', title='For 15-min chart, show EMA of: ', group = "Alt
EMA Inputs")
tf_5 = input.timeframe('15', title='For 5-min chart, show EMA of: ', group = "Alt
EMA Inputs")
tf_default = input.timeframe("", title='For others (Default)', group = "Alt EMA
Inputs")
tf = timeframe.period
// tf = timeframe of the viewed chart
tf_alt = tf == '60' ? tf_1H : tf == '45' ? tf_15 : tf == '5' ? tf_5 :
tf_default // alternative timeframe depends on 'tf'
// End
// Calulations
sma = ta.sma(calc_src, len_TMA)
sum = 0.0
for i = 0 to len_TMA - 1 by 1
sum += sma[i]
sum
a = sum / len_TMA
b = a[s]
atx = ta.atr(13)
factor = atx * fact
TMA_High = b + factor
TMA_Low = b - factor
// End
// Plot Options
plotBull = input(title="Plot Bullish", defval=true)
plotHiddenBull = input(title="Plot Hidden Bullish", defval=true)
plotBear = input(title="Plot Bearish", defval=true)
plotHiddenBear = input(title="Plot Hidden Bearish", defval=true)
// Color Scheme
bearColor = color.red
bullColor = color.green
hiddenBullColor = color.new(color.green, 30)
hiddenBearColor = color.new(color.red, 30)
textColor = color.white
noneColor = color.new(color.white, 100)
// MFI Inputs
mfi_src = input.source(defval = hlc3, title = "Source", group = "MFI Inputs")
length = input(title='Length', defval=14, group = "MFI Inputs")
// MFI Calculation
rawMoneyFlow = request.security(syminfo.tickerid, res, mfi_src) * volume
positiveMoneyFlow() =>
a_pos = 0.0
a_pos := mfi_src > mfi_src[1] ? a_pos + rawMoneyFlow : a_pos
a_pos
negativeMoneyFlow() =>
b_neg = 0.0
b_neg := mfi_src < mfi_src[1] ? b_neg + rawMoneyFlow : b_neg
b_neg
//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low
plotshape(
show_RSI_MFI_Signals and bullCond ? moneyFlowIndex[lbR] : na,
offset=-lbR,
title="Regular MFI Bullish Label",
text=" Bull MFI ",
style=shape.labelup,
location=location.belowbar,
color=bullColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low
plotshape(
show_RSI_MFI_Signals and hiddenBullCond ? moneyFlowIndex[lbR] : na,
offset=-lbR,
title="Hidden MFI Bullish Label",
text=" H Bull MFI ",
style=shape.labelup,
location=location.belowbar,
color=bullColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High
plotshape(
show_RSI_MFI_Signals and bearCond ? moneyFlowIndex[lbR] : na,
offset=-lbR,
title="Regular MFI Bearish Label",
text=" Bear MFI ",
style=shape.labeldown,
location=location.abovebar,
color=bearColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High
plotshape(
show_RSI_MFI_Signals and hiddenBearCond ? moneyFlowIndex[lbR] : na,
offset=-lbR,
title="Hidden MFI Bearish Label",
text=" H Bear MFI ",
style=shape.labeldown,
location=location.abovebar,
color=bearColor,
textcolor=textColor
)
// End
//RSI Inputs
// RSI Calculations
src_RSI = request.security(syminfo.tickerid, res, RSI_src)
rsi = ta.wma(ta.rsi(src_RSI, len_RSI), 5)
//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low
plotshape(
show_RSI_MFI_Signals and bullCond ? rsi[lbR] : na,
offset=-lbR,
title="Regular Bullish Label RSI",
text=" Bull RSI ",
style=shape.labelup,
location=location.belowbar,
color=bullColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low
plotshape(
show_RSI_MFI_Signals and hiddenBullCond_RSI ? rsi[lbR] : na,
offset=-lbR,
title="Hidden Bullish Label RSI",
text=" H Bull RSI ",
style=shape.labelup,
location=location.belowbar,
color=bullColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High
plotshape(
show_RSI_MFI_Signals and bearCond_RSI ? rsi[lbR] : na,
offset=-lbR,
title="Regular Bearish Label RSI",
text=" Bear RSI ",
style=shape.labeldown,
location=location.abovebar,
color=bearColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High
plotshape(
show_RSI_MFI_Signals and hiddenBearCond_RSI ? rsi[lbR] : na,
offset=-lbR,
title="Hidden Bearish Label RSI",
text=" H Bear RSI ",
style=shape.labeldown,
location=location.abovebar,
color=bearColor,
textcolor=textColor
)
// End
buy_short_term = close > TMA_Low and close > smplBelow and close > ema_short
sell_short_term = close < smplAbove
// Plot signals
plotshape(show_htf_signals and buy_strong and not buy_strong[1], title="Strong Long
Signal", text="Go Long", textcolor=color.new(color.black, 0),
location=location.belowbar, color=color.new(color.lime, 0), style=shape.triangleup,
size=size.small)
plotshape(show_htf_signals and sell_strong and not sell_strong[1], title="Strong
Short Signal", text="Go Short", textcolor=color.new(color.black, 0),
location=location.abovebar, color=color.new(color.red, 0),
style=shape.triangledown, size=size.small)
// End