Count bars from events

 

I have been looking for something like BarsSince (or Bars Since) we find in other platforms but didnt found what I was looking for (maybe Im not good in searching). So I decided to do it on my own and share it here just in case others are in the same situation like I was yesterday.

It is a very simple and easy to read, understand and modify code. In this example I have been looking for how many bars back a bars High last touched the Donchian High and same for the Low. Simply replace it with the code you are looking for. Use it as stand alone or copy and paste it into your code. The Comment shows the calculated results for a quick visual check and if not needed anymore can just be deleted.

Maybe its usefull for one or two out there.

Have fun



 
realtrade:

The Comment shows the calculated results for a quick visual check and if not needed anymore can just be deleted.


How do you delete the Comment ?
 

You should add this line to the deinit() function . . .

Comment("");
 
RaptorUK:

You should add this line to the deinit() function . . .

oh yes Raptor, nice thought. Should have done that. But I more thought of simply deleting it in the editor when you do your coding. However, I added it to the code.
Reason: