Pine Script Qstick

Master this unique momentum indicator in TradingView's Pine Script that quantifies the strength of candlestick bodies to reveal underlying buying and selling pressure.

Subscribe now @ $99/month

What is Qstick?

Qstick is a technical indicator that measures the market's internal momentum by quantifying the strength and direction of candlestick bodies over a specified period. Developed by Tushar Chande and Stanley Kroll, Qstick essentially calculates the Simple Moving Average (SMA) of the difference between the closing price and the opening price of each candlestick. A positive Qstick value indicates that candlesticks are closing higher than they open on average, suggesting bullish momentum. Conversely, a negative value indicates bearish momentum.

In Pine Script, Qstick is a valuable tool for traders seeking a smoothed view of real body momentum, helping to identify trend changes, confirm direction, and spot divergences without the noise often found in pure price oscillators.

Components and Calculation

The calculation of Qstick is straightforward:

  1. Individual Bar Difference (C-O): For each bar, calculate `Close - Open`. This represents the "body" of the candlestick. A positive value means a bullish candle; a negative value means a bearish candle.
  2. Qstick Formula: Calculate the Simple Moving Average (SMA) of these `(Close - Open)` differences over a specified `length` (e.g., 10 periods).
    `Qstick = SMA( (Close - Open), length)`

The resulting Qstick value oscillates around a zero line. Values above zero suggest increasing bullish momentum from candlestick bodies, while values below zero suggest increasing bearish momentum.

Basic Qstick Implementation in Pine Script

Pine Script v5 provides a convenient built-in function `ta.qstick()` for calculating Qstick.

//@version=5
indicator("My Qstick Indicator", overlay=false) // overlay=false to plot in a separate pane

// Input for Qstick length
length = input.int(10, title="Qstick Length", minval=1)

// Calculate Qstick value using the built-in function
qstickValue = ta.qstick(length)

// Plot the Qstick line
plot(qstickValue, title="Qstick", color=color.blue, linewidth=2)

// Plot the Zero Line
hline(0, "Zero Line", color.gray, linestyle=hline.style_solid)

// Optional: Add bands for visual reference, although Qstick is unbounded
// (These bands are illustrative and depend on historical observation for the asset)
// hline(avg(abs(qstickValue), 50), "Upper Ref", color=color.red, linestyle=hline.style_dashed)
// hline(-avg(abs(qstickValue), 50), "Lower Ref", color=color.green, linestyle=hline.style_dashed)
Candlestick Body Focus: Qstick filters out the noise from wicks and focuses solely on the strength of the candle's real body, providing a smoother momentum signal.

Practical Qstick Trading Strategies

1. Zero Line Crossover (Momentum Shift)

The most common and straightforward strategy with Qstick involves its crossovers of the zero line. This signals a shift in the dominant candlestick body momentum.

//@version=5
strategy("Qstick Zero Line Crossover Strategy", overlay=true)

// Input for Qstick length
length = input.int(10, title="Qstick Length", minval=1)
zeroLine = 0.0

// Calculate Qstick
qstickValue = ta.qstick(length)

// Plot Qstick in a separate pane for visualization
plot(qstickValue, "Qstick", color.blue, display=display.pane_only)
hline(zeroLine, "Zero Line", color.gray, linestyle=hline.style_solid, display=display.pane_only)

// Define conditions for entries
longSignal = ta.crossover(qstickValue, zeroLine)
shortSignal = ta.crossunder(qstickValue, zeroLine)

// Strategy entries/exits
if (longSignal)
    strategy.entry("Long", strategy.long)

if (shortSignal)
    strategy.entry("Short", strategy.short)

2. Trend Confirmation and Strength

The magnitude of Qstick can confirm the strength of a trend. Consistently positive and rising Qstick values confirm a strong uptrend, while consistently negative and falling values confirm a strong downtrend.

//@version=5
strategy("Qstick Trend Strength Confirmation", overlay=true)

length = input.int(10, title="Qstick Length", minval=1)

qstickValue = ta.qstick(length)

plot(qstickValue, "Qstick", color.blue, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_solid, display=display.pane_only)

// Using a simple threshold for strength, adjust based on asset
bullishStrengthThreshold = input.float(0.5, title="Bullish Strength Threshold", step=0.1)
bearishStrengthThreshold = input.float(-0.5, title="Bearish Strength Threshold", step=0.1)

// Long entry: Qstick is positive and above a certain strength threshold
longConfirm = qstickValue > bullishStrengthThreshold and qstickValue > qstickValue[1]

// Short entry: Qstick is negative and below a certain strength threshold
shortConfirm = qstickValue < bearishStrengthThreshold and qstickValue < qstickValue[1]

if (longConfirm)
    strategy.entry("TrendLong", strategy.long)

if (shortConfirm)
    strategy.entry("TrendShort", strategy.short)

// Example exit: if Qstick crosses zero or reverses strongly
strategy.close("TrendLong", when=qstickValue < 0)
strategy.close("TrendShort", when=qstickValue > 0)

3. Qstick Divergence Strategy

Divergence between price and Qstick can be a powerful early warning signal for trend reversals, as it suggests that the underlying momentum from candlestick bodies is weakening even if price continues its current path.

//@version=5
indicator("Qstick Divergence Scanner", overlay=true)

length = input.int(10, title="Qstick Length", minval=1)

qstickValue = ta.qstick(length)

plot(qstickValue, "Qstick", color.blue)
hline(0, "Zero Line", color.gray, linestyle=hline.style_solid)

// Simple divergence detection (conceptual, robust detection requires advanced pivot logic)
// This is a simplified example focusing on price vs Qstick divergence.

// Bullish Divergence (Price lower low, Qstick higher low)
bullishDivergence = close[2] > close[1] and close[1] > close and qstickValue[2] < qstickValue[1] and qstickValue[1] < qstickValue

// Bearish Divergence (Price higher high, Qstick lower high)
bearishDivergence = close[2] < close[1] and close[1] < close and qstickValue[2] > qstickValue[1] and qstickValue[1] > qstickValue

plotshape(bullishDivergence, title="Bullish Divergence", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(bearishDivergence, title="Bearish Divergence", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)

alertcondition(bullishDivergence, "Bullish Qstick Divergence", "Potential bullish reversal based on Qstick divergence.")
alertcondition(bearishDivergence, "Bearish Qstick Divergence", "Potential bearish reversal based on Qstick divergence.")

Optimizing Qstick Performance

To get the most from Qstick in Pine Script:

Smoothed Candle Momentum: Qstick offers a unique perspective by averaging the strength of bullish and bearish candlestick bodies, providing a clearer signal of who's in control on a bar-by-bar basis.

Common Qstick Pitfalls

Conclusion

Qstick is an insightful technical indicator in Pine Script for TradingView that offers a unique perspective on market momentum by quantifying the strength of candlestick bodies. By smoothing the difference between open and close prices, it helps traders identify shifts in underlying buying and selling pressure. Whether used for identifying trend changes through zero-line crossovers, confirming trend strength, or spotting powerful reversals through divergence, Qstick provides valuable insights into market dynamics. By understanding its calculation, thoughtfully tuning its parameters, and integrating it strategically with other technical analysis tools, you can leverage Qstick to enhance your trading decisions and gain a clearer understanding of market conviction.

Enhance Your Trading

Get a high-performance Pine Script analysis tool for actionable market insights, designed for traders on the move.

This strategy runs in live mode on TradingView, helping you identify potential opportunities.

Subscribe now @ $99/month