Beginner Trading Tutorial — Confirmed Simple True Range Mean in cTrader
Measuring volatility is not always as straightforward as subtracting the low of a candle from its high. When price opens outside the preceding trading range, a substantial change can occur before the first trade of a new candle. True Range (TR) provides a useful way to include this displacement. This tutorial builds a native cTrader C# indicator that calculates the simple arithmetic mean of true ranges over a configurable number of completed candles. It is an introductory implementation designed to make every step visible rather than hide the calculation inside an existing volatility study.
From ordinary range to true range
The ordinary range is High minus Low. True range instead selects the greatest of three distances: High minus Low, the absolute difference between High and the previous Close, and the absolute difference between Low and the previous Close. When the preceding close lies within the current interval, the ordinary range is already the greatest distance. When the preceding close lies outside that interval, one of the other two distances captures the additional separation.
The simple mean sums N consecutive true ranges and divides by N. Every observation has the same weight, and the oldest observation leaves the window when a new one is added. This is different from the recursively smoothed Average True Range (ATR) associated with Wilder's method. Different smoothing conventions can give different readings even on identical historical prices, so the tutorial explicitly calls the result a simple TR mean.

Calculate a small example
Suppose an initial reference candle closes at 100. The first evaluated candle has a high of 103, low of 99 and close of 102. Its ordinary range is 4; the two distances from the previous close are 3 and 1. The greatest distance is 4. The second evaluated candle has a high of 110, low of 106 and close of 108. Its ordinary range is again 4, but the two distances from the preceding close of 102 are 8 and 4. Its true range is therefore 8. The third candle has a high of 109, low of 106 and close of 107. Its three distances are 3, 1 and 2, giving a true range of 3.
With Period set to 3, the resulting mean is (4 + 8 + 3) / 3 = 5 price units. If the next completed observation has a true range of 6, the next window contains 8, 3 and 6. Its mean is 17 / 3, or approximately 5.67. The first range has been removed rather than retained through recursive smoothing. All values in this example are hypothetical and are not historical market observations.
Complete native indicator source
using System;
using cAlgo.API;
namespace cAlgo
{
[Indicator(IsOverlay = false,
AccessRights = AccessRights.None)]
public class ConfirmedSimpleTrueRangeMean : Indicator
{
[Parameter("Period", DefaultValue = 14, MinValue = 1)]
public int Period { get; set; }
[Output("TR Mean", LineColor = "SteelBlue",
Thickness = 2)]
public IndicatorDataSeries Result { get; set; }
public override void Calculate(int index)
{
// Exclude the currently forming candle.
if (index == Bars.Count - 1)
{
if (index > 0)
CalculateCompleted(index - 1);
Result[index] = double.NaN;
return;
}
CalculateCompleted(index);
}
private void CalculateCompleted(int index)
{
// Each of the Period ranges needs a prior close.
if (index < Period)
{
Result[index] = double.NaN;
return;
}
double sum = 0.0;
for (int j = index - Period + 1; j <= index; j++)
{
double high = Bars.HighPrices[j];
double low = Bars.LowPrices[j];
double priorClose = Bars.ClosePrices[j - 1];
// True range includes gaps from the prior close.
double tr = Math.Max(high - low,
Math.Max(Math.Abs(high - priorClose),
Math.Abs(low - priorClose)));
sum += tr;
}
// Simple arithmetic mean, not Wilder smoothing.
Result[index] = sum / Period;
}
}
}
Understanding the C# structure
The Indicator attribute creates a separate chart panel and specifies that the program does not need extra access rights. Period is an integer input with a minimum value of one and a default of fourteen. The output attribute defines an IndicatorDataSeries which stores one result for each chart bar. The Calculate method receives the index of the bar that cTrader is evaluating. Historical indices increase from the oldest available bar toward the newest, which is the opposite of the reverse indexing commonly used in MetaTrader examples.
CalculateCompleted checks the history requirement before accessing any price. A period of three needs three true ranges and an additional earlier closing price. Thus the earliest eligible index is three when indexing begins at zero. The inner loop starts at index minus Period plus one and ends at index inclusive. For every iteration it reads the high, low and preceding close, selects the largest of the three distances and adds it to the sum. Dividing by Period yields the result. Missing early observations are represented by double.NaN rather than an invented zero.
The direct summation is easy to audit and takes time proportional to Period for each evaluated bar. A rolling sum could improve performance for long lookbacks, but would require careful treatment of historical reloads and repeated calculation calls. This introductory version avoids that extra state. Recalculating the same completed bar from identical input prices produces the same value.
Installation in cTrader
Open the Algo workspace, create a new C# indicator named ConfirmedSimpleTrueRangeMean, replace its generated source with the full example, and build it. Address any messages in the compiler output. Add the indicator to a standard candlestick chart and temporarily set Period to three while checking the example. The line appears in a separate panel and reports quoted price units, not pips or money. To compare symbols with different price scales, a separate normalization rule may be needed. This source has not been compiled or executed in cTrader here.
Closed-bar confirmation and repainting
During a live candle, the high and low can change repeatedly. A volatility calculation that includes that candle would therefore be provisional. The implementation identifies the last chart bar and assigns double.NaN to its output. It also explicitly evaluates the preceding bar, so when a new bar is recognized the former live candle receives its completed value. Although the result is drawn at the previous candle's position, it was not available in confirmed form earlier. This matters when consuming the output in a cBot or when comparing historical plots with real-time observations.
The calculation uses no future price data and does not deliberately repaint finalized observations. Data-feed corrections, changes to session settings, or reconstructed chart bars can still change historical input prices. In addition, the final chart bar may remain excluded during a market closure until the platform recognizes a subsequent bar. Automated consumers should select the last completed index and check for NaN before applying any threshold.
Testing and limitations
First reproduce the sample manually or in a spreadsheet. Then check a gap upward, a gap downward, a previous close inside the current interval, a flat sequence, Period equal to one, and insufficient history. Observe the first tick of a new candle and verify that the forming bar stays blank. Compare the completed readings after a chart reload with identical data. The measure reports volatility magnitude, not whether the market is bullish or bearish. It can be influenced by session gaps and unusually large observations, and the simple average may change abruptly when a large range leaves the window. It does not include spread, liquidity, or execution costs. Test any proposed use against independent market data.
For alternative smoothing, pip normalization, volatility thresholds or cBot integration, contact our Custom cTrader indicator Development Services.
Risk disclosure: educational material only. Trading involves risk of loss. Hypothetical examples do not establish profitability.