Advanced Trading Tutorial — Sierra Chart ACSIL C++ custom indicator development
Candlestick wicks are often interpreted one candle at a time. However, a long lower wick on a single bar cannot tell us whether the surrounding price action exhibits a persistent imbalance between upper and lower excursions. Counting candles with longer lower wicks offers one possible perspective, but treats very small and very large wicks equally. This tutorial develops an aggregate Wick Asymmetry Balance indicator that compares total lower-wick length with total upper-wick length over a fixed completed-bar window. A companion activity measure reports how much of the total observed high-low range consists of wicks. Together, these two outputs provide a more explicit description of candle geometry than an isolated rejection pattern, without assuming that candle geometry reveals the intentions of market participants.
Define two complementary measurements
For each valid candle, identify the upper edge of the body as the greater of its opening and closing prices. Identify the lower edge as the smaller of the two prices. The upper wick is the high minus the upper body edge; the lower wick is the lower body edge minus the low. Both quantities are nonnegative for consistent OHLC data. A doji can have wicks on either side, whereas a candle whose body occupies the full range has no wicks.
Sum upper-wick lengths across N completed bars to obtain U, and sum lower-wick lengths to obtain L. The signed balance is 100 times (L minus U) divided by (L plus U), provided the denominator is positive. A positive value means lower wicks contribute more total length, and a negative value means upper wicks contribute more. The endpoints are -100 and +100. The indicator assigns zero when there is no wick length at all. Importantly, this is a ratio of sums, not the average of each candle's individual imbalance ratio. Larger wick observations have more influence, which is an intentional property of the definition.
The second series, Wick Activity, divides total wick length by the sum of the high-low ranges of the same valid candles, then multiplies by one hundred. It ranges from zero to one hundred. A positive balance with low activity describes a window with relatively small wicks dominated by the lower side. The same balance with high activity describes a window in which wicks occupy a larger share of observed ranges. Neither measure estimates a probability of future price movement.
Worked example using three completed candles
Suppose the first candle has an upper wick of two price units and a lower wick of four. The second has an upper wick of three and a lower wick of one. The third has an upper wick of one and a lower wick of three. Upper lengths sum to six and lower lengths sum to eight. The balance equals 100 times (8 minus 6) divided by 14, or approximately +14.29. If each candle's body is 1.5 price units, the total high-low range is 14 plus 4.5, or 18.5. Wick Activity is therefore approximately 75.68%. Set Completed Bars to three to reproduce the example. The direction of each candle's body does not enter the formula; only its upper and lower edges are used.

For comparison, an entirely wickless window produces both balance and activity of zero. A window with equal positive upper and lower wick totals also produces zero balance but positive activity. Reading the two lines together distinguishes these cases, provided there is valid history. A window with all its wick length on the lower side has +100 balance even if the total wick length is small. Activity provides additional context for interpreting that extreme.
Complete ACSIL C++ source
#include "sierrachart.h"
SCDLLName("PatternSmart Wick Asymmetry Balance")
SCSFExport scsf_WickAsymmetryBalance(SCStudyInterfaceRef sc)
{
SCSubgraphRef Balance = sc.Subgraph[0];
SCSubgraphRef Activity = sc.Subgraph[1];
SCInputRef Length = sc.Input[0];
if (sc.SetDefaults)
{
sc.GraphName = "Wick Asymmetry Balance";
sc.StudyDescription =
"Signed aggregate wick imbalance and wick activity.";
sc.AutoLoop = 1;
sc.GraphRegion = 1;
Balance.Name = "Balance";
Balance.DrawStyle = DRAWSTYLE_LINE;
Balance.PrimaryColor = RGB(45, 95, 190);
Balance.DrawZeros = 1;
Activity.Name = "Wick Activity";
Activity.DrawStyle = DRAWSTYLE_LINE;
Activity.PrimaryColor = RGB(35, 145, 100);
Activity.DrawZeros = 1;
Length.Name = "Completed Bars";
Length.SetInt(20);
Length.SetIntLimits(2, 500);
return;
}
const int n = Length.GetInt();
sc.DataStartIndex = n;
const int i = sc.Index;
if (i < n)
{
Balance[i] = 0.0f;
Activity[i] = 0.0f;
return;
}
double upper = 0.0;
double lower = 0.0;
double ranges = 0.0;
// Use only preceding completed bars, not index i.
for (int j = i - n; j < i; ++j)
{
const double h = sc.High[j];
const double l = sc.Low[j];
const double o = sc.Open[j];
const double c = sc.Close[j];
const double top = o > c ? o : c;
const double bottom = o < c ? o : c;
// Exclude malformed OHLC observations.
if (h < top || l > bottom || h < l)
continue;
upper += h - top;
lower += bottom - l;
ranges += h - l;
}
const double wicks = upper + lower;
Balance[i] = wicks > 0.0
? static_cast<float>(100.0 * (lower - upper) / wicks)
: 0.0f;
Activity[i] = ranges > 0.0
? static_cast<float>(100.0 * wicks / ranges)
: 0.0f;
}
Build and install the study
Save the listing as a C++ source file in Sierra Chart's ACS_Source directory, then use Analysis and the Build Custom Studies DLL interface to compile the source through the available build process. Add the resulting Wick Asymmetry Balance study using the chart Studies window. The blue line represents signed balance, while the green line represents wick activity. Both plots deliberately show zero values after the data start index. Completed Bars defaults to twenty and is limited to the range two through five hundred. The implementation is designed for a single primary chart and uses standard ACSIL input, subgraph and automatic-loop interfaces. It has not been compiled in a Sierra Chart installation for this article; perform the local build and verify chart output before relying on it.
Closed-bar alignment and historical recalculation
ACSIL automatic looping supplies the chart index through sc.Index. At index i, the loop reads bars i-N through i-1. The current bar i is excluded deliberately, regardless of whether the study is being evaluated historically or during a realtime update. The output displayed at a particular chart position therefore describes its immediately preceding completed-bar window. This is an intentional one-bar alignment convention. The current forming bar cannot alter the output through its own high, low, opening or closing price. Once a new bar appears, the newly completed bar enters the window.
The DataStartIndex is set to N, the first position with enough preceding bars. Earlier output positions are initialized to zero and are not valid observations. Downstream studies should honor this warm-up requirement instead of treating initial zeros as evidence of a balanced market. The algorithm recalculates the sums directly at every evaluated index. It maintains no persistent counter that could be duplicated by repeated calls on the latest bar. It does not use future bars, negative array indices or a centered lookback. Historical corrections and changes to chart construction may nevertheless alter the underlying OHLC inputs.
Parameter choices and numerical safeguards
Short windows can respond rapidly to newly formed wicks but may be dominated by a single unusual candle. Longer windows reduce the influence of routine individual fluctuations, while potentially retaining an extreme observation long after its occurrence. The default twenty is a research starting point, not a universal optimum. The loop excludes malformed candles whose high or low is inconsistent with the open and close. Their ranges are also excluded from activity. If no valid positive range remains, both outputs are zero; data-quality monitoring should be handled separately if this distinction is material.
The calculation has linear work per evaluated bar and constant additional storage. It uses double precision for accumulated lengths and converts to the subgraph's floating-point output only at the end. This direct implementation is intended to be straightforward to audit. A rolling-sum optimization may be useful for very long histories, but should be tested against the direct implementation under recalculation, data correction and input changes.
Validation checklist
- Reproduce the three-candle example and confirm +14.29 balance and 75.68% activity.
- Test equal upper and lower totals, all-lower wicks, all-upper wicks and wickless bars.
- Verify the output does not change when only the current forming bar changes.
- Check that the first valid output occurs after N completed bars.
- Scale all prices by a positive constant and verify approximate invariance.
- Compare a complete historical recalculation with identical data and chart settings.
- Inspect missing history, malformed candles, session gaps and synthetic chart types separately.
Limitations and custom extensions
Wick lengths do not reveal the sequence in which trades occurred or prove that a market rejected a particular price. Gaps between bars are not included in high-low ranges, and liquidity, spread, volume distribution and execution costs are outside the calculation. An unusual price print can dominate the sums. A positive balance does not establish bullish continuation, just as a negative balance does not establish bearish continuation. If you would like to extend the indicator with session filtering, robust weighting or integration into a custom study, contact us through our Custom Sierra Chart indicator Development Services.
Trading involves risk of loss. The examples use hypothetical data and no claim of profitability is made. Verify compilation, data quality, calculation timing and any derived trading rules before using real capital.