Hello..
I’ve been looking at this over the weekend. I couldn’t determine if the errors were related to math, algorithm logic, or the way PRT executes code.
I decided to start from scratch and try to make something work even if it’s not exactly what is required. However, it may be easier to understand/modify the code from a working position.
I couldn’t fully understand the version of the logarithmic/linear equation you used, so I used a linear/linear equation for the calculation, which is much simpler and could be replaced later if needed.
The logic of the program took a while, but it got easier, with the math under control. But there were also some execution issues to overcome.
Looking at the indicator’s movement, I can see that there are more things to do on the logical side, as usual! Under various conditions, the line changes abruptly. The movement of the points on a new breakout of the trendline may require “some” delay when the points end very close together.
Also, all this numerical calculation will slow down the program, but the parts could be optimized. For example, if the trendline point of the next new bar is known before the next bar arrives, then it would be a simple calculation to determine if it would break the trendline, therefore it would not require a loop of point movement etc., just the next point for the verification of the next bar.
Just speculating on more modifications!
This version is generalized so that it can be used for low or high trend lines using two instances of the indicator and setting the ‘switch’ variable to ‘1 or 0’ and adjusting the colour of the High/Low line via the settings menu if it is a standalone indicator, or hidden, if it is added to the price panel.
Take a look around and see what fits, etc.
druby