MTF Trend Widget

This indicator identifies trends in multiple higher timeframes (D, W, M) and shows them in a widget off to the right of the chart.
It's meant to be used as an alternative filter for "trading with the trend." Typically people use moving averages of varying lengths for this (i.e. if over 200 MA it's an uptrend, etc.), but I wanted to see if it might be more effective to see if the higher timeframes were actually trending or not in a certain direction.
For the purposes of this indicator, an uptrend is defined as higher highs and higher lows. So if currently in a downtrend and the highs are broken, the indicator will flip to an uptrend because now we have a higher high. Vice versa for downtrends.
The user can choose the lookback period for defining these highs/lows (the pivot points ). A smaller lookback number will give you more frequent pivot points .
The user can toggle on visibility of all historical pivot points to make sure the frequency and placement of the swing highs/lows is to their liking.
The user can show the support/resistance lines of those most recent swing high/low points on the multiple timeframes as well.
When these lines are breached, that is when the trends change, so you can see if you are close to changing any longer term trends.
My hope is that this gives people a quick glance at the overall trend without having to cycle through different timeframes.
Note di rilascio: This update:
  • Optimizes the code for improved speed (with some coding help from @RozaniGhani-RG)
  • Allows the user to select which timeframes they want to view the trend information on instead of that being hard coded
  • Moves the information from the widget that was at the right of the chart to a table (upper right) for easier viewing at all zoom levels and to allow me to pass on the variable timeframe (which was not allowed on the widget)
  • Adds additional color options for support/resistance lines to give the user greater control over how they look

Hope you guys find it useful!
Note di rilascio: More speed optimization to limit the number of security calls. Allow for ability for user to reposition the table.
Script open-source

Nello spirito di condivisione promosso da TradingView, l'autore (al quale vanno i nostri ringraziamenti) ha deciso di pubblicare questo script in modalità open-source, così che chiunque possa comprenderlo e testarlo. Puoi utilizzarlo gratuitamente, ma il riutilizzo del codice è subordinato al rispetto del Regolamento. Per aggiungerlo al grafico, mettilo tra i preferiti.

Vuoi usare questo script sui tuoi grafici?


Thank for sharing.
f_getHTF() =>
ph = pivothigh(high, lookback, lookback)
pl = pivotlow(low, lookback, lookback)
highLevel = valuewhen(ph, high, 0)
lowLevel = valuewhen(pl, low, 0)
barsSinceHigh = barssince(ph) + lookback
barsSinceLow = barssince(pl) + lookback
timeSinceHigh = time
timeSinceLow = time

// Doubt you need all these variables...but just take out what you wouldnt need (didnt look at ALL of code to determine)

{ph_01, pl_01, hL_01, lL_01, bsSH_01, bsSL_01, tSH_01, tSL_01} = security(syminfo.tickerid, tf01, f_getHTF())
{ph_02, pl_02, hL_02, lL_02, bsSH_02, bsSL_02, tSH_02, tSL_02} = security(syminfo.tickerid, tf02, f_getHTF())
{ph_03, pl_03, hL_03, lL_03, bsSH_03, bsSL_03, tSH_03, tSL_03} = security(syminfo.tickerid, tf03, f_getHTF())
{ph_04, pl_04, hL_04, lL_04, bsSH_04, bsSL_04, tSH_04, tSL_04} = security(syminfo.tickerid, tf04, f_getHTF())
{ph_05, pl_05, hL_05, lL_05, bsSH_05, bsSL_05, tSH_05, tSL_05} = security(syminfo.tickerid, tf05, f_getHTF())
{ph_06, pl_06, hL_06, lL_06, bsSH_06, bsSL_06, tSH_06, tSL_06} = security(syminfo.tickerid, tf06, f_getHTF())
{ph_07, pl_07, hL_07, lL_07, bsSH_07, bsSL_07, tSH_07, tSL_07} = security(syminfo.tickerid, tf07, f_getHTF())
{ph_08, pl_08, hL_08, lL_08, bsSH_08, bsSL_08, tSH_08, tSL_08} = security(syminfo.tickerid, tf08, f_getHTF())
{ph_09, pl_09, hL_09, lL_09, bsSH_09, bsSL_09, tSH_09, tSL_09} = security(syminfo.tickerid, tf09, f_getHTF())
{ph_10, pl_10, hL_10, lL_10, bsSH_10, bsSL_10, tSH_10, tSL_10} = security(syminfo.tickerid, tf10, f_getHTF())

// ***Now you somply use all these variables as needed and (if you wanted to) you could use up to 40 TF (thats the limit by TV in 1 script)***
ChasinAlts ChasinAlts
@ChasinAlts, something happened to my other comment but ill repeat...a few of your scripts (when first starting out 9 mo ago) became very helpful to me and actually one of them ultimately led to the best strat i think ive ever seen...and created(still in testing phase so hope I dont have to eat my words). This is a little trick I recently learned as I extensively use all 40 security calls per script so thought id share. TV recently released the ability (well...some time ago now I guess) to use touples in security() calls. Hope it come of some use to you. Have a great day my freind.

OHH...and had to use squiggly brackets bc, you know...TV deletes anything between them if use them in comments (Im sure for SOME reason).
millerrh ChasinAlts
@ChasinAlts, Thanks, glad I can be of help to you. And thanks for passing on the recommendation. I actually used one Tuple in this code under the "Trend Calculations" section based on some feedback from someone else. But I'm not an expert at coding so I need to get more familiar with how they work. Seems like an even quicker way of doing repetitive functions though. I'll have to check this out and see if it helps simplify it even more. Thanks for the suggestion!
ChasinAlts millerrh
@millerrh, Itll be far less security calls so itll speed it up quite a bit (and yea...I just was shown this and had to really try to wrap my head around it bc of my ZERO coding experience. Seems were in the same boat ;)

Theres a Pinescripters Telegram group that is INVALUABLE to me. Any of the BIG authors names youve no doubt seen on here you will see in there trying to help people. The more you try to help little questions that arent worth their time but need to get answered nonetheless...the more they seem to help you. Join it...itll change the game. Just google it.
+1 Rispondi
millerrh ChasinAlts
@ChasinAlts, Yeah, the only thing I know how to code is in Pine and only through brute force trial and error, lol. The sharing community here has helped immensely which is why I tend to share most things. The only way I learned is by others sharing with me.
good job!
RozaniGhani-RG RozaniGhani-RG
I just saw the problem with ph(tf) and similar.
Amazing Work!!!
Can you also add 5 minutes timeframe?