Angular Momentum Swing Heat Map Plot with Signal V3.txt
Copy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=4
study("Angular Momentum Swing Heat Map Plot", shorttitle="AMHMP", overlay=false)
_source = close
src = close
MA = input(title="MA", options=["SMA", "EMA", "WMA"], defval="EMA")
MA2 = input(title="MA2", options=["SMA", "EMA", "WMA"], defval="EMA")
sm = input(true, title="Smooth Momentum")
smp = input(28, title="Smoothing Period")
Theme = input(title="Theme", options=["Theme 1", "Theme 2", "Theme 3"], defval="Theme 2")
inc = input(title="Increment", defval=1)
smooth = input(title="Smooth", defval=1, type=input.integer)
smoothSlow= input(title="Smooth Slow", defval=14, type=input.integer)
plotNumber= input(title="Plot Number", defval=18, minval=1, maxval=28, type=input.integer)
PaintBars = input(title="Paint Bars", defval=false, type=input.bool)
IncType = input(title="Waves", defval=false, type=input.bool)
loopback = input(title="Loopback Length to Normalize", defval=160, type=input.integer)
lbR = input(title='Oscilator Pivot Lookback Right ST', defval=1)
lbL = input(title='Oscilator Pivot Lookback Left ST', defval=10)
lbR2 = input(title='Oscilator Pivot Lookback Right MT', defval=1)
lbL2 = input(title='Oscilator Pivot Lookback Left MT', defval=30)
lbR3 = input(title='Oscilator Pivot Lookback Right LT', defval=30)
lbL3 = input(title='Oscilator Pivot Lookback Left LT', defval=100)
rangeUpper = input(title='Max of Lookback Range ST/MT', defval=100)
rangeLower = input(title='Min of Lookback Range ST/MT', defval=1)
rangeUpper2 = input(title='Max of Lookback Range LT', defval=800)
rangeLower2 = input(title='Min of Lookback Range LT', defval=100)
bearColor = color.new(color.red, 0)
bullColor = color.new(color.green, 0)
bearColor2 = color.new(color.fuchsia, 0)
bullColor2 = color.new(color.blue, 0)
textColor = color.new(color.white, 0)
nma(src, length1, length2) =>
lambda = length1 / length2
alpha = lambda * (length1 - 1) / (length1 - lambda)
ma1 = ema(src, length1)
ma2 = ema(ma1, length2)
nma = (1 + alpha) * ma1 - alpha * ma2
dema(src, len) =>
ma1 = ema(src, len)
ma2 = ema(ma1, len)
2 * ma1 - ma2
eTma(_src, _len) =>
_tma = ema(ema(_src, _len), _len)
tma(_src, _len) =>
_tma = sma(sma(_src, _len), _len)
noma(_src,_len) =>
_noma = _src
tema(src, len) =>
ma1 = ema(src, len)
ma2 = ema(ma1, len)
ma3 = ema(ma2, len)
3 * (ma1 - ma2) + ma3
tdema(src, len) =>
ma1 = dema(src, len)
ma2 = dema(ma1, len)
ma3 = dema(ma2, len)
3 * (ma1 - ma2) + ma3
ttema(src, len) =>
ma1 = tema(src, len)
ma2 = tema(ma1, len)
ma3 = tema(ma2, len)
3 * (ma1 - ma2) + ma3
tnma(src, len) =>
ma1 = nma(src, len, 3)
ma2 = nma(ma1, len, 3)
ma3 = nma(ma2, len, 3)
3 * (ma1 - ma2) + ma3
thma(src, len) =>
ma1 = hma(src, len)
ma2 = hma(ma1, len)
ma3 = hma(ma2, len)
3 * (ma1 - ma2) + ma3
zlema(src, len) =>
lag = round((len - 1) / 2)
zlsrc = src + (src - src[lag])
ema(zlsrc, len)
zldema(src, len) =>
lag = round((len - 1) / 2)
zlsrc = src + (src - src[lag])
dema(zlsrc, len)
zltema(src, len) =>
lag = round((len - 1) / 2)
zlsrc = src + (src - src[lag])
tema(zlsrc, len)
dzlema(src, len) =>
ma1 = zlema(src, len)
ma2 = zlema(ma1, len)
2 * ma1 - ma2
tzlema(src, len) =>
ma1 = zlema(src, len)
ma2 = zlema(ma1, len)
ma3 = zlema(ma2, len)
3 * (ma1 - ma2) + ma3
llema(src, len) =>
srcnew = 0.25*src + 0.5*src[1] + 0.25*src[2]
ema(srcnew, len)
llsma(src, len) =>
srcnew = 0.25*src + 0.5*src[1] + 0.25*src[2]
sma(srcnew, len)
llhma(src, len) =>
srcnew = 0.25*src + 0.5*src[1] + 0.25*src[2]
hma(srcnew, len)
llwma(src, len) =>
srcnew = 0.25*src + 0.5*src[1] + 0.25*src[2]
wma(srcnew, len)
llrma(src, len) =>
srcnew = 0.25*src + 0.5*src[1] + 0.25*src[2]
rma(srcnew, len)
lltema(src, len) =>
srcnew = 0.25*src + 0.5*src[1] + 0.25*src[2]
tema(srcnew, len)
_inRange(cond) =>
bars = barssince(cond == true)
rangeLower <= bars and bars <= rangeUpper
_inRange3(cond) =>
bars2 = barssince(cond == true)
rangeLower2 <= bars2 and bars2 <= rangeUpper2
trans = 0
cp1 = color.new(#01ff00, trans)
cp2 = color.new(#05d904, trans)
cp3 = color.new(#04b504, trans)
cp4 = color.new(#039103, trans)
cp5 = color.new(#027502, trans)
cn1 = color.new(#ff0505, trans)
cn2 = color.new(#d60606, trans)
cn3 = color.new(#b80606, trans)
cn4 = color.new(#910303, trans)
cn5 = color.new(#750202, trans)
cp6 = color.new(#00ddff, trans)
cp7 = color.new(#04bcd9, trans)
cp8 = color.new(#049cb3, trans)
cp9 = color.new(#047f91, trans)
cp10 = color.new(#046775, trans)
cn6 = color.new(#d800ff, trans)
cn7 = color.new(#bb04db, trans)
cn8 = color.new(#9b05b5, trans)
cn9 = color.new(#7b038f, trans)
cn10 = color.new(#640275, trans)
cp11 = color.new(#cf0000, trans)
cp12 = color.new(#f22b11, trans)
cp13 = color.new(#f29811, trans)
cp14 = color.new(#eef211, trans)
cp15 = color.new(#3af211, trans)
cn11 = color.new(#02269e, trans)
cn12 = color.new(#0039f5, trans)
cn13 = color.new(#1176f2, trans)
cn14 = color.new(#11aff2, trans)
cn15 = color.new(#11e7f2, trans)
fc1 = color.new(color.white, 0)
sc1 = color.new(color.silver, 0)
//fc2 = color.new(color.white, 0)
fc2 = color.new(color.fuchsia, 0)
//sc2 = color.new(color.blue, 0)
sc2 = color.new(color.white, 0)
fc3 = color.new(color.white, 0)
sc3 = color.new(color.orange, 0)
fastColour = Theme == "Theme 1" ? fc1 : Theme == "Theme 2" ? fc2 : fc3
slowColour = Theme == "Theme 1" ? sc1 : Theme == "Theme 2" ? sc2 : sc3
pColour1 = Theme == "Theme 1" ? cp1 : Theme == "Theme 2" ? cp6 : cp11
pColour2 = Theme == "Theme 1" ? cp2 : Theme == "Theme 2" ? cp7 : cp12
pColour3 = Theme == "Theme 1" ? cp3 : Theme == "Theme 2" ? cp8 : cp13
pColour4 = Theme == "Theme 1" ? cp4 : Theme == "Theme 2" ? cp9 : cp14
pColour5 = Theme == "Theme 1" ? cp5 : Theme == "Theme 2" ? cp10 : cp15
nColour1 = Theme == "Theme 1" ? cn1 : Theme == "Theme 2" ? cn6 : cn11
nColour2 = Theme == "Theme 1" ? cn2 : Theme == "Theme 2" ? cn7 : cn12
nColour3 = Theme == "Theme 1" ? cn3 : Theme == "Theme 2" ? cn8 : cn13
nColour4 = Theme == "Theme 1" ? cn4 : Theme == "Theme 2" ? cn9 : cn14
nColour5 = Theme == "Theme 1" ? cn5 : Theme == "Theme 2" ? cn10 : cn15
getColour(a) =>
if(a >= 90)
pColour1
else
if(a >= 80)
pColour2
else
if(a >= 70)
pColour3
else
if(a >= 60)
pColour4
else
if(a >= 50)
pColour5
else
if(a >= 40)
nColour5
else
if(a >= 30)
nColour4
else
if(a >= 20)
nColour3
else
if(a >= 10)
nColour2
else
if(a >= 0)
nColour1
//getStoch(i, incr) =>
// c = (i * inc)
// s = smooth + incr
// if MA == "SMA"
// sma(stoch(_source, high, low, c), s)
// else
// if MA == "EMA"
// ema(stoch(_source, high, low, c), s)
// else
// if MA == "WMA"
// wma(stoch(_source, high, low, c), s)
getStoch(i, incr) =>
c = (i * inc)
p = 2 * c + 1
ema_1 = tzlema(src, smp)
//amom = 100 * ((sm ? ema_1 : src) / dema(src, p) - 1)
amom = (100*((sm ? ema_1 : src) / dema(src, p) - 1))
stoch1 = plotNumber > 0 ? getStoch(IncType ? 1 : 1 , IncType ? 1 : 0) : 0
stoch2 = plotNumber > 1 ? getStoch(IncType ? 2 : 2 , IncType ? 2 : 0) : 0
stoch3 = plotNumber > 2 ? getStoch(IncType ? 3 : 3 , IncType ? 3 : 0) : 0
stoch4 = plotNumber > 3 ? getStoch(IncType ? 4 : 4 , IncType ? 4 : 0) : 0
stoch5 = plotNumber > 4 ? getStoch(IncType ? 5 : 5 , IncType ? 5 : 0) : 0
stoch6 = plotNumber > 5 ? getStoch(IncType ? 6 : 6 , IncType ? 6 : 0) : 0
stoch7 = plotNumber > 6 ? getStoch(IncType ? 7 : 7 , IncType ? 7 : 0) : 0
stoch8 = plotNumber > 7 ? getStoch(IncType ? 8 : 8 , IncType ? 8 : 0) : 0
stoch9 = plotNumber > 8 ? getStoch(IncType ? 9 : 9 , IncType ? 9 : 0) : 0
stoch10 = plotNumber > 9 ? getStoch(IncType ? 10 : 10, IncType ? 10 : 0) : 0
stoch11 = plotNumber > 10 ? getStoch(IncType ? 15 : 11, IncType ? 11 : 0) : 0
stoch12 = plotNumber > 11 ? getStoch(IncType ? 20 : 12, IncType ? 12 : 0) : 0
stoch13 = plotNumber > 12 ? getStoch(IncType ? 25 : 13, IncType ? 13 : 0) : 0
stoch14 = plotNumber > 13 ? getStoch(IncType ? 30 : 14, IncType ? 14 : 0) : 0
stoch15 = plotNumber > 14 ? getStoch(IncType ? 35 : 15, IncType ? 15 : 0) : 0
stoch16 = plotNumber > 15 ? getStoch(IncType ? 40 : 16, IncType ? 16 : 0) : 0
stoch17 = plotNumber > 16 ? getStoch(IncType ? 45 : 17, IncType ? 17 : 0) : 0
stoch18 = plotNumber > 17 ? getStoch(IncType ? 50 : 18, IncType ? 18 : 0) : 0
stoch19 = plotNumber > 18 ? getStoch(IncType ? 55 : 19, IncType ? 19 : 0) : 0
stoch20 = plotNumber > 19 ? getStoch(IncType ? 60 : 20, IncType ? 20 : 0) : 0
stoch21 = plotNumber > 20 ? getStoch(IncType ? 70 : 21, IncType ? 21 : 0) : 0
stoch22 = plotNumber > 21 ? getStoch(IncType ? 80 : 22, IncType ? 22 : 0) : 0
stoch23 = plotNumber > 22 ? getStoch(IncType ? 90 : 23, IncType ? 23 : 0) : 0
stoch24 = plotNumber > 23 ? getStoch(IncType ? 100 : 24, IncType ? 24 : 0) : 0
stoch25 = plotNumber > 24 ? getStoch(IncType ? 110 : 25, IncType ? 25 : 0) : 0
stoch26 = plotNumber > 25 ? getStoch(IncType ? 120 : 26, IncType ? 26 : 0) : 0
stoch27 = plotNumber > 26 ? getStoch(IncType ? 140 : 27, IncType ? 27 : 0) : 0
stoch28 = plotNumber > 27 ? getStoch(IncType ? 160 : 28, IncType ? 28 : 0) : 0
colour1 = getColour(stoch1)
colour2 = getColour(stoch2)
colour3 = getColour(stoch3)
colour4 = getColour(stoch4)
colour5 = getColour(stoch5)
colour6 = getColour(stoch6)
colour7 = getColour(stoch7)
colour8 = getColour(stoch8)
colour9 = getColour(stoch9)
colour10 = getColour(stoch10)
colour11 = getColour(stoch11)
colour12 = getColour(stoch12)
colour13 = getColour(stoch13)
colour14 = getColour(stoch14)
colour15 = getColour(stoch15)
colour16 = getColour(stoch16)
colour17 = getColour(stoch17)
colour18 = getColour(stoch18)
colour19 = getColour(stoch19)
colour20 = getColour(stoch20)
colour21 = getColour(stoch21)
colour22 = getColour(stoch22)
colour23 = getColour(stoch23)
colour24 = getColour(stoch24)
colour25 = getColour(stoch25)
colour26 = getColour(stoch26)
colour27 = getColour(stoch27)
colour28 = getColour(stoch28)
getAverage = (stoch1 + stoch2 + stoch3 + stoch4 + stoch5 + stoch6 + stoch7 + stoch8 + stoch9 + stoch10 + stoch11 + stoch12 + stoch13 + stoch14 + stoch15 + stoch16 + stoch17 + stoch18 + stoch19 + stoch20 + stoch21 + stoch22 + stoch23 + stoch24 + stoch25 + stoch26 + stoch27 + stoch28) / plotNumber
getAverage1 = (stoch1 + stoch2 + stoch3 + stoch4 + stoch5 + stoch6 + stoch7 + stoch8 + stoch9 + stoch10 + stoch11 + stoch12 + stoch13 + stoch14) / plotNumber
fast = ((getAverage / 100) * plotNumber)
fast1 = ((getAverage1 / 100) * plotNumber*2)
slow = MA == "SMA" ? sma(fast1, smoothSlow) : MA == "EMA" ? zlema(fast1, smoothSlow) : wma(fast1, smoothSlow)
barColour = getColour(getAverage)
plot(slow, color=slowColour, linewidth=1, style=plot.style_line, title="slow")
plot(fast, color=fastColour, linewidth=1, style=plot.style_line, title="fast")
plot (0, color=color.gray, linewidth=1, transp=0)
plFound = na(pivotlow(slow, lbL, lbR)) ? false : true
phFound2 = na(pivothigh(slow, lbL2, lbR2)) ? false : true
plFound3 = na(pivotlow(slow, lbL3, lbR3)) ? false : true
phFound = na(pivothigh(slow, lbL, lbR)) ? false : true
plFound2 = na(pivotlow(slow, lbL2, lbR2)) ? false : true
phFound3 = na(pivothigh(slow, lbL3, lbR3)) ? false : true
//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low
oscHL = slow[lbR] > valuewhen(plFound, slow[lbR], 1) and _inRange(plFound[1])
oscHL2 = slow[lbR2] > valuewhen(plFound2, slow[lbR2], 1) and _inRange(plFound2[1])
oscHL3 = slow[lbR3] > valuewhen(plFound3, slow[lbR3], 1) and _inRange3(plFound3[1])
bullCond = (oscHL and plFound) or (oscHL2 and plFound2)
bullCond2 = oscHL3 and plFound3
plotshape(bullCond ? slow[lbR] : na, offset=-lbR, title='Regular Bullish Label', style=shape.labelup, location=location.absolute, size=size.tiny, color=bullColor, textcolor=textColor, transp=0)
plotshape(bullCond2 ? slow[lbR2] : na, offset=-lbR2, title='Regular Bullish Label LT', style=shape.labelup, location=location.absolute, size=size.tiny, color=bullColor2, textcolor=textColor, transp=0)
//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High
oscLH = slow[lbR] < valuewhen(phFound, slow[lbR], 1) and _inRange(phFound[1])
oscLH2 = slow[lbR2] < valuewhen(phFound2, slow[lbR2], 1) and _inRange(phFound2[1])
oscLH3 = slow[lbR3] < valuewhen(phFound3, slow[lbR3], 1) and _inRange3(phFound3[1])
bearCond = (oscLH and phFound) or (oscLH2 and phFound2)
bearCond2 = oscLH3 and phFound3
plotshape(bearCond ? slow[lbR] : na, offset=-lbR, title='Regular Bearish Label', style=shape.labeldown, location=location.absolute, size=size.tiny, color=bearColor, textcolor=textColor, transp=0)
plotshape(bearCond2 ? slow[lbR2] : na, offset=-lbR2, title='Regular Bearish Label LT', style=shape.labeldown, location=location.absolute, size=size.tiny, color=bearColor2, textcolor=textColor, transp=0)
// Alerts
f_crossing_level_up(sr, r) =>
//(r > sr and r < sr[1])
(r < sr and r > sr[1])
f_crossing_level_down(sr, r) =>
//(r < sr and r > sr[1])
(r > sr and r < sr[1])
if f_crossing_level_up(fast, slow)
if (fast > 0)
alert("Angular Momentum Heat Map Plot: " + syminfo.ticker + " Buy Signal (>0) at " + tostring(close) + " has tiggered! " + timeframe.period, freq = alert.freq_once_per_bar)
else
alert("Angular Momentum Heat Map Plot: " + syminfo.ticker + " Buy Signal (<0) at " + tostring(close) + " has tiggered! " + timeframe.period, freq = alert.freq_once_per_bar)
else
if f_crossing_level_down(fast, slow)
if (fast > 0)
alert("Angular Momentum Heat Map Plot: " + syminfo.ticker + " Sell Signal (>0) at " + tostring(close) + " has triggered! " + timeframe.period, freq = alert.freq_once_per_bar)
else
alert("Angular Momentum Heat Map Plot: " + syminfo.ticker + " Sell Signal (<0) at " + tostring(close) + " has triggered! " + timeframe.period, freq = alert.freq_once_per_bar)
// -->
Show all 393 lines