It is like old version but use V3 of PineScript (no repainting if you want to change it and transform in strategy).
It have a problem with alert ... I send a ticket and this is the answer.
Some scripts can potentially get repainted, and a script on which your alert is set on could be one of them. Such scripts may show different results when using historical and real-time data. This discrepancy can be observed when adding a script to the chart. Wait until it compiles the bars and refresh the page afterwards. There is a number of reasons for that, you can learn more about them in this article.
Calculations of such scripts can vary when they are based on real-time and historical data. It can also be calculated every time on different servers and give different calculation results due to unique architectural features of every server. As a result, the script’s behavior may not match what’s seen on a chart, as a chart gets computed on a separate server. Therefore, on a chart, we can see that a condition was met but an alert hasn’t triggered and vice versa.
At the moment there is no workaround, thus we strongly recommend not to set alerts on such scripts.
I don't use automatic alert but only plot this on the chart...