0

I want to raise an alert when 3 indicators show the same point using 3 indicators with different parameters, how should I set the conditions?

enter image description here

Here are the 3 Bollinger Bands. Same indicator, but Each parameter is 20.40.60, which has a different value. If you look at the place marked, this is where the bottom line of each indicator meets. I would like to know the price at this time.

G.Lebret
  • 2,826
  • 2
  • 16
  • 27
김한수
  • 15
  • 3

1 Answers1

0

The calcul in Pinescript are discrete, at the end of each bar.
So you can't calculate when each indicator's line 'meet'.
You should calculate the average distance between your 3 lines and decide when this distance is so little that you can consider your 3 lines have met.
Here is a exemple with 3 bottom line of the bolinger band indicator.
In this exemple, we consider that the 3 lines have met when the average distance between the 3 lines is under 8 and then plot a red line :

//@version=5
indicator("My script", overlay=true)
level = input.float(8,"Level under which you consider the 3 bb are touching themselves")
[middle1, upper1, lower1] = ta.bb(close,20,2)
[middle2, upper2, lower2] = ta.bb(close,40,2)
[middle3, upper3, lower3] = ta.bb(close,60,2)
plot(lower1)
plot(lower2)
plot(lower3)
distance = math.avg(math.abs(lower1-lower2), math.abs(lower1-lower3), math.abs(lower2-lower3))

price = math.avg(lower1, lower2, lower3)
plot(distance>level?na:price,color=color.red,style=plot.style_linebr, linewidth = 4)

enter image description here

G.Lebret
  • 2,826
  • 2
  • 16
  • 27