OPEN-SOURCE SCRIPT

Stochastic Average (2 TFs)

58
“Stoch (2 TFs)” plots two separate Stochastic oscillators from two different timeframes in a single pane and adds an average line of all four values (%K and %D from each timeframe). It is designed to quickly compare short-term vs higher-timeframe momentum and see whether they are aligned or diverging.

The script is an overlay-off oscillator, so it appears in its own window under the price chart.

How it works

The indicator calculates a classic Stochastic (%K and %D) on two user-selectable timeframes:

tf1 (default 30 minutes)

tf2 (default 60 minutes)

For each timeframe it:

Requests the high, low and close series from that timeframe using request.security.

Computes %K as the smoothed position of the close within the lookback high/low range.

Computes %D as a moving average of %K.

So you get four lines in total:

K1 and D1 from timeframe 1

K2 and D2 from timeframe 2

A small table in the top-right of the pane shows which timeframes are currently selected for TF1 and TF2, so you always know what you are looking at even if you change the chart timeframe.

Inputs

%K Length – lookback period used to find highest high and lowest low.

%K Smoothing – smoothing length for the %K line.

%D Smoothing – smoothing length for the %D line.

30 (tf1) – first Stochastic timeframe (default 30m).

%K Color (1) / %D Color (1) – colors for K1 and D1.

60 (tf2) – second Stochastic timeframe (default 60m).

%K Color (2) / %D Color (2) – colors for K2 and D2.

Average Color – color for the current bar average line.

Average Prev Color – color for the previous-bar average line.

You can put this indicator on any chart timeframe; the internals always use the two selected timeframes via request.security.

Visual elements

The pane shows:

Four Stochastic lines:
K1 and D1 (for tf1), K2 and D2 (for tf2), using the input colors.

Three horizontal reference levels:
80 (upper band), 50 (middle), 20 (lower band).

A light blue background band between 80 and 20 to make the overbought/oversold zone easier to see visually.

A 2-cell table in the top-right with the current values of tf1 and tf2.

These elements make it easy to see when each timeframe is overbought, oversold, or in the middle zone, and whether the two timeframes are synchronized or showing divergence.

Average and previous-average lines

At the bottom of the script there is a simple composite measure:

Sum KD adds K1 + D1 + K2 + D2 and divides by 4.

Prev Sum KD does the same for the previous bar ([1]).

Both are plotted as separate lines:

Sum KD – current bar average of all four Stochastic values (main composite).

Prev Sum KD – previous bar average (for comparison).

This makes it easy to see whether overall multi-timeframe Stochastic momentum is increasing or decreasing from bar to bar without having to visually average four separate curves.

How to use

Typical uses:

See short- vs higher-timeframe Stochastic at a glance and trade only when they agree.

Look for divergence between TF1 and TF2 (e.g., lower timeframe overbought while higher timeframe still neutral).

Use the average lines (Sum KD and Prev Sum KD) as a simple “multi-TF momentum gauge” for confirmations or filters.

면책사항

해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.