Machine Learning: Multiple Logistic Regression
Multiple Logistic Regression Indicator
The Logistic Regression Indicator for TradingView is a versatile tool that employs multiple logistic regression based on various technical indicators to generate potential buy and sell signals. By utilizing key indicators such as RSI, CCI, DMI, Aroon, EMA, and SuperTrend, the indicator aims to provide a systematic approach to decision-making in financial markets.
How It Works:
Technical Indicators:
The script uses multiple technical indicators such as RSI, CCI, DMI, Aroon, EMA, and SuperTrend as input variables for the logistic regression model.
These indicators are normalized to create categorical variables, providing a consistent scale for the model.
Logistic Regression:
The logistic regression function is applied to the normalized input variables (x1 to x6) with user-defined coefficients (b0 to b6).
The logistic regression model predicts the probability of a binary outcome, with values closer to 1 indicating a bullish signal and values closer to 0 indicating a bearish signal.
Loss Function (Cross-Entropy Loss):
The cross-entropy loss function is calculated to quantify the difference between the predicted probability and the actual outcome.
The goal is to minimize this loss, which essentially measures the model's accuracy.
// Error Function (cross-entropy loss)
loss(y, p) =>
-y * math.log(p) - (1 - y) * math.log(1 - p)
// y - depended variable
// p - multiple logistic regression
Gradient Descent:
Gradient descent is an optimization algorithm used to minimize the loss function by adjusting the weights of the logistic regression model.
The script iteratively updates the weights (b1 to b6) based on the negative gradient of the loss function with respect to each weight.
// Adjusting model weights using gradient descent
b1 -= lr * (p + loss) * x1
b2 -= lr * (p + loss) * x2
b3 -= lr * (p + loss) * x3
b4 -= lr * (p + loss) * x4
b5 -= lr * (p + loss) * x5
b6 -= lr * (p + loss) * x6
// lr - learning rate or step of learning
// p - multiple logistic regression
// x_n - variables
Learning Rate:
The learning rate (lr) determines the step size in the weight adjustment process. It prevents the algorithm from overshooting the minimum of the loss function.
Users can set the learning rate to control the speed and stability of the optimization process.
Visualization:
The script visualizes the output of the logistic regression model by coloring the SMA.
Arrows are plotted at crossover and crossunder points, indicating potential buy and sell signals.
Lables are showing logistic regression values from 1 to 0 above and below bars
Table Display:
A table is displayed on the chart, providing real-time information about the input variables, their values, and the learned coefficients.
This allows traders to monitor the model's interpretation of the technical indicators and observe how the coefficients change over time.
How to Use:
Parameter Adjustment:
Users can adjust the length of technical indicators (rsi_length, cci_length, etc.) and the Z score length based on their preference and market characteristics.
Set the initial values for the regression coefficients (b0 to b6) and the learning rate (lr) according to your trading strategy.
Signal Interpretation:
Buy signals are indicated by an upward arrow (▲), and sell signals are indicated by a downward arrow (▼).
The color-coded SMA provides a visual representation of the logistic regression output by color.
Table Information:
Monitor the table for real-time information on the input variables, their values, and the learned coefficients.
Keep an eye on the learning rate to ensure a balance between model adjustment speed and stability.
Backtesting and Validation:
Before using the script in live trading, conduct thorough backtesting to evaluate its performance under different market conditions.
Validate the model against historical data to ensure its reliability.
Logistic
Logistic RSI, STOCH, ROC, AO, ... by DGTExperimental attemt of applying Logistic Map Equation for some of widly used indicators.
With this study "Awesome Oscillator (AO)", "Rate of Change (ROC)", "Relative Strength Index (RSI)", "Stochastic (STOCH)" and a custom interpretation of Logistic Map Equation is presented
Calculations with Logistic Map Equation makes sense when the calculated results are iterated many times within the same equation.
Here is the Logistic Map Equation : Xn+1 = r * Xn * (1 - Xn)
Where, the value of r is the key for this equation which changes amazingly the behaviour of the Logistic Map.
The value we have asigned for r is less then 1 and greater than 0 ( 0 < r < 1) and in this case the iterations performed with the maximum number of output series allowed by Pine is quite enough for our purpose and thanks to arrays we can easiliy store them for further processing
What we have as output:
Each iteration result is then plotted (excluding plotting the first iteration), as circles or line based on user preference
Values above and below zero level (0) are coloured differently to emphasis bull and bear power
Finally Standard Deviation of Array's Elements is ploted as line. Users may choose to display this line only
So where it comes the indicators "Awesome Oscillator (AO)", "Rate of Change (ROC)", "Relative Strength Index (RSI)", "Stochastic (STOCH)".
Those are the indicators whose values are assigned to our key varaiable in the Logistic Map equation forulma which is r
Further details regarding Logistic Map can found under the description of “Logistic EMA w/ Signals by DGT” study
Disclaimer:
Trading success is all about following your trading strategy and the indicators should fit within your trading strategy, and not to be traded upon solely
The script is for informational and educational purposes only. Use of the script does not constitute professional and/or financial advice. You alone have the sole responsibility of evaluating the script output and risks associated with the use of the script. In exchange for using the script, you agree not to hold dgtrd TradingView user liable for any possible claim for damages arising from any decision you make based on use of the script
Logistic EMA w/ Signals by DGTLogistic Map Equation - The logistic map connects fluid convection, neuron firing, the Mandelbrot set and so much more.
This study is an attempt to apply Logistic Map Equation in Trading
Logistic Map Equation
Xn+1 = r * Xn * (1 - Xn)
Where,
r - growth rate
Xn - percentage of theoretical maximum of measured event (from 0 to 1)
(1 - Xn) - represents constraints of the environment, presents the idea of negative feedback
For trading the measured event will be the price of the instrument (price is commonly reffered as source in mathematicall forumlations),
hence
r - growth rate can be expressed as => change(source, length) / source, expressing r in such manner mades the equation dynamic with regards to the growth rate
Xn - percentage of theoretical maximum of the price for given duration can be expressed as => source / highest(length)
Putting pieces together we are ready to plot
Printed alone does not seem to provide much useful visualization for trading, in fact not easy to interpret especially when the market is an uptrend
What it has numerically,
Provides a ratio, where sudden changes are much more reflected thanks to negative feedback nature of the logistic equation.
As we know moving average indicators are lagging and the logistic map may fit here to reduce the lag
With this study you will find application of Logistic Map Equation with combination of Exponential Moving Average (EMA)
Logistic EMA (LEMA) and LEMA COLORS
one line with user defined periods of length, where the colors of the line will change automatically depending where the value is compared to 50-100-200 moving average
Multiple LEMAs : optional – three fixed lenght of 50-100-200 period lines
LEMA Signals
Various signals are added by using LEMA and applying some common market approaches. Use with caution and with conjunction of other indicators
Thanks to @allanster for the idea
A fascinating YouTube video explaining the logistic map - “This equation will change how you see the world (the logistic map)”
Disclaimer:
Trading success is all about following your trading strategy and the indicators should fit within your trading strategy, and not to be traded upon solely
The script is for informational and educational purposes only. Use of the script does not constitute professional and/or financial advice. You alone have the sole responsibility of evaluating the script output and risks associated with the use of the script. In exchange for using the script, you agree not to hold dgtrd TradingView user liable for any possible claim for damages arising from any decision you make based on use of the script
Volatility Bands by DGTVolatility represents how large an asset's prices swing around the mean price, the degree of variation of a trading price over time, and is commonly measured with beta (β) coefficients, standard deviations (σ) of returns where tools such as Average True Range, Bollinger Bands, Keltner Channel, Squeeze Indicator, etc presents volatility concept
Volatility often refers to the amount of uncertainty or risk related to the size of changes in a security's value. The higher the volatility, the riskier the security - the price of the security can change dramatically over a short time period in either direction. A lower volatility - security's value does not fluctuate dramatically, and tends to be more steady
This study, Volatility Bands , attempts to present a way to measure and visualize volatility , using standard deviations (σ) and average true range indicator, and aims to point out areas that might indicate potential trading opportunities
I will try to explain the usage with examples,
same setup with different option selected
as you may observe from the examples different setting may have advantages and disadvantages over one another, it is recommended to verify a trading setup with different available options.
Additionally, It is recommended to use this indicator in conjunction with other technical indicators, or verify using chart/candle patterns. Below is an usage example using in conjunction with other indicator, in the given example “Neglected Volume by DGT” is selected
Similarities and Differences
Bollinger Bands depicts two standard deviations above and below a simple moving average, and Keltner Channel depicts two times average true range (ATR) above and below an exponential moving average
Volatility Bands study combines the approach of both Bollinger Bands and Keltner Channel, with different settings and different visualization
Default settings are one standard deviations and one time average true range (ATR) above and below 13 period exponential moving average. Setting can be adjusted by users but let me remind all testes are performed with the default settings.
Mathematically expressed as
Upper band area between “ema + stdev” and “ema + atr”
Lower band area between “ema – stdev” and “ema – atr”
A different display is added with the inspiration I get from one of the @quantgym ‘s study, many thanks @quantgym 😉
When difference band display is selected the study will reflect the area between “ema + stdev – atr” and “ema – stdev + atr”. As shown in the examples above
Note: standard deviation calculation can be adjusted based on price action or its moving average.
Other differentiation between BB and KC is with V-BANDS mostly we look for trade opportunities when price action move out of the bands and in most cases we assume market is consolidating when the price action is within the bands
The other indicator that presents similarities to Volatility Bands is Squeeze Indicator, which measures the relationship between Bollinger Bands and Keltner's Channels to help identify consolidations and signal when prices are likely to break out. Mainly Volatility Bands is different version of Squeeze indicator, in fact the purpose is almost same but visualization is completely different. Additionally Volatility Bands Offers trading opportunities whereas Squeeze indicator only presents market states unless a momentum indicator is adapted to Squeeze indicator.
Disclaimer:
Trading success is all about following your trading strategy and the indicators should fit within your trading strategy, and not to be traded upon solely
The script is for informational and educational purposes only. Use of the script does not constitute professional and/or financial advice. You alone have the sole responsibility of evaluating the script output and risks associated with the use of the script. In exchange for using the script, you agree not to hold dgtrd TradingView user liable for any possible claim for damages arising from any decision you make based on use of the script
Logistic Difference (ps4)This is an PS4 update to the Logistic Difference Indicator. It uses logistic function (sigmoid), which stabilizes the variance of data. The logistic function resembles the inverse Fisher transform. This version has a repaint/non-repaint switch and a scaling feature.
Logistic DifferenceLogistic Difference Indicator uses logistic function (sigmoid), which stabilizes the variance of data.
Logistic CorrelationLogistic Correlation is a correlation oscillator using a logistic function.
A Logistic Function is a Sigmoid Function who stabilize the variance of data.The logistic function have the same function as the inverse fisher transform but with an advantage over it, the k constant can control the steepness of the curve, lowers k's will preserve the original form of the data while highers one will transform it into a more square shaped form.
10 k
20 k