Skip to content

BarCount Function

By Optuma Team · Updated 2018-10-26

The BarCount() script function will return either the total number of data bars that are available for a symbol, or the total number of bars on the screen at the time. This can be used in instances where you want to disregard newly floated stocks, or wanting to have a dynamic moving average calculated off the total number of bars in view.

For example, if you wanted a scan to disregard newly listed stocks you could use something like this:

BarCount() > 100

This would mean that if a chart had less than 100 trading days it would be excluded from the scans results.

This example can be used in a Show Plot to calculate an average price level based off the entire chart’s price history.

$b = BARCOUNT();
v1 = MA(BARS=$b);
LAST(V1)

On the chart the result would look like this, with the horizontal line being the average of the entire history of the chart:

BARcount

This script can be modified so that the average price is calculated based off the number of bars visible in the screen at the time:

$b = BARCOUNT(RANGE=VISIBLE);
v1 = MA(BARS=$b);
LAST(V1)

BarCount2

As you zoom in / out and the number of bars in view changes, the line will be recalculated.

Choose which categories of cookies you allow. Strictly-necessary cookies are always on. You can change this any time via the "Cookie Settings" link in the footer.

  • Functional

    Remember preferences like dismissed banners and your dark-mode choice.

  • Analytics

    Help us understand how the site is used so we can improve it.

  • Marketing

    Measure our advertising and help us reach people who may be interested in Optuma.