Oscillator Matrix With Alerts
Oscillator Matrix With Alerts
0
at https://mozilla.org/MPL/2.0/
//@version=5
indicator("[StratifyTrade] Oscillator Matrix (TNR and Punkchainer Adjusted) ",
shorttitle = "Oscillator Matrix", max_lines_count = 500)
var maxval = 0.
var minval = 1000.
dwTL = "Length of the hyper wave"
smTL = "[SMA] Smooth signal with a simple moving average\n[EMA] Smooth signal with
an exponential moving average\n[Input] Length of the smooth"
dvTL = "Sensibility of the real time divergence : less sensibility = more short
term divs; more sensibility = more long term divs"
rfTL = "More factor will return in less signals but in a stronger way, less factor
will return more signal with less strength"
type oL
float sig
float sgD
color cO
type dP
int n
float src
float p
type smf
float mfi
color mfc
float blMFI
float brMFI
type cnf
color up
color dn
float[] blT
float[] brT
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
type = "TEMA"
len = rsF*10
count = 20
colUp = #2962ff
colDn = #f23645
colMa = #787b86
//-----------------------------------------------------------------------------}
//Method MA
//-----------------------------------------------------------------------------{
method ma(string type, int length) =>
//
ema1 = ta.ema(close, length)
ema2 = ta.ema(ema1 , length)
ema3 = ta.ema(ema2 , length)
//
switch type
"SMA" => ta.sma (close, length)
"EMA" => ema1
"SMMA (RMA)" => ta.rma (close, length)
"HullMA" => ta.hma (close, length)
"WMA" => ta.wma (close, length)
"VWMA" => ta.vwma(close, length)
"DEMA" => 2 * ema1 - ema2
"TEMA" => (3 * ema1) - (3 * ema2) + ema3
=> na
//-----------------------------------------------------------------------------}
//Calculations
//-----------------------------------------------------------------------------{
ma = type.ma(len)
fl = ta.falling(ma , count)
rs = ta.rising (ma , count)
up = fl[1] and ma > ma[1]
dn = rs[1] and ma < ma[1]
atr = ta.atr(14)
n = bar_index
//-----------------------------------------------------------------------------}
//Execution
//----------------
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
bigRev = 0
if (up)
bigRev := 1
if (dn)
bigRev := -1
//-----------------------------------------------------------------------------}
length = 2+rsF
src = close
//Style
bull_css_0 = color.black
bull_css_1 = color.black
bear_css_0 = color.black
bear_css_1 = color.black
//-----------------------------------------------------------------------------}
//Normalization variables
//-----------------------------------------------------------------------------{
var short_len = int(length / 2)
var hull_len = int(math.sqrt(length))
//-----------------------------------------------------------------------------}
//Hull coefficients
//-----------------------------------------------------------------------------{
var lcwa_coeffs = array.new_float(hull_len, 0)
var hull_coeffs = array.new_float(0)
if barstate.isfirst
//Linearly combined WMA coeffs
for i = 0 to length-1
sum1 = math.max(short_len - i, 0)
sum2 = length - i
//-----------------------------------------------------------------------------}
//Hull squeeze oscillator
//-----------------------------------------------------------------------------{
var os = 0
var lenn = array.size(hull_coeffs)-1
hma = 0.
inv_hma = 0.
for i = 0 to lenn
hma += src[i] * array.get(hull_coeffs, i)
inv_hma += src[lenn-i] * array.get(hull_coeffs, i)
//-----------------------------------------------------------------------------}
//Plot
//-----------------------------------------------------------------------------{
//Colors
css0 = color.from_gradient(hso, 0, cmean, bull_css_0, bull_css_1)
css1 = color.from_gradient(hso, -cmean, 0, bear_css_1, bear_css_0)
css = hso > 0 ? css0 : css1
smallRev = 0
if os > os[1] and os == 1
smallRev := -1
if os < os[1] and os == -1
smallRev := 1
lookbackPeriod = mfL
// Iterate over the lookback period and count the number of upward and downward
trends
for i = 1 to lookbackPeriod
if priceChangePercentage[i] > 0
upwardTrends := upwardTrends + 1
else if priceChangePercentage[i] < 0
downwardTrends := downwardTrends + 1
// Calculate the oscillator value based on the difference between upward and
downward trends
oscillatorValue = probabilityUpward - probabilityDownward
// Determine the histogram color based on the difference between the oscillator
value and zero line
mfT() =>
switch
mf.mfi > 0 =>
if cf.brT.size() > 1
cf.brT.pop()
if cf.blT.size() > mfL
cf.blT.pop()
if mf.mfi > cf.blT.avg()
cf.blT.unshift(mf.mfi)
else
cf.blT.unshift(mf.mfi[mfL] > 0 ? mf.mfi[mfL] : mf.mfi)
method st(simple string src, float osc, simple int len) =>
float o = switch src
"SMA" => ta.sma(osc, len)
"EMA" => ta.ema(osc, len)
rv() =>
vMA = ta.sma(volume, 7)
rsi = ta.rsi(vMA, 7) - 50
mjBR = tMj and osc.sig > rsF and mf.mfi > cf.blT.avg() ? true :
false
mjBL = tMj and osc.sig < -rsF and mf.mfi < cf.brT.avg() ? true :
false
mnBR = tMn and osc.sig > 20 and osc.sig > osc.sgD and rsi > 20 ? true :
false
mnBL = tMn and osc.sig < -20 and osc.sig < osc.sgD and rsi < -20 ? true :
false
mfi() =>
mf.mfi := ta.sma(ta.mfi(hl2, mfL) - 50, mfS)
bL = mf.mfi - 10
bR = mf.mfi + 10
cDiv() =>
mx = math.max(osc.sig, osc.sgD, osc.sig[1], osc.sgD[1])
mn = math.min(osc.sig, osc.sgD, osc.sig[1], osc.sgD[1])
switch
osc.sig > dvT =>
if ta.crossunder(osc.sig, osc.sgD)
switch
na(div.src) =>
div.n := bar_index - mxid
div.src := math.max(open[mxid], close[mxid])
div.p := mx
//osc(mL, sL)
n1 = mL
n2 = sL
ap = hlc3
esa = ta.ema(ap, n1)
d = ta.ema(math.abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d)
tci = ta.ema(ci, n2)
wt1 = tci
//wt1 += mf.mfi
zi = (wt1-minval)/(maxval-minval)*100
wt1 := zi
wt1 := wt1-50
wt2 = ta.sma(wt1, 3)
if (sT == 'EMA')
wt2 := ta.ema(wt1, 3)
//wt2 = ta.sma(wt1, 2)
var indbot=0
var indtop=0
osc.sig := wt1
osc.sgD := wt2
osc.cO := osc.sig > osc.sgD ? fCSS.css(1) : sCSS.css(1)
//if ()
// Histogram
// Histogram
if sDiv
cDiv()
// REVERSAL SIGNAL
plotshape(bigRev == 1 ? -65 : na, location = location.absolute, color = rsBL, size
= size.tiny, style = shape.triangleup)
plotshape(bigRev == -1 ? 65 : na, location = location.absolute, color = rsBR, size
= size.tiny, style = shape.triangledown)
// HYPER WAVE
plot(ta.crossover (osc.sig, osc.sgD) and dW ? math.min(osc.sig, osc.sgD) : na,
style = plot.style_circles, linewidth = 2, color = osc.cO.css(0), offset = 0)
plot(ta.crossunder(osc.sig, osc.sgD) and dW ? math.max(osc.sig, osc.sgD) : na,
style = plot.style_circles, linewidth = 2, color = osc.cO.css(0), offset = 0)
switch
osc.sig > 0 and mf.mfi > 0 => cf.up := cnBL
osc.sig < 0 and mf.mfi < 0 => cf.dn := cnBR
=>
cf.dn := cnBR.transp(60)
cf.up := cnBL.transp(60)
//threshold
plot(mf.mfi > 0 and Smf ? cf.blT.avg() : na, color = mfBL, style =
plot.style_linebr)
plot(mf.mfi < 0 and Smf ? cf.brT.avg() : na, color = mfBR, style =
plot.style_linebr)
//CONFLUENCE METER
if barstate.islast
line.new(x1 = last_bar_index, x2 = bar_index - 1, y1 = 20, y2 = 20, color =
chart.fg_color.transp(50), style = line.style_dashed, extend = extend.right)
line.new(x1 = last_bar_index, x2 = bar_index - 1, y1 = -20, y2 = -20, color =
chart.fg_color.transp(50), style = line.style_dashed, extend = extend.right)
if sCNF
var label lb = na
lb.delete()
lb := na
for i = 0 to 21
int id = switch i
0 => 55
1 => 50
2 => 45
3 => 40
4 => 35
5 => 30
6 => 25
7 => 20
8 => 15
9 => 10
10 => 5
11 => 0
12 => -5
13 => -10
14 => -15
15 => -20
16 => -25
17 => -30
18 => -35
19 => -40
20 => -45
21 => -50
ln.unshift(
line.new(
x1 = bar_index + 2
, x2 = bar_index + 2
, y1 = id
, y2 = id - 5
, color = color.from_gradient(id, -50, 55, cnBR, cnBL)
, width = 4
)
)
cnfP = switch
osc.sig > 0 and mf.mfi > 0 and mf.mfi > cf.blT.avg() => 40
osc.sig < 0 and mf.mfi < 0 and mf.mfi < cf.brT.avg() => -40
lb := label.new(
x = bar_index + 3
, y = cnfP
, text = "◀"
, color = na
, textcolor = chart.fg_color
, size = size.small
, style = label.style_label_left
)