PATTERNSMART / SIERRA CHART ACSIL ENGINEERING NOTE
Sierra Chart Efficiency Ratio Hysteresis: Confirmed-Bar Trend and Chop Regime Study in ACSIL
Level: Trading Tips | Sierra Chart ACSIL C++ | Standalone custom study, not an automated trading system
A one-threshold regime detector is often too eager to switch states. Suppose we call the market “trending” whenever an Efficiency Ratio (ER) exceeds 0.50, and “choppy” whenever it falls back below 0.50. A sequence such as 0.49, 0.51, 0.48, 0.52 produces four classifications from small changes around one number. This practical Sierra Chart ACSIL study adds a second threshold: it enters the trend regime only above a stricter level, but retains the prior regime until ER falls below a lower exit level. It also refuses to make a new decision on a still-forming candle.
Efficiency Ratio measures direction relative to path
ER is not a measure of future return or the probability of the next winning trade. Over a lookback of N bars it calculates the absolute net change divided by the total absolute path length: ER[t] = |Close[t]−Close[t−N]| / Σ from k=t−N+1 to t of |Close[k]−Close[k−1]|. A nearly one-way path has a ratio near one; a back-and-forth path that ends near where it started has a low ratio. The ratio is bounded between zero and one for normal data. When the denominator is zero, the study explicitly sets ER to zero rather than dividing by zero.
Here is a fully reproducible hypothetical ten-step example. Start with a close of 100 and apply the changes +1, −0.5, +0.5, +1, −0.5, +1, +0.5, −0.5, +0.5, +1. The close ends at 104, so the numerator is 4. The sum of absolute steps is 7, making ER=4/7≈0.571. Starting in CHOP, a 0.55 entry threshold would change the state to TREND after this completed bar. None of these numbers represent sampled market history or a backtest.

The two-threshold state machine: change less, explain more
Defaults are EnterTrend=0.55 and ExitTrend=0.35. CHOP is encoded as 0 and TREND as 1. If the prior state is CHOP, only a completed-bar ER ≥0.55 can initiate TREND. If the prior state is TREND, only ER ≤0.35 can end it. Values in between preserve the previous state. This is a path-dependent decision rule, not an extra smoothing average. It can reduce regime-label flicker without guaranteeing that a market stays trending once labeled.
| Closed ER | Prior state | New state | Interpretation |
|---|---|---|---|
| 0.20 | CHOP 0 | CHOP 0 | Below entry level |
| 0.38 | CHOP 0 | CHOP 0 | Between levels; keep previous state |
| 0.57 | CHOP 0 | TREND 1 | First acceptance at or above 0.55 |
| 0.49 / 0.42 | TREND 1 | TREND 1 | Below entry, still above exit |
| 0.34 | TREND 1 | CHOP 0 | Exit at or below 0.35 |
| 0.46 / 0.60 | CHOP 0 | CHOP then TREND | Needs another 0.55 entry |
Settings, plotted outputs and tuning trade-offs
| Setting/output | Default | Meaning and constraint |
|---|---|---|
| ER Lookback Bars | 10 | Net change and sum of absolute close-to-close changes across 10 bars; adjustable 2–200 |
| Enter Trend when ER >= | 0.55 | Strict entry threshold while the previous state is CHOP |
| Exit Trend when ER <= | 0.35 | Lower exit threshold while the previous state is TREND |
| Efficiency Ratio | 0–1 | Raw ER; zero if the path-length denominator is zero |
| Trend State 0/1 | 0 / 1 | Confirmed classification; an open last bar holds the previous confirmed state |
| Entry / exit plots | 0.55 / 0.35 | Threshold guides, not entry or stop orders |
Increasing the entry level to 0.65 makes regime entries rarer and generally later. Raising the exit level to 0.45 can make trend classification end earlier. Increasing the gap between entry and exit makes state changes less sensitive, but also increases the delay before classification reverses. A plot with fewer transitions is not automatically better for trading; test the relationship between state, market conditions and independently defined execution rules.
Complete Sierra Chart ACSIL C++ source
This one-file custom study uses the platform-native sierrachart.h header, SCDLLName, SCSFExport, SCStudyInterfaceRef, four Subgraph arrays and sc.AutoLoop=1. The GetBarHasClosedStatus() branch does not recalculate a new state for an incomplete candle, while historical completed bars are evaluated sequentially. It is not an auto-trading system and invokes no order placement functions. The code has been reviewed for API plausibility but has not been compiled against a real Sierra Chart installation; perform a local or remote build before using it.
// Sierra Chart ACSIL: closed-bar efficiency-ratio hysteresis
// Standalone study. No orders, fills, or external study IDs.
#include "sierrachart.h"
#include <cmath>
SCDLLName("PatternSmart Efficiency Ratio Regime")
SCSFExport scsf_PS_EfficiencyRatioHysteresis(SCStudyInterfaceRef sc)
{
SCSubgraphRef Efficiency = sc.Subgraph[0];
SCSubgraphRef TrendState = sc.Subgraph[1];
SCSubgraphRef EnterLevel = sc.Subgraph[2];
SCSubgraphRef ExitLevel = sc.Subgraph[3];
SCInputRef Lookback = sc.Input[0];
SCInputRef EnterTrend = sc.Input[1];
SCInputRef ExitTrend = sc.Input[2];
if (sc.SetDefaults)
{
sc.GraphName = "PS Closed-Bar ER Hysteresis";
sc.StudyDescription = "Confirmed-bar efficiency ratio and stable regime";
sc.AutoLoop = 1;
sc.GraphRegion = 1;
sc.ValueFormat = 3;
Efficiency.Name = "Efficiency Ratio";
Efficiency.DrawStyle = DRAWSTYLE_LINE;
Efficiency.PrimaryColor = RGB(34, 89, 207);
Efficiency.LineWidth = 2;
TrendState.Name = "Trend State 0/1";
TrendState.DrawStyle = DRAWSTYLE_LINE;
TrendState.PrimaryColor = RGB(18, 135, 83);
TrendState.LineWidth = 2;
EnterLevel.Name = "Trend Entry Threshold";
EnterLevel.DrawStyle = DRAWSTYLE_LINE;
EnterLevel.PrimaryColor = RGB(105, 70, 176);
ExitLevel.Name = "Trend Exit Threshold";
ExitLevel.DrawStyle = DRAWSTYLE_LINE;
ExitLevel.PrimaryColor = RGB(190, 64, 67);
Lookback.Name = "ER Lookback Bars";
Lookback.SetInt(10);
Lookback.SetIntLimits(2, 200);
EnterTrend.Name = "Enter Trend when ER >=";
EnterTrend.SetFloat(0.55f);
ExitTrend.Name = "Exit Trend when ER <=";
ExitTrend.SetFloat(0.35f);
return;
}
const int i = sc.Index;
const int length = Lookback.GetInt();
const float enter = EnterTrend.GetFloat();
const float leave = ExitTrend.GetFloat();
EnterLevel[i] = enter;
ExitLevel[i] = leave;
// Require ordered thresholds and a valid ER calculation window.
if (i < length || enter <= leave || leave < 0.0f || enter > 1.0f)
{
Efficiency[i] = 0.0f;
TrendState[i] = 0.0f;
return;
}
// Last bar can still be forming: hold previous confirmed values.
// On the next bar, Sierra Chart processes the newly closed bar.
if (sc.GetBarHasClosedStatus(i) == BHCS_BAR_HAS_NOT_CLOSED)
{
Efficiency[i] = Efficiency[i - 1];
TrendState[i] = TrendState[i - 1];
return;
}
// ER = absolute net price change / sum of stepwise changes.
const float netChange = fabsf(sc.Close[i] - sc.Close[i - length]);
float pathLength = 0.0f;
for (int k = i - length + 1; k <= i; ++k)
pathLength += fabsf(sc.Close[k] - sc.Close[k - 1]);
float er = pathLength > 0.0f ? netChange / pathLength : 0.0f;
if (er > 1.0f)
er = 1.0f; // Floating point rounding guard.
Efficiency[i] = er;
// Hysteresis prevents one-threshold flip-flopping.
const bool wasTrend = TrendState[i - 1] >= 0.5f;
bool isTrend = wasTrend;
if (!wasTrend && er >= enter)
isTrend = true;
else if (wasTrend && er <= leave)
isTrend = false;
TrendState[i] = isTrend ? 1.0f : 0.0f;
}
Implementation notes: confirmed bars and safe defaults
Automatic looping versus live unfinished input
AutoLoop processes the array index sc.Index one bar at a time. Completed history is recalculated sequentially, and the regime depends on the previous TrendState value. When the current index is still forming, GetBarHasClosedStatus returns BHCS_BAR_HAS_NOT_CLOSED and the code carries forward the last confirmed ratio and state. It does not manufacture a new transition based on provisional live input. On ordinary subsequent updates Sierra Chart will process the bar that has just closed. The held display at the far right is not a forecast.
Zero motion, warm-up and bad thresholds
The code returns a neutral state before sufficient history exists. It also requires 0≤exit
Install, build and audit the output
- Save the full C++ source, for example as PS_ERHysteresis.cpp, in the supported Sierra Chart ACSIL source location.
- Use Analysis → Build Custom Studies DLL (or the supported Remote Build workflow) and resolve any local version-specific compiler messages.
- Add PS Closed-Bar ER Hysteresis to a chart and verify the efficiency ratio, trend state, entry threshold and exit threshold in its separate graph region.
- Use N=10, entry 0.55 and exit 0.35, then manually check a synthetic sequence against the state-transition table above.
- Reproduce the hypothetical net change 4 over path 7 to obtain ER≈0.571 and an entry to TREND when starting from CHOP.
- Use a replay or live chart to observe a forming bar; verify that the state does not change until the bar has completed.
- Test a completely flat price path, short history, invalid threshold ordering, data reload and different chart periods.
Failure modes, regime limits and risk
ER captures close-to-close path efficiency, not depth, volume, order-flow imbalance or forward expected return. A directional market may reverse rapidly even while classified as trending. Hysteresis reduces label flicker but delays some regime changes. Historical closed bars can be fully recalculated; the last live bar is deliberately held, so interpretation requires attention to bar timing. Overnight sessions, data gaps and unusual price formats merit separate tests. This is a regime annotation utility, not an entry, exit or position-sizing system.
Interested in this free ACSIL indicator or trading concept and want to modify thresholds, alerts or the state engine? Our Custom Trading Software Development Services can help discuss extensions to your workflow.
Risk note: Every illustrated number is a hypothetical teaching example. The source has not been compiled on your Sierra Chart installation; it requires a build and independent verification. No profitability, hit rate or backtest result is represented or guaranteed. Trading involves risk of loss.