Polarity Divergences


This indicator looks at the polarity of the intrabars composing a chart bar and fills chart candles orange when a majority of intrabars does not have the same polarity as that of the chart bar.


Bar polarity

By bar polarity, we mean the direction of a bar, which is determined by looking at the bar's close vs its open.


Intrabars are chart bars at a lower timeframe than the chart's. Each 1H chart bar of a 24x7 market will, for example, usually contain 60 bars at the lower timeframe of 1min, provided there was market activity during each minute of the hour. Mining information from intrabars can be useful in that it offers traders visibility on the activity inside a chart bar.

Lower timeframes (LTFs)

A lower timeframe is a timeframe that is smaller than the chart's timeframe. This script determines which ​LTF to use by examining the chart's timeframe. The ​LTF determines how many intrabars are examined for each chart bar; the lower the timeframe, the more intrabars are analyzed. This table shows which ​LTF is used for each range of chart timeframes:
    Chart TF       ​LTF

     <   1D        1min
     <   1W        30min
     >=  1W        1D


The idea underlying this indicator is that if the polarity of a chart bar is up or down, the majority of its constituent intrabars should also be up or down. If that is not the case, then we can consider the bar to be abnormal, and so worthy of our attention. You will notice that such anomalies often occur before reversals, but irregularities do not necessarily announce reversals, as they also occur on pauses in trends or in trend-less conditions.

The indicator will update in real time, as intrabars composing the realtime chart bar are gradually built. The closer the realtime bar is to being closed, the more reliable the result will be, as that is when the indicator can analyze the most intrabars.

█  NOTES FOR Pine Script™ CODERS

This script uses the recently released request.security_lower_tf() Pine Script™ function discussed in this blog post. It works differently from the usual in that it can only be used at LTFs, and it returns an array containing one value per intrabar. This makes it much easier for programmers to access intrabar information.

A script can access a maximum of 100K intrabars; that is the reason we step the ​LTF by taking into account the chart's timeframe. By progressively increasing the ​LTF as the chart's timeframe increases, we provide users with optimal coverage of the chart bars. Always using a 1min ​LTF would, for example, limit the chart coverage to the last 69 bars on a 1D chart of a 24x7 market because each chart bar will usually contain 1440 intrabars (100K / 1440 = 69.4). By using a 30min ​LTF for 1D charts, we cover 100K / 48 = 2083 bars.
Notas de Lançamento: v2

Added option to plot a character above or below the bar on divergences.

Get $30 worth of TradingView Coins for you and a friend:

Read more about the new tools and features we're building for you:
Script de código aberto

Dentro do verdadeiro espírito TradingView, o autor deste script publicou ele como um script de código aberto, para que os traders possam compreender e checar ele. Um viva ao autor! Você pode usá-lo gratuitamente, mas a reutilização deste código em uma publicação é regida pelas Regras da Casa. Você pode favoritá-lo para usá-lo em um gráfico.

Aviso legal

As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.

Quer usar esse script no gráfico?