Flux Charts MTF Supply and Demand Zones (Premium)Indicator Overview
The Multi-Timeframe Supply & Demand Zones indicator by Flux Charts displays supply and demand zones on multiple timeframes with two different zone detection methods. These zones are commonly known as areas where there are lots of buyers/sellers present in the market.
Adaptive Detection Method
AMEX:SPY 5m timeframe, October 8 2023
Indicator Settings: (Timeframe: Chart & 15m, Method: Adaptive, Zone Multiplier: 1)
Many times supply and demand scripts try and precisely define conditions that qualify for supply and demand zones. People, however, when locating supply and demand zones manually generally do not take a quantitative approach, rather looking for qualities in price action that have generalized qualities and trends. The adaptive algorithm uniqueness comes from adapting the human approach to work computationally. It generalizes the qualities of supply and demand zones and locates areas in the chart with an acceptable similarity. Specifically, it looks for consolidated areas within the chart that are preceded by a rise or fall in price. The rise or fall length has to be a certain ratio to the consolidation length. If the criteria are met it will draw the zone, if a zone already exists at that price level it will ignore it or merge them if they are different timeframes. This results in a much more consistent ability to identify areas of supply and demand.
Basic Detection Method
The basic detection method looks for areas where price made drastic movements within a small period of time, which could indicate a high level of buyers/sellers at the spot. Thus, these zones are formed and can be used as areas of trading where money is going in/out of the markets.
Multi-Timeframe (MTF) S&D
Flux Charts supply and demand script utilizes MTF. This allows for displaying zones from different timeframes on one chart. Utilizing higher timeframes is a common practice in trading, and it can be easy to forget about key levels & zones on higher timeframes which could cause reversals/bounces.
Here is an example of a 15 minute supply zone formed on the NASDAQ, and with this indicator, you can also see this same 15 minute supply zone while being on a 5 minute candlestick chart, since you have the 15 minute zones enabled in the settings. This indicator offers supply & demand zones on multiple timeframes including the 5 minute, 15 minute, 30 minute, 1 hour, and 4 hour.
Settings
Method:
Choose between the Supply & Demand zones detection (Basic / Adaptive)
Zone Retests:
Choose how retests should be considered. You can choose between a high/low candle wick entering a zone, or a candle closing inside of a zone to be considered a valid retest.
Zone Invalidation:
Choose how zones are invalidated. You can choose between a high/low candle wick exiting a zone, or a candle closing outside of a zone to be considered a zone invalidation.
Zone multiplier:
Adjust zone size (1 is recommended)
Timeframe:
Choose the timeframes you would like Supply & Demand zones to be displayed from.
Zone Appearance:
Adjust the colors of Supply/Demand zones
Enable/Disable the center dashed line in zones
Display Labels:
Choose to toggle on/off retest & break labels
Notifications:
Choose what alerts you would like to receive. You can choose to have new zone formations, zone breaks, and zone retests.
Linearalgebra
Levinson-Durbin Autocorrelation Extrapolation of Price [Loxx]Levinson-Durbin Autocorrelation Extrapolation of Price is an indicator that uses the Levinson recursion or Levinson–Durbin recursion algorithm to predict price moves. This method is commonly used in speech modeling and prediction engines.
What is Levinson recursion or Levinson–Durbin recursion?
Is a linear algebra prediction analysis that is performed once per bar using the autocorrelation method with a within a specified asymmetric window. The autocorrelation coefficients of the window are computed and converted to LP coefficients using the Levinson algorithm. The LP coefficients are then transformed to line spectrum pairs for quantization and interpolation. The interpolated quantized and unquantized filters are converted back to the LP filter coefficients to construct the synthesis and weighting filters for each bar.
Data inputs
Source Settings: -Loxx's Expanded Source Types. You typically use "open" since open has already closed on the current active bar
LastBar - bar where to start the prediction
PastBars - how many bars back to model
LPOrder - order of linear prediction model; 0 to 1
FutBars - how many bars you want to forward predict
Things to know
Normally, a simple moving average is caculated on source data. I've expanded this to 38 different averaging methods using Loxx's Moving Avreages.
This indicator repaints
Included
Bar color muting
Further reading
Implementing the Levinson-Durbin Algorithm on the StarCore™ SC140/SC1400 Cores
LevinsonDurbin_G729 Algorithm, Calculates LP coefficients from the autocorrelation coefficients. Intel® Integrated Performance Primitives for Intel® Architecture Reference Manual
Matrix Library (Linear Algebra, incl Multiple Linear Regression)What's this all about?
Ever since 1D arrays were added to Pine Script, many wonderful new opportunities have opened up. There has been a few implementations of matrices and matrix math (most notably by TradingView-user tbiktag in his recent Moving Regression script: ). However, so far, no comprehensive libraries for matrix math and linear algebra has been developed. This script aims to change that.
I'm not math expert, but I like learning new things, so I took it upon myself to relearn linear algebra these past few months, and create a matrix math library for Pine Script. The goal with the library was to make a comprehensive collection of functions that can be used to perform as many of the standard operations on matrices as possible, and to implement functions to solve systems of linear equations. The library implements matrices using arrays, and many standard functions to manipulate these matrices have been added as well.
The main purpose of the library is to give users the ability to solve systems of linear equations (useful for Multiple Linear Regression with K number of independent variables for example), but it can also be used to simulate 2D arrays for any purpose.
So how do I use this thing?
Personally, what I do with my private Pine Script libraries is I keep them stored as text-files in a Libraries folder, and I copy and paste them into my code when I need them. This library is quite large, so I have made sure to use brackets in comments to easily hide any part of the code. This helps with big libraries like this one.
The parts of this script that you need to copy are labeled "MathLib", "ArrayLib", and "MatrixLib". The matrix library is dependent on the functions from these other two libraries, but they are stripped down to only include the functions used by the MatrixLib library.
When you have the code in your script (pasted somewhere below the "study()" call), you can create a matrix by calling one of the constructor functions. All functions in this library start with "matrix_", and all constructors start with either "create" or "copy". I suggest you read through the code though. The functions have very descriptive names, and a short description of what each function does is included in a header comment directly above it. The functions generally come in the following order:
Constructors: These are used to create matrices (empy with no rows or columns, set shape filled with 0s, from a time series or an array, and so on).
Getters and setters: These are used to get data from a matrix (like the value of an element or a full row or column).
Matrix manipulations: These functions manipulate the matrix in some way (for example, functions to append columns or rows to a matrix).
Matrix operations: These are the matrix operations. They include things like basic math operations for two indices, to transposing a matrix.
Decompositions and solvers: Next up are functions to solve systems of linear equations. These include LU and QR decomposition and solvers, and functions for calculating the pseudo-inverse or inverse of a matrix.
Multiple Linear Regression: Lastly, we find an implementation of a multiple linear regression, including all the standard statistics one can expect to find in most statistical software packages.
Are there any working examples of how to use the library?
Yes, at the very end of the script, there is an example that plots the predictions from a multiple linear regression with two independent (explanatory) X variables, regressing the chart data (the Y variable) on these X variables. You can look at this code to see a real-world example of how to use the code in this library.
Are there any limitations?
There are no hard limiations, but the matrices uses arrays, so the number of elements can never exceed the number of elements supported by Pine Script (minus 2, since two elements are used internally by the library to store row and column count). Some of the operations do use a lot of resources though, and as a result, some things can not be done without timing out. This can vary from time to time as well, as this is primarily dependent on the available resources from the Pine Script servers. For instance, the multiple linear regression cannot be used with a lookback window above 10 or 12 most of the time, if the statistics are reported. If no statistics are reported (and therefore not calculated), the lookback window can usually be extended to around 60-80 bars before the servers time out the execution.
Hopefully the dev-team at TradingView sees this script and find ways to implement this functionality diretly into Pine Script, as that would speed up many of the operations and make things like MLR (multiple linear regression) possible on a bigger lookback window.
Some parting words
This library has taken a few months to write, and I have taken all the steps I can think of to test it for bugs. Some may have slipped through anyway, so please let me know if you find any, and I'll try my best to fix them when I have time to do so. This library is intended to help the community. Therefore, I am releasing the library as open source, in the hopes that people may improving on it, or using it in their own work. If you do make something cool with this, or if you find ways to improve the code, please let me know in the comments.