No, there’s no instruction to detect a crossover with lines.
You have to compute the price level on which the line is sitting candle by candle.
Firstly, compute the price difference between the leftmost and the rightmost candle:
1
2
3
4
5
StartBar=barindex[20]
EndBar=barindex
Bars=EndBar-StartBar
EndPrice=Close
Difference=(EndPrice-Close[20])/Bars
then add that difference each candle to know the current price level where the line is plotted. Next candle compute the new price level where the line is supposed to sit:
1
EndPrice=EndPrice+Difference
Now you can compare the current price vs the supposed price to detect any crossover:
1
2
3
Ifclosecrosses overEndPricethen
// do whatever you want when a crossover is detected
Endif
if the difference is negative the direction continues downwards, otherwise it will continue upwards.
Repeat the last process each bar.
When you need to draw a new line elsewhere, repeat the whole process from start.
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok