PROTECTED SOURCE SCRIPT
Mis à jour

Market Structure [keypoems]

6 456
This indicator displays Market Structure: Zones, Valid Pullbacks, Protected levels.

A PRO version with advanced features is in the works. It will display SNDRs and Origins automatically and other highly requested features.

The default mode of the indicator is to mark valid pullbacks if they are up-close candles for highs, down-close candles for low. If you prefer wick based zones, uncheck the relative setting in the options. For now wick based zones is EXPERIMENTAL and possibly inaccurate.

This indicator marks with labels and lines Market Structure in the timeframe of the chart (multi-timeframe will come, in the PRO version).

It marks pullback zones, valid pullback swings aka "valid" high/lows on the body close high/low not the highest/lowest swing point.

It marks protected high/lows.

It calculates the length of the last zone and can compute a simple risk/reward ratio given a risk amount.

Labels are customizable.

Debugged for a long time and it's now very accurate.

Changelog:

v12 up-close / down-close 3 candle swings done properly
v14 with labels
v19 swings do not consider opposite close candles
v119 v h/l finally almost right
v137 add debug boxes
v226 v h/l alternating but not tracking highest/lowest wince prev valid. almost.
v242 lowest_since_vh and highest_since_vl are now working
v279 debugging lines, lowest_since_vh inversed?
v298 the lowest_since_vh now move properly
v319 progress
v338 85% there i'd say.
v346 flags to hide stuff from settings
v363 track v h/l better but misses 1 candle counterfeits
v365 removed old comments
restart
reset to v15 (v76) (v75 has previous attempt)
v120 improvement to basic is_swing_high/low
v137 candidate vl tracking works
v139 valid low correct!
v144 valid high correct! now issue with max_bars_back
v159 all works on barlast!
v165 we got it!!!
v178 added some options and version 0.9dev is live
v181 renames
v182 v0.9.1dev create offset_last_swing
v185 fixed that new candidate vh/vl has to close above prev candidate not wick
v221 v0.9.2 draw line that decides if candidate v h/l becomes valid
v232 v0.9.3 drastically improved swing high/low correctness
v237 v0.9.4 fix candidate valid high/low bug when new candidate is not a swing
last sync'd valid h/l code v0.9.4
zero
v9 first prot h/l set on first valid high and low and we go from there
v20 zone high becomes protected high once protected low is breached. works for firsties.
v24 add spacing to different labels so they are visible. v0.1.1
v31 create first proper prot low if the high of a zone is closed above
v40 we drew the first protected low
v43 draw lines for protected low and zone high v0.1.2
v55 we now mark a proper continuation valid high above a zone high v0.1.3
v58 continuation high gets broken after a valid low in a bullish ms we have a new zone and new prot low v0.1.4
v62 properly delete prot low when new one is created
v74 protected lows are more than 1 should not be possible
v87 clean up swing highs and low arrays (port)
reduce protl to 1 single one
actually add zh/zl when new one is created v0.1.5
v91 use gpt 4o o flip the logic for when ms is bearish. almost there.
v122 tracking of protected low, continuation h/l improves v0.1.6
v126 MSS almost works perfectly. v0.1.7
v129 protected h/l logic starts to be close v0.1.8 (issue with 1st zone high after mss)
v135 protected h/l stable with fixed proper start v0.1.8
v142 draggable start of analysis (useful for internal ranges) v0.2
v156 cosmetic changes v0.2.1
v181 continuation lines appear v0.2.2
v183 protected high/low v0.3 fuhinally
v185 v0.3.1
v188 profile optimisation #1 (instantiate lines only once)
v218 add stoic style dotted line breaks for zone high/low v0.3.3
v252 bos lines almost perfect v0.4.0
v257 add option to hide bos/mss lines v0.4.1
v355 debugging protected low on continuations v0.5.0
v357 remove commented code
v376 fix one-off error on continuation for new protected highs v0.5.1
v386 size() == 0 issues fixed v0.5.2
v388 another size() fix v0.5.2a
v 391 max_bars_back to 1000
v393 v0.5.3 add options for colors bos/mss
v410 reworked options panel with inline and groups
v428 major fix for bos lines accuracy v0.6
v443 v0.7 vertical line with points/risk for 50% of last zone
v455 v0.7.1 risk calculation for half range of last zone
v464 v0.7.2 info box bottom right
v494 v0.8 can draw zone boxes if flag is on
v499 v0.8.1 neutral zone color options
re-add info box
add option for info box size
v537 v0.8.2 fix prot h/l mss problem in some scenarios. more robust now.
Notes de version
Latest change: v0.8.3 start time is optional, if not checked it defaults to 5000 bars in the past

This indicator displays market structure and valid high/lows the way Pac teaches them.

This indicator does not implement gap logic.

This indicator marks with labels and lines Market Structure in the timeframe of the chart.
It uses Pac style DFTX's insights.

It marks pullback zones, valid pullback swings aka "valid" high/lows on the body close high/low not the highest/lowest swing point.

It marks protected high/lows.

It calculates the length of the last zone and can compute a simple risk/reward ratio given a risk amount.

Labels are customizable.

Debugged for a long time and it's now very accurate.

Changelog:

v12 up-close / down-close 3 candle swings done properly
v14 with labels
v19 swings do not consider opposite close candles
v119 v h/l finally almost right
v137 add debug boxes
v226 v h/l alternating but not tracking highest/lowest wince prev valid. almost.
v242 lowest_since_vh and highest_since_vl are now working
v279 debugging lines, lowest_since_vh inversed?
v298 the lowest_since_vh now move properly
v319 progress
v338 85% there i'd say.
v346 flags to hide stuff from settings
v363 track v h/l better but misses 1 candle counterfeits
v365 removed old comments
restart
reset to v15 (v76) (v75 has previous attempt)
v120 improvement to basic is_swing_high/low
v137 candidate vl tracking works
v139 valid low correct!
v144 valid high correct! now issue with max_bars_back
v159 all works on barlast!
v165 we got it!!!
v178 added some options and version 0.9dev is live
v181 renames
v182 v0.9.1dev create offset_last_swing
v185 fixed that new candidate vh/vl has to close above prev candidate not wick
v221 v0.9.2 draw line that decides if candidate v h/l becomes valid
v232 v0.9.3 drastically improved swing high/low correctness
v237 v0.9.4 fix candidate valid high/low bug when new candidate is not a swing
last sync'd valid h/l code v0.9.4
zero
v9 first prot h/l set on first valid high and low and we go from there
v20 zone high becomes protected high once protected low is breached. works for firsties.
v24 add spacing to different labels so they are visible. v0.1.1
v31 create first proper prot low if the high of a zone is closed above
v40 we drew the first protected low
v43 draw lines for protected low and zone high v0.1.2
v55 we now mark a proper continuation valid high above a zone high v0.1.3
v58 continuation high gets broken after a valid low in a bullish ms we have a new zone and new prot low v0.1.4
v62 properly delete prot low when new one is created
v74 protected lows are more than 1 should not be possible
v87 clean up swing highs and low arrays (port)
reduce protl to 1 single one
actually add zh/zl when new one is created v0.1.5
v91 use gpt 4o o flip the logic for when ms is bearish. almost there.
v122 tracking of protected low, continuation h/l improves v0.1.6
v126 MSS almost works perfectly. v0.1.7
v129 protected h/l logic starts to be close v0.1.8 (issue with 1st zone high after mss)
v135 protected h/l stable with fixed proper start v0.1.8
v142 draggable start of analysis (useful for internal ranges) v0.2
v156 cosmetic changes v0.2.1
v181 continuation lines appear v0.2.2
v183 protected high/low v0.3 fuhinally
v185 v0.3.1
v188 profile optimisation #1 (instantiate lines only once)
v218 add stoic style dotted line breaks for zone high/low v0.3.3
v252 bos lines almost perfect v0.4.0
v257 add option to hide bos/mss lines v0.4.1
v355 debugging protected low on continuations v0.5.0
v357 remove commented code
v376 fix one-off error on continuation for new protected highs v0.5.1
v386 size() == 0 issues fixed v0.5.2
v388 another size() fix v0.5.2a
v 391 max_bars_back to 1000
v393 v0.5.3 add options for colors bos/mss
v410 reworked options panel with inline and groups
v428 major fix for bos lines accuracy v0.6
v443 v0.7 vertical line with points/risk for 50% of last zone
v455 v0.7.1 risk calculation for half range of last zone
v464 v0.7.2 info box bottom right
v494 v0.8 can draw zone boxes if flag is on
v499 v0.8.1 neutral zone color options
re-add info box
add option for info box size
v537 v0.8.2 fix prot h/l mss problem in some scenarios. more robust now.
v561 v0.8.3 start time is optional, if not checked it defaults to 5000 bars in the past
Notes de version
Changelog:

v0.8.4 add option to set line style for BOS/MSS lines
Notes de version
Changelog: v0.8.5 add 30/50% levels to zones (with option to hide)
Notes de version
Fix typo v0.8.5b
Notes de version
v0.8.6 option to choose the color of the valid h/l labels
option to choose the color of the protected h/l line
Notes de version
Changelog: v0.9.0 add option to turn on zone box new style
Notes de version
Changelog: v0.9.1 extend 30/50/70 lines in new style
Notes de version
Changelog:

v0.9.2 color for bullish/bearish zones color option
v0.9.3 add option for style of 30/50/70 lines
Notes de version
Changelog v0.10.0:

- Fixed annoying bug with initial out of screen zone extending to infinity
- Default zone look is now the restrained/boxed (if you want the previous one go to settings and un-ckeck it)
Notes de version
This release is experimental. You can now activate wick based zones by going in the settings.

No guarantees, possibly fails spectacularly in some market scenarios. I still can't validate if it's completely broken or not. Sometimes it does make sense.

Changelog:

- v0.11.0 EXPERIMENTAL: Initial work to support marking zones from wicks and not Valid high/lows (Pac logic)
Notes de version
Changelog v0.11.1:

- Name change in preparation of roll out of Market Structure [PRO]
- Improvements to wick based zone detection in continuations (still experimental).
Notes de version
Changelog v1.0.0:

- Major bug fixes and stability improvements
- Wick based zones fixes
- Proper initialisation that prevents indicator to vanish if initial candles don't retrace
- Protected high/low color/width/style configurable
- Changed continuation high/low labels
- Changed default mss/bos style
- Prevent max_bars_back errors

The old protracted look for zones and the option to extend zone lines has been removed. Do not upgrade if you relied on these features and do not plan to upgrade to the PRO version. This features (and much more) appear fixed and improved in the upcoming PRO version.
Notes de version
Changelog: v1.0.1 emergency fix color of bearish zones
Notes de version
Changelog v1.0.2:

- Major bugfix that should solve the chart being sometimes left empty (because of no immediate pullback at start time)
- Remove comments unused code
- Solve some initialization issues [reset]
- Fix bug on MSS for wick based zones where the protected levels were lost
- Port from upcoming PRO indicator feature drawing zones from zone start (and not from protected level).
Notes de version
Changelog v1.1.0:

- Robustness fixes that avoid indicator to go blank when it can't calculate the max_bars_back
- Work around 500 labels limit that would bug out and lose protected levels
- Tweak code so that proper protected levels are deleted.
- Persist continuation high/lows externally to labels (which max out at 500).
Notes de version
No major new features in this release but a lot of stability and maintainability fixes. Indicator looks the same but runs smoother and with less hiccups. Options screen has been streamlined and looks much better.

Changelog v2.0.6:
- Major cut of code to start rewrite
- Remove ph/pl labels
- Candidate high/lows are moved off labels
- Draw only one candidate high/low
- Major resolution of continuation high/lows simplified structures
- Options clean up
- Tiny bug to draw continuation high wick based
- Rework options ordering

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.