Can't figure out how to calculate if candle breakes algo trendline

 

I have code that finds two highs within diffrent timespans, so the first looks x candles back and the other looks y candles back to then make a RAY. But i cant figure out how to implement if the candlestick breakes the trendline.

hope you can help!