TradingView
SimpleCryptoLife
4 de Oct. de 2020 22:15

[SCL] True Market Structure 

Bitcoin / TetherUSBinance

Descripción

See market structure at a glance with Higher Highs and Lower Lows. Bullish/Bearish/Ranging market bias is automatically derived. Optionally get alerted for breaks in market structure. Uses true Local Highs/Lows instead of simply the highest/lowest "pivot" for x bars. Can be useful as a support for learning market structure or for alerts for a change in structure while you're not at the computer.

Notas de prensa

Fixed some broken logic. It confirms Highs and Lows better now. This is why you keep the debug handy, kids.

Notas de prensa

Updated comments to match the fixed functions.
Note to the Pinescripters: I was having problems accessing past states of variables within functions using [1], which is why you'll see the workaround with variable_1, passing in a hardcoded [1].

Notas de prensa

Fixed a case where we could confirm fractals out of sequence.
Added a new setting: "Use Short Label Text"; off by default. This makes the label text much shorter and people will probably prefer it after they get used to the indicator.
Removed the setting to display market bias in labels, because it's superseded by the new setting.

Note about rogue wicks
If we get a candle with a high wick but a normal close, after a Local High but before that Local High is confirmed by the appropriate close, the high wick will never be counted as a Local High, even if it ends up coming in sequence after a Local Low.
Basically, candidates for Local Highs are only accepted AFTER the previous Local High is confirmed (or on the very same bar), and I'm probably going to keep it that way. Not only would it be extremely time-consuming to code and test doing it differently, I'm not convinced it would be the right thing to do.
Same thing goes for Lows.
This case is quite rare (I don't even have a screenshot handy). Also, note that forcing confirmations with a low number could change this behaviour and confirm the wick.
For any other cases where you think the script isn't picking out Highs and Lows correctly, please do drop a comment with a screenshot of the chart and your current settings.

Notas de prensa

Fixed the spelling on the short label text. Hat tip to @crossc for letting me know

Notas de prensa

Simplified the display mode inputs. There's only one colour scheme now, which is according to market bias. I think that's more useful than just red/green.

Added a minimalist mode, because having all the labels displayed when using the indicator regularly cluttered up the chart a bit. This mode only shows the most recent High and Low (the code that deletes old labels might be interesting if you need to script with labels printed in arbitrary locations). The defaults are the same as before.

Notas de prensa

Added a new display option. You can show only those breaks in market structure that are reversals, or you can show both reversal and continuation breaks.

For fun: find an asset that trends nicely and hide everything except reversal breaks.

Notas de prensa

Attempting to fix a user-reported issue with Bearish Breaks.

Notas de prensa

+ Added a label to show the current market bias, with three settings: Short Text, Full Text, and Off. The label is coloured according to the bias.

+ Added an option to fill the background with the market bias colour.

With the range of visualisations now available, you can see market structure in as much or as little detail as you want, with the best chance of avoiding visual conflict with whatever other indicators you might be using.

+ Fixed the market bias to be set properly on breaks. Needed now it's more visible!

+ Increased the maximum number of labels shown to 100. If you want to do historical analysis, you can increase this number up to the system limit of 500 manually.

+ Added lines that show where price needs to close in order to flip market bias to bullish or bearish. You *could* also add lines to show the close needed to flip to ranging. If people want this feature I might add it.
NOTE: This feature repaints in the sense that it extends the line back in time to the High or Low that set that price.
Importantly, it can change intra-candle. A candle close is needed to confirm a Local High/Low, and while a candle is open it uses the current price as the "working close". So if we are in the very first candle of a changed market bias, the most recent Local High/Low is actually waiting for the current candle to close in order to be confirmed. If the current candle then reverses, the line will revert back to using the previously confirmed High/Low. Although this looks jarring when it happens, it's technically correct. Coding it to always use a High/Low that's confirmed on close instead is probably not worth the effort and would be less useful most of the time. The general principle is the same as for most indicators - for the current candle, Things Can Change until it's closed.

If you have questions, please read the full description of the settings in the top part of the script first.

Notas de prensa

New feature: Option to display the break of the line that shows where a close would need to be in order to break the current market structure. Thanks to user @Meshidorin for the suggestion.
Updated the colours so that you won't get compilation warnings from TradingView because of the impending deprecation of "transp".

Notas de prensa

Thanks to @dalescher for a fix to the price on the label for the price needed for a bullish or bearish break

Notas de prensa

Minor update: Fixed the alert text for Breaks.

Notas de prensa

Added max_bars_back=500 to get around the issue where keeping the last two labels only wasn't working.
Hopefully this addition doesn't cause any other problems.

Notas de prensa

Updated to v5.
Fixed a bug where the break line was not getting displayed if the High/Low was very far away. This may uncover other bugs in dealing with edge cases.
Speaking of bugs, I can't figure out why the label offset isn't working, so if anyone knows how to fix that, do comment.

Notas de prensa

I've tried many ways of getting the labels to display in the future. All of them *should* work, and they all seem to sort of work, in that the label displays further in the future the higher you set the input, but it never exactly matches. For example, for certain values of input, the labels don't move.
If anyone has a method that compiles and is tested not to have this problem, do let me know.
Comentarios
carnagecain
Little confused how this isn't an Editor's pick or significantly more popular...or that I somehow have just discovered it. Great job man!
SimpleCryptoLife
@carnagecain, Thank you very much!
robertttme
I really love this indicator great for learning market structure , a quick question
if i use intraday day trading stocks , and i use 5 min chart and 1 min , can i keep the same settinngs for hh and ll , im asking because before i found your awsome code , i was using a different hh and ll and i think the setting were something around 5 candles , and was giving me more hh and ll , im asking because just want to make sure im using it in a good way , any explains is well welcome , thank you
SimpleCryptoLife
@robertttme, Thanks. I can't comment specifically about your assets or timeframe. It sounds like the one you were using before was finding highs and lows using standard pivots - i.e. highest high/lowest low out of the most recent 5 bars. This type of indicator (which is most of the market structure ones) will give different results to mine. Not necessarily better or worse, but different. You can see from the comments that my script waits for a close beyond the High/Low. These confirmed Local Highs and Lows tend to be more solid support/resistance, and can confirm more quickly or more slowly than standard pivots. For more understanding there's no substitute for hours behind the charts ;-)
juledg
Hi. I really appreciate this code.

I was wondering if there was any way possible to add a feature to this (Or be its own stand alone indicator) that could show the trend of multiple TFs on the chart in a table? I like trading the 5m charts but need to see if the 1h, 4h and 1d align. Would be great to do that in 1 window rather than having to check 4 windows.

Thank you!
SimpleCryptoLife
@juledg, Thanks for your appreciation. Yes, that would be nice ;-)
Multiple timeframes is a bit tricky to really get correct (see my various timeframe libraries for a full discussion). I didn't write this code with multiple timeframes in mind, so it would be even trickier.
scarf
Superb indicator, thank you!
SimpleCryptoLife
@scarf, Thanks for your encouragement!
robertttme
After few days trading with this great code I don't if I can do it without it , a quick question would it be possible to add an adjustment for color at HH and LL, HL, I mean for all the marks above the candles , a color adjustment and size?
SimpleCryptoLife
@robertttme, Glad you're getting use out of it. You can make the label size a bit smaller by choosing Short Text in the settings. The colour is linked to the market bias at the time. I don't think I'm going to add an override setting. But you're free to copy the script for your own use and update any of the colours or sizes. Just search the code for "color=" and "size=". The title element identifies what each plot is.
Más