MultiCharts .NET Up-Close Frequency Indicator: Count Rising Closes with PowerLanguage C#
Beginner Trading Tutorial | MultiCharts .NET | C# Indicator
When traders describe a market as consistently rising, they sometimes combine two distinct ideas: the magnitude of the price change and how frequently prices move higher. A market that rises sharply on one bar and declines slightly on several subsequent bars can still finish above its starting price. Conversely, a sequence of small upward moves can be offset by a single large decline. A directional frequency indicator helps separate the number of rising observations from the magnitude of the overall movement.
This tutorial creates an Up-Close Frequency indicator using the native MultiCharts .NET PowerLanguage C# interface. It counts how often a bar closes above the preceding bar's close within a configurable rolling window. The result is expressed on a 0–100 scale, with a midpoint at 50. The design is intentionally simple so that the indexing, calculation and display can be independently verified.
Define the observation before calculating the percentage
For each comparison, assign one point if the newer close is strictly greater than the preceding close and zero otherwise. For a window containing N comparisons, the formula is Up-Close Frequency = 100 × number of strictly rising closes / N. Unchanged closes remain in the denominator but do not increase the numerator. A reading of 60 therefore means 60% of the comparisons were strictly upward; it does not necessarily mean that 40% were downward because some may have been unchanged.
Do not confuse this definition with the count of bullish candle bodies. A candle with a close above its open can still close below the preceding bar's close after a downward gap. Our calculation uses close-to-close comparisons, not open-to-close comparisons. It also does not use RSI's average-gain and average-loss calculations, so it is not a replacement for RSI.

Consider closing prices of 100, 102, 101, 101, 104 and 105 in chronological order. The five comparisons are up, down, unchanged, up and up. The numerator is three and the denominator is five, so the result is 60%. All examples use hypothetical data. Importantly, five comparisons require six prices. Using only five closing prices and dividing by five would omit one required observation and systematically distort the count.
| Window of five comparisons | Up count | Frequency |
|---|---|---|
| Up, down, tie, up, up | 3 | 60% |
| Up, up, up, up, up | 5 | 100% |
| Down, tie, down, down, tie | 0 | 0% |
| Tie, tie, tie, tie, tie | 0 | 0% |
The last two rows show a deliberate limitation: a reading of zero does not distinguish a falling market from an unchanged market. The feature describes the frequency of upward moves, not a complete classification of all directions. A separate downward-frequency or unchanged-frequency plot could provide additional information.
Complete C# indicator for MultiCharts .NET
// PatternSmart Up Close Frequency - MultiCharts .NET
using System;
using System.Drawing;
using PowerLanguage;
namespace PowerLanguage.Indicator
{
public class PSUpCloseFrequency : IndicatorObject
{
private IPlotObject frequencyPlot;
private IPlotObject midpointPlot;
public PSUpCloseFrequency(object ctx) : base(ctx)
{
Lookback = 20;
}
[Input]
public int Lookback { get; set; }
protected override void Create()
{
frequencyPlot = AddPlot(new PlotAttributes(
"UpClosePct", EPlotShapes.Line, Color.RoyalBlue));
midpointPlot = AddPlot(new PlotAttributes(
"Midpoint", EPlotShapes.Line, Color.Gray));
}
protected override void CalcBar()
{
// Restrict the supported input range.
if (Lookback < 1 || Lookback > 500)
return;
int upCount = 0;
// N comparisons need N+1 closes.
// Configure MaxBarsBack for at least Lookback + 1.
for (int i = 0; i < Lookback; i++)
{
double newer = Bars.Close[i];
double older = Bars.Close[i + 1];
// Do not turn invalid data into a down close.
if (double.IsNaN(newer) || double.IsInfinity(newer)
|| double.IsNaN(older) || double.IsInfinity(older))
return;
if (newer > older)
upCount++;
}
// Equal closes remain in the denominator.
double pct = 100.0 * upCount / Lookback;
frequencyPlot.Set(pct);
midpointPlot.Set(50.0);
}
}
}
Read the platform-specific code in three parts
The class derives from IndicatorObject inside the PowerLanguage.Indicator namespace. This is MultiCharts .NET C#, rather than the classic PowerLanguage syntax. The constructor supplies the default Lookback of 20, while the Input attribute allows the user to change that value through the study settings. The supported range is restricted to integers between 1 and 500; values outside this range cause the calculation to return without producing a new reading.
In Create(), the indicator defines two IPlotObject instances using AddPlot and PlotAttributes. The first displays the frequency in blue, while the second displays the constant 50 reference in gray. Creating plot objects in this lifecycle stage rather than inside the bar-calculation loop avoids repeated plot construction and follows the platform's documented study structure.
CalcBar() executes in the context of the bar being evaluated. Bars.Close[0] refers to that bar's closing value, Bars.Close[1] to the preceding bar and so on. The loop compares offset i with offset i+1. For Lookback equal to 20, the largest accessed offset is 20. Each rising comparison adds one to a local integer counter. The counter is initialized on every calculation rather than accumulated in a persistent field, so repeated intrabar calls cannot add the same observation twice.
After all comparisons are counted, multiplication by 100.0 ensures a floating-point percentage. The indicator assigns the resulting value to its first plot and sets the second plot to 50. It performs a straightforward O(N) scan each time CalcBar runs. This is easy to audit; very large lookbacks, tick-by-tick updates or many simultaneous study instances may justify a more efficient rolling-count implementation.
Configure sufficient history
A window of N comparisons needs N preceding bar offsets plus the bar being evaluated. In the study properties, use automatic MaxBarsBack detection where supported, or set the manual history requirement conservatively to at least Lookback + 1. For the default Lookback of 20, use a manual value of 21 or greater. Increase that value when increasing the lookback. MultiCharts .NET can detect additional historical references and restart calculations in its automatic history-management mode; do not assume every installation uses the same setting.
Load enough data to cover the warm-up period and a useful analysis window. The code does not substitute a zero for unavailable history or for invalid numerical prices. The platform's history-management settings must be correct before accessing older bars. If you deliberately enter an unsupported lookback or encounter invalid data, the method skips writing a fresh plot value; how a previously plotted live value appears in that exceptional situation should be checked in your installation.
Choose a meaningful lookback
| Lookback | Smallest change in percentage per one-count difference | Research character |
|---|---|---|
| 5 | 20 percentage points | Very responsive, coarse scale |
| 20 (default) | 5 percentage points | Moderate sensitivity |
| 50 | 2 percentage points | Smoother directional count |
With a rolling window, two observations can affect the result when a new bar arrives: the new comparison enters, and the oldest comparison leaves. If both are upward comparisons, the count remains unchanged. If the entering comparison is upward and the departing one was not, the count increases by one. A steady reading therefore does not mean the price was unchanged. The discrete step sizes in the table are consequences of counting observations; they are not independently selected smoothing parameters.
Installation and closed-bar validation
- Open the MultiCharts .NET PowerLanguage Editor and create a new C# Indicator named PSUpCloseFrequency.
- Paste the complete class and compile it. Review any compiler messages.
- Insert the study into a separate chart pane and confirm the Lookback and MaxBarsBack settings.
- For completed-bar research, disable Update on Every Tick in the indicator properties.
- Set Lookback to five. Choose six consecutive completed bars, count how many of their five close-to-close comparisons are upward, and compare the percentage with the plotted value.
Repeat the calculation for rising, declining and unchanged prices. Verify that all-up windows yield 100 and all-non-up windows yield zero. Test a different lookback and confirm the history requirement is still sufficient. If tick updates are enabled, the current bar's close can cross above and below the preceding close before completion. That can change the latest percentage by one counting step when the other comparisons remain fixed. Such an intrabar reading is provisional. This code does not force a separate bar-status filter; its closed-bar behavior depends on the indicator's calculation configuration.
Interpretation and limitations
Frequency does not account for the magnitude of gains or losses. For example, five small increases followed by one unusually large decline may produce a high proportion of rising closes despite an overall loss. The midpoint is a descriptive reference, not a proven trading threshold. Session definitions, contract rolls, synthetic bars and data corrections may influence comparisons. If exact unchanged prices are common, consider adding separate counts for down and unchanged observations rather than treating a low upward frequency as evidence of strong selling pressure.
This indicator is suitable as a transparent research feature, not a standalone trading strategy. If you would like to extend the free program with direction-specific alerts, additional frequency plots, rolling calculations or strategy integration, contact us through our Custom Trading Software Development Services.
The implementation was reviewed against the official MultiCharts .NET indicator, calculation lifecycle and plotting documentation. It has not been compiled or executed in the platform. Validate it using your own installation and data. Trading involves risk and historical directional frequency cannot guarantee future returns.