Bull/Bear Candle % Oscillator

SolCollector Güncellendi   

This script determines the proportion of bullish and bearish candles in a given sample size. It will produce an oscillator that fluctuates between 100 and -100, where values > 0 indicate more bullish candles in the sample and values < 0 indicate more bearish candles in the sample. Data produced by this oscillator is normalized around the 50% value, meaning that an even 50/50 split between bullish and bearish candles makes this oscillator produce 0; this oscillator indirectly represents the percent proportion of bullish and bearish candles in the sample (see HOW TO USE/INTERPRETATION OF DATA).

It has two overarching settings: 'classic' and 'range'.


This script will cover concepts related to candlestick analysis, volumetric analysis, and lower timeframes.

Candlestick Analysis - The idea behind this script is to solely look at the candlesticks themselves and derive information from them in a given sample. It separates candles into two categories, bullish (close > open) and bearish (close < open).

If the indicator's setting is set to 'classic', the size of candles do not matter and all are assigned a value of 1 or 0.

If the indicator's setting is set to 'range', specific candle ranges modify the proportion of bullish/bearish values. Bullish candle values include all bullish candles in the set from their lows to the close, plus the lower wicks of all bearish candles. Bearish candle values include all bearish candles in the set from their highs to the close, plus the upper wicks of all bullish candles.

Volumetric Analysis - One of this script's features allows the user to modify the bullish and bearish candle proportions by its 'weight' determined by its volume compared to the sample set's total volume. Volumetric analysis for the 'range' setting are more complex than 'classic' as described below.

Lower Timeframes - For volumetric analysis to be done on candle wicks, there needed to be a way to determine how much volume had occurred in the wick by itself to find the weight of upper and lower wicks. To accomplish this, I employed PineScrypt's request.security_lower_tf function to grab OHLC values of lower timeframe candles (as well as volume) to determine how much volume had occurred in the wicks of the chart resolution's candle. The default OHLC values used here are the lows for upper wicks and highs for lower wicks. These OHLC values are then compared to the chart resolution candle's close to determine if the volume of that lower timeframe candle should be shifted to the wick weight or stay in the current weight of that candle. The reason 'low' and 'high' are used here is to guarantee that 100% of the volume of a lower timeframe candle had occurred in the wick of the candle at the current resolution (see LIMITATIONS).

Bullish candles will exclude volume of all lower timeframe candles whose lows were greater than that candle's close. Bearish candles will exclude volume of all lower timeframe candles whose highs were less than that candle's close. These wick volumes are then divided by the volume of the sample set, and wick sizes are then multiplied by this weight before being added to their specific bullish/bearish sums (lower wicks to bullish and upper wicks to bearish).


There are 13 inputs for the user to modify the behavior/visual representation of this script.

Sample Length - This determines how many candles are in the sample set to find the proportion of bullish and bearish candles.

Colors and Invert Colors - There are three colors set by the user: a bullish color, neutral color, and bearish color. The oscillator plots two lines, one at 0 and another that represents the proportion of bullish or bearish candles in the sample set (we'll call this the 'signal line'). If the oscillator is above 0, bullish color is used, bearish otherwise. This script generates a gradient to color a filled area between the 0 line and the signal line based on the historical values of the oscillator itself and the signal line. For bullish values, the closer the signal line is to the max (or restricted max described below) that the oscillator has experienced, the more colored toward bullish color the shaded area will be, using the neutral color as a starting point. The same is applied to the bearish values using the bearish color.

There is an additional input to invert the colors so that the bearish color is associated with bullish values and vise-versa.

Calculation Type - This determines the overarching behavior of the oscillator and has two settings:
  • Classic - The weight of candles are either 1 if they occurred and 0 if not.
  • Range - The weight of candles is determined by the size of specific sections as described in CONCEPTS - Candlestick Analysis.

Volume Weighted - This enables modifying the weights of candles as described in CONCEPTS - Volumetric Analysis and Lower Timeframes based on which Calculation Type is used.

Wick Slice Resolution - This is the lower timeframe resolution that will be used to slice the chart resolution's candle when determining the volumetric weight of wicks. Lower timeframe resolutions like '1 minute' will yield more precise results as they will give more data points to go off of (see LIMITATIONS).

Upper/Lower Wick Source - These two inputs allow the user to select which OHLC values to compare against the chart resolution's candle close when determining which lower timeframe candles will have their volumes associated with the wicks of candles being analyzed at the chart's resolution.

Restrict Min/Max Data and Restriction - This will restrict the maximum and minimum values that will be used for the signal line when comparing its value to previous oscillator values and change how the color gradient is generated for the indicator. Restriction is the number of candles back that will determine these maximum and minimum values.

Display Min/Max Guide - This will plot two lines that are colored the corresponding bullish and bearish colors which follow what the maximum and minimum values are currently for the oscillator.


As mentioned in the OVERVIEW section, this oscillator provides an indirect representation of the percent proportion of bullish or bearish candles in a given sample. If the oscillator reads 80, this does not mean that 80% of all candles in the sample were bullish. To find the percentage of candles that were bullish or bearish, the user needs to perform the following:

50% + ((|oscillator value| / 100) * 50)%

If the oscillator value is negative, the value from above will represent the percentage of bearish candles in the sample. If it is positive, this value represents the percentage of bullish candles in the sample.

Example 1 (oscillator value = 80):

50% + ((|80| / 100) * 50)%
50% + ((0.80) * 50)%
50% + 40% = 90%

90% of the candles in the sample were bullish.

Example 2 (oscillator value = -43):

50% + ((|-43| / 100) * 50)%
50% + ((0.43) * 50)%
50% + 21.5% = 71.5%

71.5% of the candles in the sample were bearish.

An example use of this indicator would be to put in a 'buy' order when its value shows a significant proportion of the sampled candles were bearish, and put in a 'sell' order when a significant proportion of candles were bullish. Potential divergences of this oscillator may also be used to plan trades accordingly such as bearish divergence - price continues higher as the oscillator decreases in value and vise-versa.*

*Nothing in this script constitutes any form of financial advice. The user is solely responsible for their trading decisions and I will not be held liable for any losses or gains incurred with the use of this script. Please proceed with caution when using this script to assist with trading decisions.


Range Volumetric Weights:

Because of the conditions that must be met in order for volume to be considered part of wicks, it is possible that the default settings and their intended reasoning will not produce reliable results. If all lower timeframe candles have highs or lows that are within the body of the candle at the chart's resolution, the volume for the wicks will effectively be 0, which is not an accurate representation of those wicks. This is one of the reasons why I included the ability to change the source values used for these conditions as certain OHLC values may produce more reliable/intended results under these conditions.

Wick Slice Resolution:

PineScript restricts the number of intrabar references to 100,000 total. This script uses 3 separate request.security_lower_tf calls and has a default resolution of 1 minute. This means that if the user were to set the oscillator to the Range setting, enable volume weighted, and had the Wick Slice Resolution set to 1 minute, this script will exceed this 100,000 reference restriction within 24 days of data and will not produce any results beyond the previous 23.14 days.

Below are example uses of all the different settings of this script, these are done on the 1D chart of BTCUSD :

Default Settings:

Classic - Volume Weighted:

Range - no Volume Weight:

Range - Volume Weighted (1 min slices):

Range - Volume Weighted (1 hour slices):

Display Min/Max Guide - No Restriction:

Display Min/Max Guide - Restriction:

Invert Colors:

Sürüm Notları:
Updated functionality: Added a method to convert the normalized value into the true percent value.

User may now plot a line that represents the true percentage of bullish and bearish candles in the sample, instead of just the normalized value shown by the "Bull/Bear ± % Line"

The color of the line is independent of the 'Invert Color' settings and will correspond to 'Bull Color' and 'Bear Color', switching between the two to match which type of candles appeared more often.

Usage Example:

Sürüm Notları:
Minor proofreading/consistency issue fixes

I build open-source indicators, help support my work:

BTC: 3GJFVgbxWLZjbupSEDifqouKSw1DsQytDP
ETH/USDC: 0x8a9915B9281F72C08f0274049028bdD89cF76Fd3
LTC: MFX9qvAvMvz9rRC3o9QchzH1rP4woGSmv2
Açık kaynak kodlu komut dosyası

Gerçek TradingView ruhuyla, bu betiğin yazarı, yatırımcının anlayabilmesi ve doğrulayabilmesi için onu açık kaynak olarak yayınladı. Yazarın eline sağlık! Bunu ücretsiz olarak kullanabilirsiniz, ancak bu kodun bir yayında yeniden kullanımı Kullanım Koşulları ile yönetilir. Bir grafikte kullanmak için favorilere ekleyebilirsiniz.


Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.

Bu komut dosyasını bir grafikte kullanmak ister misiniz?