TradingView
twingall
22 กรกฎา 2022 เวลา 22 นาฬิกา 27 นาที

10yr, 20yr, 30yr Averages: Month/Month % Change; Seasonality 

Gold FuturesCOMEX

คำอธิบาย

Calculates 10yr, 20yr and 30yr averages for month/month % change

~shows seasonal tendencies in assets (best in commodities). In above chart: August is a seasonally bullish month for Gold: All the averages agree. And January is the most seasonally bullish month.
~averages represent current month/previous month. i.e. Jan22 average % change represents whole of jan22 / whole of dec21
~designed for daily timeframe only: I found calling monthly data too buggy to work with, and I thought weekly basis may be less precise (though it would certainly reduce calculation time!)
~choose input year, and see the previous 10yrs of monthly % change readings, and previous 10yrs Average, 20yr Average, 30yr Average for the respective month. Labels table is always anchored to input year.
~user inputs: colors | label sizes | decimal places | source expression for averages | year | show/hide various sections
~multi-yr averges always print, i.e if only 10yrs history => 10yr Av = 20yr Av = 30yr Av. 'History Available' label helps here.

Based on my previously publised script: "Month/Month Percentage % Change, Historical; Seasonal Tendency"
Publishing this as seperate indicator because:
~significantly slower to load (around 13 seconds)
~non-premium users may not have the historical bars available to use 20yr or 30yr averages =>> prefer the lite/speedier version

~~tips~~
~after loading, touch the new right scale; then can drag the table as you like and seperate it from price chart

##Debugging/tweaking##
Comment-in the block at the end:
~test/verifify specific array elements elements.
~see the script calculation/load time

~~other ideas ~~
~could tweak the array.slice values in lines 313 - 355 to show the last 3 consecutive 10yr averages instead (i.e. change 0, 10 | 0,20 | 0, 30 to 0, 10 | 10, 20 | 20,30)
~add 40yr average by adding another block to each of the array functions, and tweaking the respective labels after line 313 (though this would likely add another 5 seconds to the load time)
~use alternative method for getting obtaining multi-year values from individual month elements. I used array.avg. You could try array.median, array.mode, array.variance, array.max, array.min (lines 313-355)

เอกสารเผยแพร่

show current month as different color and label size.

เอกสารเผยแพร่

Fixed occastional double-print glitch by changing from barstate.islast to barstate.islastconfirmedhistory

เอกสารเผยแพร่

-includes options for Volume (sma of volume) and Volatility (bollinger band width); comparing monthly % changes. Note: volume will not work on most FX pairs (no volume data there)

เอกสารเผยแพร่

-updated to use Tables

เอกสารเผยแพร่

-cleaned up code comments

เอกสารเผยแพร่

-added warning message if user is NOT on daily timeframe
ความคิดเห็น
Willsheng
Hi,
I would love to access the 10yr, 20yr, 30yr indicator but I have been trying for a long time and the yellow table does not appear at all. Am I missing something?

Can someone help me?

Best Regards,
Wills
twingall
@Willsheng, only works on daily timeframe chart. Can take a few seconds to load depending on server load in your area/country (lots of calculations)
Willsheng
@twingall, Thanks alot!! I got it already. It is extremely useful. Love it! :)
berecan
nice
CandlestickMagician
Holy Cow! Words can't explain how useful this indicator is. I've been backtesting with it... the accuracy is crazy. No idea how in the world you managed to create this gift from God, but thank you so much. You just saved me $50 a month for seasonal tendencies.
twingall
@PatientMagician, thank you, happy to hear!
Le125
would you try to make week and day of % change?
twingall
@Le125, i did one for week/week: tradingview.com/script/rhXRQLsE-Seasonal-tendency-week-on-week-change-and-10yr-Averages/.

I may in the future do an indicator with stats on days, but it will not be seasaonality based. It would be more to do with day-of-week volatility tendencies and perhaps stats on which days-of-week are most likely to form the extremes of the week..
ovestarckjohann
Hi! Nice script :-)
May you explain the difference of the four choices of "Choose Expression for Average" (options = ohlc4, sma21, vwap, vwma) ?
Is it possible to use "end of month-close-prices instead of averages ?
twingall
@ovestarckjohann, "ohlc4" is simple moving average of the (open+high+low+close/4) for the input length; "sma21" is simple moving average (based on close) for input length ; "vwap" = volume weighted average price (based on close) for the input length; "Vwma" =volume weighted moving average (based on close) for the input length. ... Default input length is 21 days, If you want end of month close prices, then setting input length to 1 should do the job, using "sma21", "vwap" or "vwma"
เพิ่มเติม