OPEN-SOURCE SCRIPT

Candle Decomposition

已更新
The Candle Decomposition indicator shows the last 2 candles in detail, with 2 levels of lower timeframes (LTF).

In this way, you can keep oversight of history, while zooming in on the last and previous candle.
This tool is meant to be used in realtime, preferentially for intraday usage.


🔶 USAGE

In this example, on the current timeframe of 15 minutes, you see the 2 latest candles, visualized through dotted lines/boxes.
The first LTF level is set at 5 minutes, the second level at 15 seconds:
快照
(The 2 exclamation marks are just to emphasize this is the latest price which will be repainted)

The combination of 2 LTF's can be helpful in finding support/resistance levels.
These are taken in realtime, not in bar replay, so the outcome wasn't known in advance:快照
(blue lines were drawn manually)

After first testing resistance, the price went to the support area, bouncing back to an area of resistance and breaking it briefly.
Price turned back, and found support, after which resistance was tested once more:
快照

Support was again tested, after which resistance was clearly broken:
快照

A bit later (every time 1 candle further):
快照
快照
快照
快照


The following example shows 2 last candles with signs of indecision, but LTF candles show support and resistance areas:
快照


🔶 IMPORTANT

PP = TradingView Premium / Professional Plan
BEP = TradingView Basic / Essential / Plus Plan

This publication uses second-based TF's, which is only available for PP users.
To ensure a smooth experience for BEP users, we have disabled the setting "Premium/Professional Plan".

BEP users will get a warning when trying to use a second-based TF.

快照
If possible, BEP users should use non-second-based TF's.

PP users have to enable the setting "Premium/Professional Plan".


🔶 DETAILS


🔹 Timeframes

Most common timeframes can be used: 2W, W, 3D, 2D, D, 12h, 8h, 6h, 4h, 3h, 2h, 1h, 30min, 15min, 10min, 5min, 3min, 1min
When having the current chart timeframe at 1 of these TF's, you can set 1st and 2nd LTF. Choices are pré-set to ensure maximum usage of drawings:
快照

In the image above you'll see there are gaps between candles.
The script ensures that when there are no trades, instead of attaching the next bar next to the previous, it leaves the gap visible (which is more realistic).

More in detail you can see the gaps are preserved:
(compared between white -current TF- candles, and LTF candles)
快照
快照


🔹 Limitations

When on a Weekly TF, and 2nd LTF is set at 4h, all drawings have enough space:
快照
If we change the 2nd LTF to 2h, there isn't enough space for the second last candle, after which an orange coloured informational warning label will be shown:
快照

When current chart TF is not 1 of the encoded TF's, a red warning text will be shown:
快照

This script can be used using "Bar Replay", but very limited.
You can change the date ("Jump To..."), but "Play" is not advisable.


🔹 Code

This script uses string manipulation to convert inputs like "1 hour", "5 min", "5 sec" to usable timeframe strings like "60", "5" and "5S"



Since string manipulation consumes resources, these are place in local blocks.
While inputs always will be extracted, whether it is put in an if-block or not, the string manipulation only will be executed when condition is fulfilled, in this case when we are at the right timeframe.

In following example you'll always see the '1 sec' input, on every TF, but the string manipulation will only happen when we are at a 1 minute TF:


The "visible chart function" chart.right_visible_bar_time is used to reset everything when a new candle starts. This makes sure that when using "barstate.islastconfirmedhistory", the second last bar is used. Also all lines & boxes are automatically removed, starting with a fresh slate.



If boxes/lines end up before the first bar, or after the last bar, this can be messy.
To protect ourselves against it 2 techniques are used:

math.max(0, x) is used to make sure lines & boxes don't end up before the first bar,
isOK = index < last_bar_index is used to be sure that the width of 1 candle (here index) is not wider than the total of all bars (which is the same as last_bar_index)


🔶 SETTINGS

3 columns:
  • Current TF: This columns shows you the chart TF where LTF settings are applicable.
  • 1st LTF: set the timeframe of the first level LTF
  • 2nd LTF: set the timeframe of the second level LTF

    Colours can be set for 3 timeframes

版本注释
Typo fixed
Candlestick analysiseducationalmultitimeframe

开源脚本

本着真正的TradingView精神,此脚本的作者已将其开源,以便交易者可以理解和验证它。向作者致敬!您可以免费使用它,但在出版物中重复使用此代码受网站规则约束。 您可以收藏它以在图表上使用。

想在图表上使用此脚本?


LuxAlgo Dev: luxalgo.com
PineCoder: pinecoders.com

- We cannot control our emotions,
but we can control our keyboard -
更多:

免责声明