Impulse & Security
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Tears-Of-Broker
//@version=5
indicator(("Impulse & Security"),overlay=true)
//☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣
c=high-low
h=high
l=low
diap=input(2, title='Допустимый диапазон погрешности')

BigCand=c>c[1] and c>c[2] and c>c[3] and c>c[4] and c>c[5] and c>c[6] and c>c[7] and c>c[8] and c>c[9] and c>c[10] and c>c[11] and c>c[12]

//☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣
V= h[1]>=h and h>=(h[1]-syminfo.mintick*diap)
V2=h[2]>=h and h>=(h[2]-syminfo.mintick*diap) and h>h[1]
V3=h[3]>=h and h>=(h[3]-syminfo.mintick*diap) and h>h[1] and h>h[2]
V4=h[4]>=h and h>=(h[4]-syminfo.mintick*diap) and h>h[1] and h>h[2] and h>h[3]
V5=h[5]>=h and h>=(h[5]-syminfo.mintick*diap) and h>h[1] and h>h[2] and h>h[3] and h>h[4]
V6=h[6]>=h and h>=(h[6]-syminfo.mintick*diap) and h>h[1] and h>h[2] and h>h[3] and h>h[4] and h>h[5]
V7=h[7]>=h and h>=(h[7]-syminfo.mintick*diap) and h>h[1] and h>h[2] and h>h[3] and h>h[4] and h>h[5] and h>h[6]

V_= h[1]<=h and h<=(h[1]+syminfo.mintick*diap)
V_2=h[2]<=h and h<=(h[2]+syminfo.mintick*diap) and h>=h[1]
V_3=h[3]<=h and h<=(h[3]+syminfo.mintick*diap) and h>=h[1] and h>=h[2]
V_4=h[4]<=h and h<=(h[4]+syminfo.mintick*diap) and h>=h[1] and h>=h[2] and h>=h[3]
V_5=h[5]<=h and h<=(h[5]+syminfo.mintick*diap) and h>=h[1] and h>=h[2] and h>=h[3] and h>=h[4]
V_6=h[6]<=h and h<=(h[6]+syminfo.mintick*diap) and h>=h[1] and h>=h[2] and h>=h[3] and h>=h[4] and h>=h[5]
V_7=h[7]<=h and h<=(h[7]+syminfo.mintick*diap) and h>=h[1] and h>=h[2] and h>=h[3] and h>=h[4] and h>=h[5] and h>=h[6]
Vall=V or V2 or V3 or V4 or V5 or V6 or V7 or V_ or V_2 or V_3 or V_4 or V_5 or V_6 or V_7
VV= (Vall[1] and V or Vall[1] and V_) 
 
A= l[1]>=l and l>=(l[1]-syminfo.mintick*diap)
A2=l[2]>=l and l>=(l[2]-syminfo.mintick*diap) and l<l[1]
A3=l[3]>=l and l>=(l[3]-syminfo.mintick*diap) and l<l[1] and l<l[2]
A4=l[4]>=l and l>=(l[4]-syminfo.mintick*diap) and l<l[1] and l<l[2] and l<l[3]
A5=l[5]>=l and l>=(l[5]-syminfo.mintick*diap) and l<l[1] and l<l[2] and l<l[3] and l<l[4]
A6=l[6]>=l and l>=(l[6]-syminfo.mintick*diap) and l<l[1] and l<l[2] and l<l[3] and l<l[4] and l<l[5]
A7=l[7]>=l and l>=(l[7]-syminfo.mintick*diap) and l<l[1] and l<l[2] and l<l[3] and l<l[4] and l<l[5] and l<l[6]

A_= l[1]<=l and l<=(l[1]+syminfo.mintick*diap)
A_2=l[2]<=l and l<=(l[2]+syminfo.mintick*diap) and l<=l[1]
A_3=l[3]<=l and l<=(l[3]+syminfo.mintick*diap) and l<=l[1] and l<=l[2]
A_4=l[4]<=l and l<=(l[4]+syminfo.mintick*diap) and l<=l[1] and l<=l[2] and l<=l[3]
A_5=l[5]<=l and l<=(l[5]+syminfo.mintick*diap) and l<=l[1] and l<=l[2] and l<=l[3] and l<=l[4]
A_6=l[6]<=l and l<=(l[6]+syminfo.mintick*diap) and l<=l[1] and l<=l[2] and l<=l[3] and l<=l[4] and l<=l[5]
A_7=l[7]<=l and l<=(l[7]+syminfo.mintick*diap) and l<=l[1] and l<=l[2] and l<=l[3] and l<=l[4] and l<=l[5] and l<=l[6]
Aall=A or A2 or A3 or A4 or A5 or A6 or A7 or A_ or A_2 or A_3 or A_4 or A_5 or A_6 or A_7
AA= (Aall[1] and A or Aall[1] and A_) 
//plotshape(Vall, title='Vbar', style=shape.triangledown, location= location.abovebar, size=size.tiny, color=color.new(color.orange, 0))
plotshape(VV, title='VVbar', style=shape.diamond, location= location.abovebar, size=size.tiny, color=color.new(color.red, 50))
//plotshape(Aall, title='Abar', style=shape.triangleup, location= location.belowbar, size=size.tiny, color=color.new(color.blue, 0))
plotshape(AA, title='AAbar', style=shape.diamond, location= location.belowbar, size=size.tiny, color=color.new(color.green, 50))
//●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●

plot(ta.ema(close, 100),color=color.new(color.white, 10))
plot(ta.ema(close, 40),color=color.new(color.white, 10))
//Breakout ☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣
Breakout_A = close>ta.ema(close, 40) and BigCand and open<close
Breakout_V = close<ta.ema(close, 40) and BigCand and open>close 

candleColor = color.gray

if Breakout_A 
    candleColor := color.green
    candleColor

if Breakout_V
    candleColor := color.red
    candleColor

barcolor(candleColor) 
//☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣
VVV=Breakout_V[1] and h<h[1] and Vall and close < ta.ema(close, 40)
     or Breakout_V[2] and h<h[2] and Vall and close < ta.ema(close, 40)   and h[1]<h[2]
     or Breakout_V[3] and h<h[3] and Vall and close < ta.ema(close, 40)   and h[2]<h[3] and h[1]<h[3]
     or Breakout_V[4] and h<h[4] and Vall and close < ta.ema(close, 40)   and h[3]<h[4] and h[2]<h[4] and h[1]<h[4]
     or Breakout_V[5] and h<h[5] and Vall and close < ta.ema(close, 40)   and h[4]<h[5] and h[3]<h[5] and h[2]<h[5] and h[1]<h[5]
     or Breakout_V[6] and h<h[6] and Vall and close < ta.ema(close, 40)   and h[5]<h[6] and h[4]<h[6] and h[3]<h[6] and h[2]<h[6] and h[1]<h[6]
     or Breakout_V[7] and h<h[7] and Vall and close < ta.ema(close, 40)   and h[6]<h[7] and h[5]<h[7] and h[4]<h[7] and h[3]<h[7] and h[2]<h[7] and h[1]<h[7]
     or Breakout_V[8] and h<h[8] and Vall and close < ta.ema(close, 40)   and h[7]<h[8] and h[6]<h[8] and h[5]<h[8] and h[4]<h[8] and h[3]<h[8] and h[2]<h[8] and h[1]<h[8]
     or Breakout_V[9] and h<h[9] and Vall and close < ta.ema(close, 40)   and h[8]<h[9] and h[7]<h[9] and h[6]<h[9] and h[5]<h[9] and h[4]<h[9] and h[3]<h[9] and h[2]<h[9] and h[1]<h[9] 
     or Breakout_V[10] and h<h[10] and Vall and close < ta.ema(close, 40) and h[9]<h[10] and h[8]<h[10] and h[7]<h[10] and h[6]<h[10] and h[5]<h[10] and h[4]<h[10] and h[3]<h[10] and h[2]<h[10] and h[1]<h[10]  
AAA=Breakout_A[1] and l>l[1] and Aall and close > ta.ema(close, 40) 
     or Breakout_A[2] and l>l[2] and Aall and close > ta.ema(close, 40)   and l[1]>l[2]
     or Breakout_A[3] and l>l[3] and Aall and close > ta.ema(close, 40)   and l[2]>l[3] and l[1]>l[3]
     or Breakout_A[4] and l>l[4] and Aall and close > ta.ema(close, 40)   and l[3]>l[4] and l[2]>l[4] and l[1]>l[4]
     or Breakout_A[5] and l>l[5] and Aall and close > ta.ema(close, 40)   and l[4]>l[5] and l[3]>l[5] and l[2]>l[5] and l[1]>l[5]
     or Breakout_A[6] and l>l[6] and Aall and close > ta.ema(close, 40)   and l[5]>l[6] and l[4]>l[6] and l[3]>l[6] and l[2]>l[6] and l[1]>l[6]
     or Breakout_A[7] and l>l[7] and Aall and close > ta.ema(close, 40)   and l[6]>l[7] and l[5]>l[7] and l[4]>l[7] and l[3]>l[7] and l[2]>l[7] and l[1]>l[7]
     or Breakout_A[8] and l>l[8] and Aall and close > ta.ema(close, 40)   and l[7]>l[8] and l[6]>l[8] and l[5]>l[8] and l[4]>l[8] and l[3]>l[8] and l[2]>l[8] and l[1]>l[8]
     or Breakout_A[9] and l>l[9] and Aall and close > ta.ema(close, 40)   and l[8]>l[9] and l[7]>l[9] and l[6]>l[9] and l[5]>l[9] and l[4]>l[9] and l[3]>l[9] and l[2]>l[9] and l[1]>l[9] 
     or Breakout_A[10] and l>l[10] and Aall and close > ta.ema(close, 40) and l[9]>l[10] and l[8]>l[10] and l[7]>l[10] and l[6]>l[10] and l[5]>l[10] and l[4]>l[10] and l[3]>l[10] and l[2]>l[10] and l[1]>l[10]
//☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣
bgcolor(VVV  ? color.new(color.red,90) : na) 
bgcolor(AAA  ? color.new(color.green,90) : na) 


if (Breakout_A )
    line.new(bar_index, low[0], bar_index+5, low, style= line.style_dotted, color=color.new(color.red, 50), width = 2)
//    line.new(bar_index, high[0], bar_index+5, high, style= line.style_dotted, color=color.new(color.green, 50), width = 2)
if (Breakout_V)
//    line.new(bar_index-1, low[0], bar_index+5, low, style= line.style_dotted, color=color.new(color.green, 50), width = 2)
    line.new(bar_index, high[0], bar_index+5, high, style= line.style_dotted, color=color.new(color.red, 50), width = 2)    
//☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣☣






































