cTrader ATR-Buffered Range Breakout Indicator: Confirmed C# Signals and Full Source
Not every high above a recent range is a useful breakout. Some barely clear the boundary before falling back into congestion. This free cTrader Automate indicator adds a volatility-adjusted buffer to the prior range and waits for a finished candle before marking the first close through the resulting threshold. It is a chart study, not a cBot, and sends no orders.
Design: isolate the range and demand meaningful clearance
For candle t, the reference upper bound is Ut = max(Hight−N, …, Hight−1), with a symmetric lower bound Lt = min(Lowt−N, …, Lowt−1). The trigger prices are upper = Ut + m × ATRt−1 and lower = Lt − m × ATRt−1. The candle currently being evaluated does not alter its own threshold. ATR uses Wilder smoothing, calculated from true range, and the previous bar's completed ATR value.

Signal conditions
A long marker appears only when a completed close exceeds its buffered upper level and the preceding completed close was at or below its own upper level. The short rule is the mirror image below the buffered lower level. Markers are drawn on the completed candle only after the next candle has started. The latest live candle can display provisional channel lines but never a final marker on itself. The study has no trade entries, stops, exits, or broker execution logic.
Configuration and defaults
| Input | Default | Purpose |
|---|---|---|
| Range Length | 20 | Number of prior bars in the reference range |
| ATR Period | 14 | True-range smoothing horizon |
| ATR Buffer Multiplier | 0.30 | Volatility allowance beyond the high/low |
For example, if the previous 20-bar high is 105.00, completed ATR is 1.20 and the multiplier is 0.30, the upper trigger is 105.36. A finished close at 105.50 satisfies the upper-level comparison, but a marker also requires the previous finished close not to have already been above its prior trigger. These figures illustrate the formula; they are not market data.
Complete cTrader Automate C# source
Create a new C# custom indicator named PSATRBufferedRangeBreakout. The code uses the documented Indicator.Calculate(int index), IndicatorDataSeries, and built-in AverageTrueRange interfaces.
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
// Plots a prior-range threshold with a completed-bar ATR buffer.
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class PSATRBufferedRangeBreakout : Indicator
{
[Parameter("Range Length", DefaultValue = 20, MinValue = 5)]
public int RangeLength { get; set; }
[Parameter("ATR Period", DefaultValue = 14, MinValue = 2)]
public int AtrPeriod { get; set; }
[Parameter("ATR Buffer Multiplier", DefaultValue = 0.30, MinValue = 0)]
public double BufferFactor { get; set; }
[Output("Upper Trigger", LineColor = "Blue", PlotType = PlotType.Line)]
public IndicatorDataSeries Upper { get; set; }
[Output("Lower Trigger", LineColor = "Red", PlotType = PlotType.Line)]
public IndicatorDataSeries Lower { get; set; }
[Output("Confirmed Long", LineColor = "Green", PlotType = PlotType.Points)]
public IndicatorDataSeries LongSignal { get; set; }
[Output("Confirmed Short", LineColor = "Red", PlotType = PlotType.Points)]
public IndicatorDataSeries ShortSignal { get; set; }
private AverageTrueRange _atr;
protected override void Initialize()
{
_atr = Indicators.AverageTrueRange(AtrPeriod, MovingAverageType.WilderSmoothing);
}
public override void Calculate(int index)
{
Upper[index] = double.NaN;
Lower[index] = double.NaN;
LongSignal[index] = double.NaN;
ShortSignal[index] = double.NaN;
// Exclude the currently forming bar from all reference inputs.
if (index < Math.Max(RangeLength + 2, AtrPeriod + 2))
return;
double highest = double.MinValue;
double lowest = double.MaxValue;
for (int k = index - RangeLength; k < index; k++)
{
highest = Math.Max(highest, Bars.HighPrices[k]);
lowest = Math.Min(lowest, Bars.LowPrices[k]);
}
double buffer = BufferFactor * _atr.Result[index - 1];
Upper[index] = highest + buffer;
Lower[index] = lowest - buffer;
// Calculate only for bar index-1, once a successor bar exists.
// This prevents provisional intrabar breakout dots.
int closed = index - 1;
LongSignal[closed] = double.NaN;
ShortSignal[closed] = double.NaN;
if (closed > Math.Max(RangeLength + 2, AtrPeriod + 2) &&
!double.IsNaN(Upper[closed]) && !double.IsNaN(Upper[closed - 1]))
{
bool longCross = Bars.ClosePrices[closed] > Upper[closed] &&
Bars.ClosePrices[closed - 1] <= Upper[closed - 1];
bool shortCross = Bars.ClosePrices[closed] < Lower[closed] &&
Bars.ClosePrices[closed - 1] >= Lower[closed - 1];
if (longCross)
LongSignal[closed] = Bars.LowPrices[closed] - 3 * Symbol.PipSize;
if (shortCross)
ShortSignal[closed] = Bars.HighPrices[closed] + 3 * Symbol.PipSize;
}
}
}
}
Install, interpret and test
- Open cTrader Algo > Indicators > New and paste the full class into the C# editor.
- Build the indicator, correct any version-specific compiler messages, then attach it to a chart.
- Start with 20/14/0.30 and compare plotted trigger levels with manual calculations on several historical candles.
- Observe at least one live bar transition: the previous bar's signal can be finalized, whereas the current bar should not display a definitive marker.
- Test instruments with different spread structures, timeframes, sessions and volatility regimes; inspect gaps and sparse histories.
Limitations and trading risk
An ATR buffer filters very small excursions, not all false breakouts. Volatility spikes push the threshold further away, potentially reducing signals or delaying entries. Trendless markets can still produce repeated whipsaws. Historical completed-bar markers do not establish achievable fills, commissions, latency or risk-adjusted profitability. Crosses are not equivalent to executable orders. The indicator source has not been compiled in a user-specific cTrader installation; verify it before production use.
Interested in adapting this free indicator with alerts, session filters or custom risk logic? Our Custom Trading Software Development Services can help discuss a tailored implementation.