BarsSince

Category: Instructions

Definition and Purpose:

The BarsSince function in ProBuilder language is used to determine the number of bars (or candlesticks) that have elapsed since a specified condition was last true. This function is particularly useful in technical analysis for tracking how long ago an event occurred on a chart, such as a crossover of indicators or price thresholds.

Syntax:

BarsSince(Condition, Occurrence)

The Condition parameter is a boolean expression that defines the event to check for. The Occurrence parameter is optional and specifies which occurrence of the condition being true is of interest. If Occurrence is not provided, the function defaults to the most recent occurrence (0). If the condition has never been true, the function returns -1.

Example:

a = rsi[14] crosses over 50
testA = BarsSince(a, 1)
testB = BarsSince(a)
return testA as "previous occurrence", testB as "last occurrence"

In this example, a is a condition where the 14-period Relative Strength Index (RSI) crosses over the value 50. testA calculates the number of bars since the first occurrence of this condition, and testB calculates the number of bars since the last occurrence.

Additional Information:

  • The RSI (Relative Strength Index) is a momentum oscillator used in technical analysis that measures the speed and change of price movements. RSI oscillates between zero and 100. Traditionally, and according to Wilder, RSI is considered overbought when above 70 and oversold when below 30.
  • The crosses over operator in ProBuilder is used to identify when one data series, such as an indicator or price, moves above another series or a specific value.

Understanding the BarsSince function can help traders and analysts pinpoint the timing of market events relative to their occurrence, which is crucial for strategies that depend on the duration of market conditions.

Logo Logo
Loading...