fikira

Candle Decomposition

fikira Wizard Telah dikemas kini   
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"

• str.contains(str , 'hour')  ? str.tostring(str.tonumber(str.replace(str, ' hour', '')) * 60)  :  str
• str.replace(input.string(  '5 sec',  '' , options=['5 sec',  '1 sec']), " sec", "S")  
• str.replace(str, " min", "")

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:
str = ''
if timeframe.period ==   '1'
    str  := str.replace(input.string(  '1 sec',  '' , options=['5 sec',  '1 sec']), " sec", "S") 
    // output -> "5S" or "1S" 

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.

chT   = timenow  >    chart.right_visible_bar_time   
•••
if chT 
    if barstate.islastconfirmedhistory
        f(4)
    if barstate.islast  
        f(2)

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
Nota Keluaran:
Typo fixed

LuxAlgo Dev: www.luxalgo.com
PineCoder: www.pinecoders.com

- We cannot control our emotions,
but we can control our keyboard -
Skrip sumber terbuka

Dalam semangat TradingView yang sebenar, penulis skrip ini telah menerbitkannya dengan menggunakan sumber terbuka supaya pedagang-pedagang dapat memahami dan mengesahkannya. Sorakan kepada penulis! Anda dapat menggunakannya secara percuma tetapi penggunaan semula kod ini dalam penerbitan adalah dikawalselia oleh Peraturan Dalaman. Anda boleh menyukainya untuk menggunakannya pada carta.

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.

Ingin menggunakan skrip ini pada carta?