OPEN-SOURCE SCRIPT

Market structure

Cập nhật
Hi all!

This script shows you the market structure. You can choose to show internal market structure (with pivots of a default length of 5) and swing market structure (with pivots of a default length of 50). For these two trends it will show you:
• Break of structure (BOS)
• Change of character (CHoCH) (mandatory)
• Equal high/low (EQH/EQL)

It's inspired by "Smart Money Concepts (SMC) [LuxAlgo]" by LuxAlgo that will also show you the market structure.

It will create the two market structures depending on the pivots found. Both of these market structures can be enabled/disabled. The pivots length can be configured separately. The pivots found will be the 'base' of this indicator and will show you when price breaks it. When that happens a break of structure or a change of character will be created. The latest 5 pivots found within the current trends will be kept to take action on. The internal market structure is shown with dashed lines and swing market structure is shown with solid lines.

A break of structure is removed if an earlier pivots within the same trend is broken. Like in the images below, the first pivot (in the first image) is removed when an earlier pivot's higher price within the same trend is broken (the second image):
ảnh chụp nhanh

ảnh chụp nhanh

Equal high/lows have a pink zone (by default but can be changed by the user). These zones can be configured to be extended to the right (off by default). Equal high/lows are only possible if it's not been broken by price and if a later bar has a high/low within the limit it's added to the zone (without it being more 'extreme' (high or low) then the previous price). A factor (percentage of width) of the Average True Length (of length 14) that the pivot must be within to to be considered an Equal high/low. This is configurable and sets this 'limit' and is 10 by default.

You are able to show the pivots that are used. "HH" (higher high), "HL" (higher low), "LH" (lower high), "LL" (lower low) and "H"/"L" (for pivots (high/low) when the trend has changed) are the labels used.

This script has proven itself useful for me to quickly see how the current market is. You can see the pivots (price and bar) where break of structure or change of character happens to see the current trends. I hope that you will find this useful for you.

When programming I focused on simplicity and ease of read. I did not focus on performance, I will do so if it's a problem (haven't noticed it is one yet).

You can set alerts for when a change of character happens. You can configure it to fire on when it happens (all or once per bar) but it defaults to 'once_per_bar_close' to avoid repainting. This has the drawback to alert you when the bar closes.

TLDR: this is an indicator showing you the market structure (break of structures and change of characters) using swing points/pivots. Two trends can be shown, internal (with pivots of length of 5) and swing (with pivots of the length of 50).

Best of trading luck!
Phát hành các Ghi chú
- Use my new library 'MarketStructure' (tradingview.com/script/tqFlUGel-MarketStructure/)
- Bump Pine Script version to 6
Phát hành các Ghi chú
- Remove unused setting for alert frequency
- Fix tags
Phát hành các Ghi chú
- Add liquidation. The indicator will create lines and zones for spotted liquidity. It will draw a line (with dotted style) at the price level that was liquidated, but is will also draw a zone from that level to the bar that broke the pivot high or low price. If that zone is large the liquidation is big and might be significant. This can be disabled in the settings. You can also change the confirmation candles (that does not close above or below the pivot level) needed after a liquidation and how many pivots back to look at.

The lines and boxes drawn will have orange colors.

ảnh chụp nhanh

- Bump 'MarketStructure' to 4

- Remove the setting for 'Source'. Before you were able to set the source of structure changes. It will now always use the close value.
Phát hành các Ghi chú
- Bump 'MarketStructure' to 5 which contains buggfix for when a pivot with lower/higher price to cause an invalid break of structure
Phát hành các Ghi chú
- Change default pivot lengths to 5 and 15 (has been 5/50 and 3/15)
- Bump 'MarketStructure" to 7 which contains:
  • Add alerts to break of structure and equal high/low
  • Remove 'ChangeOfCharcterBroken'. Pivots are now cleared when a change of character happens. This means that no break of stucture or change of character can happen on a pivot that was befor the change of character.
  • To figure out if the current pivot was the latest of its type (high or low) the library now uses the last `bar_index`
Phát hành các Ghi chú
Change how the break of structure is drawn. Don't need to check if the pivot is the latest and only delete the ones on the 'wrong side'. Higher low price in a downtrend and lower high in an uptrend. This is possible through the bump of 'MarketStructure' to 8.

It changes the behaviour of a break of structure. The first image is how it used to be and the second is how it will be now:

ảnh chụp nhanh

ảnh chụp nhanh

As you can see the later pivot break is now shown as the break of structure (because it has the lowest price).

Hope this update finds you well, good luck trading!
Phát hành các Ghi chú
This update will keep pivots for change of characters if they are 'within' the break of that pivot and the pivot point itself. All pivots will be disabled (when a CHoCH happens) for break of structures. This will have the effect that low pivots in the bullish trends will now cause a CHoCH to a bearish trend, like this:

From this
ảnh chụp nhanh

To this
ảnh chụp nhanh

This will however also cause false CHoCHs like this:

From this
ảnh chụp nhanh

To this
ảnh chụp nhanh

As you can see in the images the indicator now creates a CHoCH to a bearish trend. This turns out to be false and causes a trend change back to bullish.

This is done through the library 'MarketStructure' that is now at version 9.

Hope that this change makes sense!
Phát hành các Ghi chú
- Add an area between the latest high and low pivot. This could be the current trading range of the pivots break some sort of structure, like a break of structure or a change of character. As it is now it's not taken into consideration if the latest high/low pivot has a structure break. I might be able to change this in the future, unfortunately not now though.
- Change back the default pivot length to 50 on the swing market structure.
Phát hành các Ghi chú
- Introduce the concept of "CHoCH+" also called Change of Character plus. Labels for a change of character can now have either the text "CHoCH" or "CHoCH+". A Change of Character plus is formed when price fails to form a higher high or a lower low before reversing. Note that a pivot that is created after the change of character might have a higher high or a lower low, thus not making the break a "CHoCH+". This is not changed after the pivot is found but is kept as is. This is done through the library 'MarketStructure'.
Phát hành các Ghi chú
This update will enable you to show statistics for CHoCH and BOS. You can edit the statistics shown in the new group 'STATISTICS'. You can define the number of years to show. Can be any number between 0-50. The shown statistics will be in different colors for the swing and internal trend. There will also be a short label saying 'I' or 'S'. The values will be bucketed into years and with this number can you define how many years back statistics for the number of change of characters and break of structures will be shown. Set to 0 to deactivate statistics. The years back defaults to 3 and is useful when setting different pivot lengths for 'internal' and 'swing' based on different timeframes. The text color will adapt to white/black depending on your theme.

I think that these statistics are very useful, I hope you think so as well (disable it if not).
Phát hành các Ghi chú
Tradingview just released screening with Pine Script! This is possible to do if you have a premium subscription. This my first take on enabling this because it's very useful to know if a ticker had a CHoCH or a BOS. You can screen for internal CHoCH and BOS and swing CHoCH and BOS. The plots that can be used for screening will be 0 when not true and -1/1 when active. So you can either use a value above/below 0 for a bullish/bearish CHoCH or BOS or crossing of 0 for both directions. You can configure the value 'keep' that will keep changes in market structure for this number of bars. For example if a change of character happens this will change the plot to -1 or 1 for this number of bars. So if you set this to 0 the change will only be active on the bar that it happened on.

This is a very fast take on this new feature but I think that it works good and provides value!
Phát hành các Ghi chú
- Fix bug setting internal BOS instead of swing BOS
marketstructurepriceactionsupportandresitanceTrend Analysis

Mã nguồn mở

Theo tinh thần TradingView thực sự, tác giả của tập lệnh này đã xuất bản dưới dạng nguồn mở để các nhà giao dịch có thể hiểu và xác minh. Chúc mừng tác giả! Bạn có thể sử dụng miễn phí. Tuy nhiên, bạn cần sử dụng lại mã này theo Quy tắc nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?

Thông báo miễn trừ trách nhiệm