Moving Average PropertiesThis indicator calculates and visualizes the Relative Smoothness (RS) and Relative Lag (RL) or call it accuracy of a selected moving average (MA) in comparison to the SMA of length 2 (the lowest possible length for a moving average and also the one closest to the price).
Median RS (Relative Smoothness):
Interpretation: The median RS represents the median value of the Relative Smoothness calculated for the selected moving average across a specified look-back period (max bar lookback is set at 3000).
Significance: A more negative (larger) median RS suggests that the chosen moving average has exhibited smoother price behavior compared to a simple moving average over the analyzed period. A less negative value indicates a relatively choppier price movement.
Median RL (Relative Lag):
Interpretation: The median RL represents the median value of the Relative Lag calculated for the selected moving average compared to a simple moving average of length 2.
Significance: A higher median RL indicates that the chosen moving average tends to lag more compared to a simple moving average. Conversely, lower values suggest less lag in the selected moving average.
Ratio of Median RS to Median RL:
Interpretation: This ratio is calculated by dividing the median RS by the median RL.
Significance: Traders might use this ratio to assess the balance between smoothness and lag in the chosen moving average. This a measure of for every % of lag what is the smoothness achieved. This can be used a benchmark to decide what length to choose for a MA to get an equivalent value between two stocks. For example a TESLA stock on a 15 minute time frame with a length of 12 has a value (ratio of RS/RL) of -150 , where as APPLE stock of length 35 on a 15 minute chart also has a value (ratio of RS/RL) of -150.
I imply that a MA of length 12 working on TESLA stock is equivalent to MA of length 35 on a APPLE stock. (THIS IS A EXAMPLE).
My assumption is that finding the right moving average length for a stock isn't a one-size-fits-all situation. It's not just about using a fixed length; it's about adapting to the unique characteristics of each stock. I believe that what works for one stock might not work for another because they have different levels of smoothness or lag in their price movements. So, instead of applying the same length to all stocks, I suggest adjusting the length of the moving average to match the values that we know work best for achieving the desired smoothness or lag or its ratio (RS/RL). This way, we're customizing the indicator for each stock, tailoring it to their individual behaviors rather than sticking to a one-size-fits-all approach.
Users can choose from various types of moving averages (EMA, SMA, WMA, VWMA, HMA) and customize the length of the moving average. RS measures the smoothness of the MA, while RL measures its lag compared to a simple moving average. The script plots the median RS and RL values, the selected MA, and the ratio of median RS to median RL on the price chart. Traders can use this information to assess the performance of different moving averages and potentially inform their trading decisions.
Optimization
Supertrend - Optimised Exit We created a small script that will allow you to have a quick look into static SL/PT to choose from. This might save you time, replacing the manual search for optimal SL/PT.
We're checking signals of the strategy and computing its performance with a grid of SL/PT selected.
We used SuperTrend signals in this example, but it will be straightforward to integrate your signals.
In addition to total Return, we compute MAX Dd and Profit Factor. Other metrics can be implemented as well.
Thanks to @MUQWISHI for helping code it.
Disclaimer
Please remember that past performance may not indicate future results.
Due to various factors, including changing market conditions, the strategy may no longer perform as well as in historical backtesting.
This post and the script don’t provide any financial advice.
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
How to avoid trading on certain dates Time Breaks for optimizingThis Snippet is useful to avoid trading in certain times.
I use to optimize when I want to avoid certain times where market behave irrationally bull or bulltard :). That way the optimization can be improved because by optimizing more for the other 99% of the time where market beahve more rational
Optimized Linear Regression ChannelReturn a linear regression channel with a window size within the range (min, max) such that the R-squared is maximized, this allows a better estimate of an underlying linear trend, a better detection of significant historical supports and resistance points, and avoid finding a good window size manually.
Settings
Min : Minimum window size value
Max : Maximum window size value
Mult : Multiplicative factor for the rmse, control the channel width.
Src : Source input of the indicator
Details
The indicator displays the specific window size that maximizes the R-squared at the bottom of the lower channel.
When optimizing we want to find parameters such that they maximize or minimize a certain function, here the r-squared. The R-squared is given by 1 minus the ratio between the sum of squares (SSE) of the linear regression and the sum of squares of the mean. We know that the mean will always produce an SSE greater or equal to the one of the linear regression, so the R-squared will always be in a (0,1) range. In the case our data has a linear trend, the linear regression will have a better fit, thus having a lower SSE than the SSE of the mean, has such the ratio between the linear regression SSE and the mean SSE will be low, 1 minus this ratio will return a greater result. A lower R-squared will tell you that your linear regression produces a fit similar to the one produced by the mean. The R-squared is also given by the square of the correlation coefficient between the dependent and independent variables.
In pinescript optimization can be done by running a function inside a loop, we run the function for each setting and keep the one that produces the maximum or minimum result, however, it is not possible to do that with most built-in functions, including the function of interest, correlation , as such we must recreate a rolling correlation function that can be used inside loops, such functions are generally loops-free, this means that they are not computed using a loop in the first place, fortunately, the rolling correlation function is simply based on moving averages and standard deviations, both can be computed without using a loop by using cumulative sums, this is what is done in the code.
Note that because the R-squared is based on the SSE of the linear regression, maximizing the R-squared also minimizes the linear regression SSE, another thing that is minimized is the horizontality of the fit.
In the example above we have a total window size of 27, the script will try to find the setting that maximizes the R-squared, we must avoid every data points before the volatile bearish candle, using any of these data points will produce a poor fit, we see that the script avoid it, thus running as expected. Another interesting thing is that the best R-squared is not always associated to the lowest window size.
Note that optimization does not fix core problems in a model, with the linear regression we assume that our data set posses a linear trend, if it's not the case, then no matter how many settings you use you will still have a model that is not adapted to your data.
Momentum adjusted Moving Average by DGTA brand new Moving Average , calculated using Momentum, Acceleration and Probability (Psychological Effect).
Momentum adjusted Moving Average(MaMA) is an indicator that measures Price Action by taking into consideration not only Price movements but also its Momentum, Acceleration and Probability. MaMA, provides faster responses comparing to the regular Moving Average
Here is the math of the MaMA idea
Momentum measures change in price over a specified time period
momentum = source – source(length)
where,
source, indicates current bar’s price value
source(length), indicates historical price value of length bars earlier
Lets play with this formula and rewrite it by moving source(length) to other side of the equation
source = source(length) + momentum
to avoid confusion let’s call the source that we aim to predict as adjustedSource
adjustedSource = source(length) + momentum
looks nice the next value of source simply can be calculated by summing of historical value of the source value and value of the momentum. I wish it was so easy, the formula holds true only when the momentum is conserved/constant/steady but momentum move up or down with the price fluctuations (accelerating or decelerating)
Let’s add acceleration effects on our formula, where acceleration is change in momentum for a given length. Then the formula will become as (skipped proof part of acceleration effects, you may google for further details)
adjustedSource = source(length) + momentum + 1/2 * acceleration
here again the formula holds true when the acceleration is constant and once again it is not the case for trading, acceleration also changes with the price fluctuations
Then, how we can benefit from all of this, it has value yet requires additional approaches for better outcome
Let’s simulate behaviour with some predictive approach such as using probability (also known as psychological effect ), where probability is a measure for calculating the chances or the possibilities of the occurrence of a random event. As stated earlier above momentum and acceleration are changing with the price fluctuations, by using the probability approach we can add a predictive skill to determine the likelihood of momentum and acceleration changes (remember it is a predictive approach). With this approach, our equations can be expresses as follows
adjustedSource = source(length) + momentum * probability
adjustedSource = source(length) + ( momentum + 1/2 * acceleration ) * probability , with acceleration effect
Finally, we plot MaMA with the new predicted source adjustedSource, applying acceleration effect is made settable by the used from the dialog box, default value is true.
What to look for:
• Trend Identification
• Support and Resistance
• Price Crossovers
Recommended settings are applied as default settings, if you wish to change the length of the MaMA then you should also adjust length of Momentum (and/or Probability). For example for faster moving average such as 21 period it would be suggested to set momentum length to 13
Alternative usage , set moving average length to 1 and keep rest lengths with default values, it will produce a predictive price line based on momentum and probability. Experience acceleration factor by enabling and disabling it
Conclusion
MaMA provide an added level of confidence to a trading strategy and yet it is important to always be aware that it implements a predictive approach in a chaotic market use with caution just like with any indicator
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
Disclaimer : The script is for informational and educational purposes only. Use of the script does not constitutes professional and/or financial advice. You alone 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
Momentum Acceleration by DGTItalian physicist Galileo Galilei is usually credited with being the first to measure speed by considering the distance covered and the time it takes. Galileo defined speed as the distance covered during a period of time. In equation form, that is v = Δd / Δt where v is speed, Δd is change in distance, and Δt is change in time. The Greek symbol for delta, a triangle (Δ), means change.
Is the speed getting faster or slower?
Acceleration will be the answer, acceleration is defined as the rate of change of speed over a set period of time, meaning something is getting faster or slower. Mathematically expressed, acceleration denoted as a is a = Δv / Δt , where Δv is the change in speed and Δt is the change in time.
How to apply in trading
Lets think about Momentum, Rate of Return, Rate of Change all are calculated in almost same approach with Speed
Momentum measures change in price over a specified time period,
Rate of Change measures percent change in price over a specified time period,
Rate of Return measures the net gain or loss over a specified time period,
And Speed measures change in distance over a specified time period
So we may state that measuring the change in distance is also measuring the change in price over a specified time period which is length, hence
speed can be calculated as (source – source )/length and acceleration becomes (speed – speed )/length
In this study acceleration is used as signal line and result plotted as arrows demonstrating bull or bear direction where direction changes can be considered as trading setups
Just a little fun, since we deal with speed the short name of the study is named after famous cartoon character Speedy Gonzales
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
Disclaimer: The script is for informational and educational purposes only. Use of the script does not constitutes professional and/or financial advice. You alone 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
Elliott Wave Oscillator Signals by DGTElliott Wave Principle , developed by Ralph Nelson Elliott, proposes that the seemingly chaotic behaviour of the different financial markets isn’t actually chaotic. In fact the markets moves in predictable, repetitive cycles or waves and can be measured and forecast using Fibonacci numbers. These waves are a result of influence on investors from outside sources primarily the current psychology of the masses at that given time. Elliott wave predicts that the prices of the a traded currency pair will evolve in waves: five impulsive waves and three corrective waves. Impulsive waves give the main direction of the market expansion and the corrective waves are in the opposite direction (corrective wave occurrences and combination corrective wave occurrences are much higher comparing to impulsive waves)
The Elliott Wave Oscillator (EWO) helps identifying where you are in the 5-3 Elliott Waves, mainly the highest/lowest values of the oscillator might indicate a potential bullish/bearish Wave 3. Mathematically expressed, EWO is the difference between a 5-period and 35-period moving average based on the close. In this study instead 35-period, Fibonacci number 34 is implemented for the slow moving average and formula becomes ewo = ema(source, 5) - ema(source, 34)
The application of the Elliott Wave theory in real time trading gets difficult because the charts look messy. This study (EWO-S) simplifies the visualization of EWO and plots labels on probable reversals/corrections. The good part is that all plotting’s are performed on the top of the price chart including a histogram (optional and supported on higher timeframes). Additionally optional Keltner Channels Cloud added to help confirming the price actions.
What to look for:
Plotted labels can be used to follow the Elliott Wave occurrences and most importantly they can be considered as signals for possible trade setup opportunities. Elliott Wave Rules and Fibonacci Retracement/Extensions are suggested to confirm the patters provided by the EWO-S
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
Disclaimer : The script is for informational and educational purposes only. Use of the script does not constitutes professional and/or financial advice. You alone 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
Script Stopwatch - PineCoders FAQ█ WARNING
The publication of our LibraryStopwatch has deprecated this publication.
█ ORIGINAL DESCRIPTION
This script calculates the run time of a Pine script. While its numbers are not very precise and it doesn’t work on all scripts, it will help developers calculate run times more precisely than by hand, and so provides Pine coders with an additional profiling tool to help them optimize their code.
How to use the code
• Place the code included between the up/down arrows after your script’s input() calls.
• Comment out the display modes you don’t want to use.
• Save your script, wait and look at the results.
• Results show in different colors, depending on the average time per bar:
- green for < 5 ms
- dark red for < 50 ms
- bright red for > 50 ms (the maximum allowed is 200).
How the code works
The code in this script starts by saving the value of the timenow variable on the first bar. While the time variable returns the time at the beginning of the bar, timenow returns the current time. The code then follows the progression of timenow during the script’s execution. The variable only updates every second, so in between updates the script makes an estimate of the total time elapsed by adding the last average time per bar calculated to each bar that passes until timenow increases by another 1000 because one more second has elapsed since its last update. At that point a new, current average time per bar is calculated and the cycle repeats.
The code only calculates elapsed time for the initial run. Once the realtime bar is hit, timing stops so that time spent in the realtime bar does not affect the numbers once they have been calculated on the script’s initial pass over the dataset.
Notes
• If results show zero elapsed time, it’s most probably because your script executes in less than one second, which is very good. In that case timenow hasn’t changed, so no timing can be calculated.
• The code is quirky and doesn’t work on all scripts.
• It doesn’t properly time execution of security() calls.
• The average time per bar will sometimes vary quite a bit with changes in chart resolution.
Look first. Then leap.