I am trying to figure out whether an event has occurred during a simulation. A very simple way to do this seems to be using BarsSince().
Is there a way to determine if the event has never occurred?
A simple example would be:
BarsSince(CLOSE>20)
Let's say CLOSE = 17,18,19,20,21... The BarsSince() would return ?,?,?,0,1. What are the values when CLOSE < 20? I plotted it out, and there is no value plotted for this scenario. Is it possible to determine a value for this case?
Wanna join the discussion?! Login to your Discussions forum accountor Register a new forum account.
There are a few ways to determine if an event happened at any time on the chart, or whether an event did not happen at any time. One of the methods uses the Cum() function to count all the instances of the event. Obviously, if the accumulator is greater than zero then the event occurred at least once, or if it is zero the event did not occur. One problem is that if the event is not recorded as occurring due the presence of N/A bars, the Cum() function will also be undefined. One way around this is to nest the IsDefined() and the event in the Cum() function and count the instances of this instead. Another way is to use the forum.dll library (see below).