[#!: full-line executeEmbeds, phraseValueList = (("fout fout)("backtrack backtrack)) [#!: path_insertIn_fHand (link d_webWork 'fin Head_one.html') fout ; Howell - TradingView PineScript of SPX500USD [Puetz time, Fibonacci price] multiFractals [#!: path_insertIn_fHand (link d_webWork 'fin Head_two.html') fout ; [#!: path_executeEmbedsInsertIn_fHand (link d_webWork 'Menu.html') phraseValueList ; [#!: path_executeEmbedsInsertIn_fHand (link d_webWork 'Menu projects.html') phraseValueList ; [#!: path_insertIn_fHand (link d_webWork 'normalStatus.html' ) fout ;

TradingView PineScript of SPX500USD [Puetz time, Fibonacci price] multiFractals

"... The true power of fractals only emerges when time is one of the dimensions. ..."

Benoit Mandelbrot, 2004, actually, I couldn't find this quote in the Mandlebrot&Hudson book (see references below)

Table of Contents


This webPage is for PineScript programmers, who may want to adapt my code or simply pick and choose parts of it for their own projects.

Perhaps more importantly, are lessons that can be learned from my own failutres, and some of the techniques I've used to help debug my Pine Script code. General comments are provided on my webPage TradingView PineScript [description, problem, debug].

Initial setup

This section also appears in my webPage for users , and also applies to programmers. Users only have to set up the basic chart and symbols in TradingView based on my chart PuetzUWS [time, price] multiFractal mirrors, SPX 1872-2020. To do so you must be a TradingView subscriber. After that, copy over my PineScript coding, which you can find on my TradingView page - click on "SCRIPTS", and select my script "PuetzUWS [time, price] multifractal of detrended SPX 1871-2020". Further setup details are given below.

What can a Pine Script Programmer easily change?

Modification of the Pine Script code is problematic, as the basic code isn't entirely "stable". Seemingly [minmor, unrelated] code changes can have serious side effects elsewhere in the code. I'm not proud of that, but I lack the experience to do much better for now. However, the changes below shouldn't cause too much frustration (I hope).

View debugging output to the chart

Perhaps the simplest thing do, is to "un-comment-out" (remove "//" characters) debugging lines that ped me solve problems. While Pine Script compiler errors are essential, they are not enough. It took me some time to get comments to work,even now there are still problems.

Add semi-log fits for other symbols like [NASDAQ, USOIL, GOLD]

Try thinking of the SPX fractal basis as being general, so retaining it facilitates visual comparisons of symbol [variance, correlation, [time, price] pattern]s.

Current coding in my script is specific to SPX 1872-2020 (formatting will be mis-aligned badly) :

// Wilhelm Abel ?1937?, David Fischer 1996, I've used the following split :
// price equilibrium (stable prices) 1871-1926
// price revolution 1926-2020

// calculate trendline for [1926.25-2020.???, 1872-1926.25]
calc_SP500Trend(y_fraction) =>
expnt = 0.0
if y_fraction >= 1926.25
expnt := 0.792392+0.0289587*(y_fraction - 1926.25)
expnt := 0.784617+1.40925E-04 *(y_fraction - 1871.08)
SP500base = math.pow(10,expnt)

lin0000 = calc_SP500Trend(year_fraction)

//lin0000_[start, end] : don't need, its just lin0000 at barstate.islast (horizontal lines)

// The "relative standard deviation" (relStdDev or rsd) of the 83y trend is from the data 1926-2020
// calculated in LibreOffice Calc spreadsheet =STDEV(SP500_detrend_1926_2020), i.e on semi-log detrend basis // see "$d_webRawe"'economics, markets/SP500/multi-fractal/SP500 1872-2020 TradingView, 1928-2020 yahoo
// WARNING!!! Redo this yourself!!! I made so many changes of a period of two years, weird things could have happened.
// keep coming back like zombies. examples :
// fib0236Hi = (1 + 0.236*relStdDev/2) should be relStdDev (should be no "/2")
// I don't trust this

relStdDev = 0.4308

Download symbol data (like [TVC:[USOIL, GOLD], NASDAQ: NDX]) from [TradingView, yahoo finance, etc]. My own data for SPX is in my LibreCalc spreadsheet SP500 1872-2020 TradingView, 1928-2020 yahoo finance.ods. Actually, it's in several different spreadsheets, hence the possibility of glitches as [update, change]s are made...

Change the basis of the [time, price] fractals to [Fibonacci, other]

I was hoping to provide this as an option in the code, but I've run out of time. I suspect that this will be a "bit more of a challenge", because the Fibonacci series doesn't [nest, recur] cleanly down levels so that the fractals zoom in to the timescale of the graph. However, it's certainly do-able, and might provide very interesting insights.

However, unless you are into Pine Script Programming seriously, I don't recommend changing the underlying [time, price] fractals, as I susect that it will be a challenge.

Fractals are defined in the code :
// Basic [constant, function]s used in rest of library

// lambdaPuetzUWS - used for timeFractals, all of which are positive!
lambdaPuetzUWS = array.from(0.0001072980, 0.0003218942, 0.0009656826, 0.002897047, 0.008691143, 0.02607343, 0.07822029, 0.2346608, 0.7039826, 2.111947, 6.335843, 19.00753, 57.02259, 171.0677, 513.2033)

// rsdPuetzUWS - used for priceFractals, which are both [posit, negat]ive!
// rsdPuetzUWS = lambdaPuetzUWS / 0.2346608 (mid-range value)
// full sequence reversal
// this shorter rsdPuetzUWS sequence - will NOT accomodate cypto and other extremely high growth! nor negatives

rsdPuetzUWS = array.from(-9., -3., -1., -0.333333, -0.111111, -0.037037, -0.0123457, -0.00411523, -0.00137174, -0.000457247, 0.000, 0.000457247, 0.00137174, 0.00411523, 0.0123457, 0.037037, 0.111111, 0.333333, 1., 3., 9.)

Note that I was un[able, interested] to get the PineScript "input tab" to work, so I provided no "standard way" to change simple parameters. However, I always prefer to do so directly in the source code, usually done automatically by [Unix, bash]*[utility, command]s that often run script files.

Adapt my PineScript program to other [symbol, application]s

So what does the user have to do to adapt my PineScript code to other [symbol, chart]s?

Users can simply follow standard Trading View guide instructions to install the Pine Script program that super-imposes fractal [time, price] grids on their charts. I don't recommend that you do this UNLESS your [are, want to be] familiar with PineScript programming. The reason that I say that is because for every market symbol being tracked, you must provide a formula for the semi-log price [trend, relative standard deviation]. Preferably get as long a series as you can get, eg download from TradingView. If you don't have 20+ years of data (eg the young crypto market), it may be a waste of your time. Here are the statements that you need to adapt to your symbol's data :

In addition to Puetz UWS cycle periods, adjustable "phase angles" (related to time lags) are use for [tune, model]ing datasets. However, I may not even look at that, as my interest is in the spike timings and not a regression model. If I ever do look at the "phase angles", it will only be after I have far better [robustness, performance] with the current script. Pine Script isn't the most obvious computer language to work with.

My [frequent, ongoing] failures with PineScript programming

I still don't understand many of the PineScript idiosyncracies. It has taken me weeks to "sort-of" solve a problem but even a year or two to gain enough knowledge to develop better approaches. For details, see Howell - TradingView PineScript [description, problem, debug].html.


Related background information on my other webPages : see [general, specific] links to [concepts, my software, data, results, etc] in :

19May2022 initial posting
28May2022 comments about SPX500USD chart (before Fibnacci priceFractals nexted)
[#!: full-line executeEmbeds, phraseValueList = (("fout fout)("backtrack backtrack)) [#!: path_executeEmbedsInsertIn_fHand (link d_webWork 'fin Footer.html') phraseValueList ;