// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © calibrated89 //@version=5 indicator("~Delta crosses MA Threshold", overlay = true, max_boxes_count = 3) //_______ Inputs _______ l1 = input(4, "Smallest Base Lookback") l2 = l1 * 2 l3 = l1 * 3 l4 = int(l1 * 4.5) l5 = l1 * 5 l6 = l1 * 6 l7 = l6 * 3 //_______ Colors _______ c1 = color.rgb(128,128,128) c2 = color.rgb(229,228,226) c3 = color.rgb(54,69,79) c4 = color.rgb(0,255,0) c5 = color.rgb(74,93,35) c6 = color.rgb(28,172,120) c7 = color.rgb(102,221,170) c8 = color.rgb(0,0,128) c9 = color.rgb(114, 184, 255) c10 = color.rgb(186,85,211) c11 = color.rgb(221, 95, 41) c12 = color.rgb(128,0,0) c13 = color.rgb(227,0,34) v = volume o = open c = close vbuy = 0.0 vsell = 0.0 if c > o vbuy := v * math.abs(o / c - 1) if c < o vsell := v * math.abs(o / c - 1) delta = ta.cum(vbuy - vsell) cvd_ma = ta.alma(delta, l2, 0.85, 6) cvd_ema = ta.ema(delta, 9) //barcolor( delta > cvd_ma ? c9 : c11) //----Normalization Function n(s,l) => hi = ta.highest(s, l) lo = ta.lowest(s, l) n = (s - lo) / (hi - lo)+1 n v00 = 0.0, b00 = 0.0, s00 = 0.0 d00 = 0.0 nd00 = 0.0 //____________ Fastest _____________________ v00 := n(volume,l2) if close > open b00 := v00 * math.abs(open / close - 1) b00 if close < open s00 := v00 * math.abs(open / close - 1) s00 d00 := ta.cum(b00 - s00) nd00 := (n(d00,l2) -1.5)*2.0 ma2 = ta.alma(nd00,l2,0.95,6) //____________ Faster _____________________ v00 := n(volume,l3) if close > open b00 := v00 * math.abs(open / close - 1) b00 if close < open s00 := v00 * math.abs(open / close - 1) s00 d00 := ta.cum(b00 - s00) nd00 := (n(d00,l3) -1.5)*2.0 ma3 = ta.alma(nd00,l3,0.95,6) ma3a = ta.alma(ma3, l3, 0.95, 6) //plot( ma3a, color = ma2 > ma3a ? c6 : c13) //____________ Slow _____________________ v00 := n(volume,l4) if close > open b00 := v00 * math.abs(open / close - 1) b00 if close < open s00 := v00 * math.abs(open / close - 1) s00 d00 := ta.cum(b00 - s00) nd00 := (n(d00,l4) -1.5)*2.0 ma4 = ta.alma(nd00,l4,0.95,6) //____________ Slower _____________________ v00 := n(volume,l5) if close > open b00 := v00 * math.abs(open / close - 1) b00 if close < open s00 := v00 * math.abs(open / close - 1) s00 d00 := ta.cum(b00 - s00) nd00 := (n(d00,l5) -1.5)*2.0 ma5 = ta.alma(nd00,l5,0.95,6) //____________ Slowest _____________________ v00 := n(volume,l6) if close > open b00 := v00 * math.abs(open / close - 1) b00 if close < open s00 := v00 * math.abs(open / close - 1) s00 d00 := ta.cum(b00 - s00) nd00 := (n(d00,l6) -1.5)*2.0 ma6 = ta.alma(nd00,l6,0.95,6) //_______ peckerponzi original rotation _______ //----Trigger Rotation v00 := n(volume,l6) if close > open b00 := v00 * math.abs(open / close - 1) b00 if close < open s00 := v00 * math.abs(open / close - 1) s00 d00 := ta.cum(b00 - s00) nd00 := (n(d00,l6) -1.5)*2.0 nd00 := ta.alma(nd00,l6,0.95,6) nd10 = ta.rma(nd00,2) //----Fast Rotation v01 = n(volume,l7) b01 = 0.0, s01 = 0.0 if close > open b01 := v01 * math.abs(open / close - 1) b01 if close < open s01 := v01 * math.abs(open / close - 1) s01 d01 = ta.cum(b01 - s01) nd01 = (n(d01,l7) -1.5)*2.0 nd01 := ta.alma(nd01,l7,0.90,6) nd11 = ta.rma(nd01,3) color1 = nd01 > nd11 ? c9 : c12 //fill(plot(nd01,'Fast Rotation',color1),plot(nd11,'Smooth Fast Rotation',color1),color=color1) //fill(hline(1,'1',#FF52528F,linestyle=hline.style_solid),hline(0.75,'0.75',#FF52528F,linestyle=hline.style_dotted),color= nd00 > 0.75 and nd00 < nd10 ? #FF5252CF : #FF52522F) //hline(0,'0',#FFFFFF8F,linestyle=hline.style_solid) //fill(hline(-0.75,'-0.75',#00BCD48F,linestyle=hline.style_dotted),hline(-1,'-1',#00BCD48F,linestyle=hline.style_solid),color= nd00 < -0.75 and nd00 > nd10 ? #00BCD4CF : #00BCD42F) //----Basic Single Alert bool vis_alert = input(true, 'Show Alert?') threshold = input(0.75,'Alert Threshold') long = ta.crossover(nd01,nd11) and nd01 <= - threshold and nd00 > nd10 short = ta.crossunder (nd01,nd11) and nd01 >= threshold and nd00 < nd10 cond = long or short bgcol = long ? #00BCD4 : short ? #FF5252 : na //bgcolor(vis_alert ? bgcol : na ,title='Alert Trigger') alertcondition(cond, title='Rotations X', message='Rotations X') // ~Delta crosses MA Threshold p1 = 0.0, p2 = 0.0 highest = ta.highest(high, 24) if ta.crossunder (nd01,nd11) and nd01 >= threshold and nd00 < nd10 box2 = box.new(bar_index, highest, bar_index+100, close, border_color = na, extend = extend.right, bgcolor=color.rgb(60,179,113, 50)) p1 := 0.0, p2 := 0.0 lowest = ta.lowest(low, 24) if ta.crossover(nd01,nd11) and nd01 <= - threshold and nd00 > nd10 box2 = box.new(bar_index, close, bar_index+100, lowest, border_color = na, extend = extend.right, bgcolor=color.rgb(207,16,32,60))