// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © maruful_islam //@version=5 indicator("~Delta crosses MA Threshold", overlay = true, max_boxes_count = 5) //_______ 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 //_______ 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.90,'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 highest = ta.highest(high, 48) if ta.crossunder (nd01,nd11) and nd01 >= threshold and nd00 < nd10 distance_up = ((highest - close)/close)*100 box_resistance = box.new( bar_index, close+distance_up, bar_index+70, close, border_color=color.rgb(0,0,0,100), bgcolor = color.maroon) lowest = ta.lowest(low, 48) if ta.crossover(nd01,nd11) and nd01 <= - threshold and nd00 > nd10 distance_dn = ((close-lowest)/close)*100 box_support = box.new(bar_index, close, bar_index+40, close+distance_dn, border_color = color.rgb(242, 242, 242, 100), bgcolor = color.teal)