Harmonic Moving AverageI was legitimately surprised no1 has already coded it out on TradingView, but you guys can copypaste & include it in Pine 5 if your see this xd
Here is it.
I've checked and double checked everything, the calculations are right, it can be proved by plotting mean, geometric mean & harmonic mean together and noticing that geometric mean will be always between Harmonic mean, which is always below, and Mean, which is always above.
...
Other central tendency measures are also here as well for usability.
Mean
Ehlers Zero Mean Roofing Filter [CC]The Zero Mean Roofing Filter was created by John Ehlers (Cycle Analytics For Traders pg 80) and this is a much more reactive roofing filter compared to Ehler's Roofing Filter which I also added for reference. Buy when the indicator rises over 0 and sell when the indicator falls below 0.
This was a special request so let me know if there are other indicators you would like to see me publish or if you want something custom done!
Time Range StatisticsA good amount of users requested a text box showing various price statistics, the following script returns various of these stats in a user-selected range, and include classical ones such as a central tendency measurement (mean), dispersion (normalized range) and percent change, but also include less common statistics such as average traded volume and number of gaps. The script also calculates the correlation between the closing price and another user-selected instrument.
The script is currently the longest one I ever made and took some efforts, as I wasn't satisfied with the statistics to be originally included. Big thx to Gael for the enormous feedback and the idea of the normalized range, to user @Cookiecrush for the feedback ( without ya I would have posted something bad you know umu ? ), and Lulidolce for the support, friendship is magic!
Selected Range
The setting Start determine the bar at which the range starts, while End determine at which bar the range end. To help you select these values, the current bar number (bar index) is displayed at the right of the indicator title in blue.
The setting evaluate to last bar will use a range starting at Start and ending at the last bar, as such you can use a full range by using Start = 0 and select evaluate to last bar
The range is highlighted by an area on the chart. By default Start = 9000 and End = 10000, you might not have this amount of data in your chart, as such use the displayed bar index to select Start and End, then set the settings as default.
Displayed Statistics
The statistics panel is displayed on the right side of the last bar, the panel has 3 sections, a title section who shows the symbol ticker, timeframe, and overall trends represented by a chart emoji, the overall trends are determined by comparing the number of higher highs with the number of lower low.
Below are displayed the date ranges with time format: year/month/day/hour:minute.
The second section shows the general statistics. The first one is the mean, also represented by the orange line in the chart, the blue line displayed represent the highest price value in the range, while the red one represents the lowest price value.
The second stat is the normalized range, and determine how spread is the price in the user-selected range, why not the standard deviation? Because the standard deviation might return results varying widely depending on the scale of the closing price, you could get measures such as 0.0156 or 16 or even 56 depending on the instrument, as such using a normalized range can be more appropriate as it lays in a range of (0,1). Lower values indicate a low degree of price variation. Note that I still want to find another measure in the future.
The percentage change (or relative change) indicates at which percentage the price has increased or decreased, and is calculated by subtracting the closing at bar Start with the price at bar End , divided by the price at bar End , the result is then multiplied by 100.
The average traded volume calculate the mean of the volume in the selected range, I used the same format used by the original volume indicator for clarity.
Finally, the last stats of the section is the number of gaps, this stat is by default hidden. An up gap is detected when the open price is superior to the previous high, while a down gap is detected when the open price is inferior to the previous low, this allow to only retain significant gaps.
The last section of the indicator panel shows the correlation between the closing price and another instrument, by default GOOG, this correlation is also calculated within the user-selected range. Positive values indicate a positive relationship, that is the two instruments tend to move in the same direction. Negative values indicate a negative relationship, both instruments tend to move in a direction opposite to each other. Values closer to 1 or -1 indicate a stronger relationship, while values closer to 0 indicate no relationship.
In Summary
The script shows various stats, each calculated within a user-selected range, in general one would be more interested in how these stats might evolve with time, but checking them in a custom range can be quite interesting.
Thx for reading. umu
Rolling deviationsSometimes the market data follows normal distribution, in these cases it is more appropriate to utilize mean-based statistical techniques. This script plots the special case of seven-number summary with 1st, 2nd & 3rd standard deviations below and above the mean.
It also has "Log-space" switch which should be checked while using logarithmic scale.
The next version with minor visual improvs might arrive soon
Mean Reversion w/ Bollinger BandsThis is a more advanced version of my original mean reversion script.
It employs the famous Bollinger Bands.
This robot will buy when price falls below the lower Bollinger Band, and sell when price moves above the upper Bollinger Band.
I've only tested it on the S&P 500, though you could try it out on other assets to see the backtest performance.
During the recent COVID-19 bear market drop, it produced several buy signals on the S&P which I followed, and made some nice gains so far.
I still think this would make a better investing strategy (buy undervalued / sell over-valued), rather than a trading strategy.
I use this robot for my long term portfolio.
Bars above/below EMACount of previous bars above or below a chosen Exponential Moving Average. Typically price reconnects with well defined EMAs regularly. If the price has been above/below an EMA for too long, you can expect a reconnect in a short order and bet on mean reversion strategies.
Mean Absolute Deviation BandsThe other way to build bands around price that uses Mean Absolute Deviation instead of Standard Deviation.
MAD is also a measure of variability, but less frequently used. MAD is better for use with distributions other than the Gaussian.
MAD is always less than or equal to Standard Deviation and the resulting bands are more tighter for the same parameters if we compare it to Bollinger Bands.
If you use band stops this can be useful.
London Breakout with MDX Trailing StopThis indicator aims to aid in using the regular London Breakout strategy, as well as improve on it by adding a trailing stop based on the Mean Deviation Index.
The London Breakout strategy (according to my personal understanding) basically sees the morning before London open as the accumulation or distribution range for large buyers or sellers, and assumes the market will break either above that mornings high or below that mornings low when they start to move price. It is mostly used to trade stock indices and forex.
This indicator plots the morning high and low for each day. The green line is the morning high, and the red line is the morning low. If price moves above the green line (the morning high) it fills that area with a green color. If price moves below the green line (the morning low) it fills that area with a red color. This makes the breakouts easy to spot.
The background color of the chart turns green when the MDX is above 0 (price is more than X times ATR above the mean) and a breakout above the morning high has occurred, and stays green until the opposite happens.
The background color of the chart turns red when the MDX is below 0 (price is more than X times ATR below the mean) and a breakout above the morning high has occurred, and stays green until the opposite happens.
The default for X above is 1.0, but this can be changed in the settings by changing "ATR Multiplier".
The background is always neutral during the morning session since the morning high and morning low are not established yet.
A trailing stop is shown when price is more than X times away from the mean and a breakout has occured. The distance is set using the MDX. The trailing stop uses a separate ATR multiplier though, to make the signal and trailing stop MDX values different, if one likes. The default ATR multiplier for the trailing stop is 1.25, but this can be changed is the settings by changing "ATR multiplier for trailing stop".
When the high or low of a candle breaks the trailing stop, it is moved further away, indicating you have been stopped out, but gives opportunity to use it if you enter again (so it doesn't just disappear).
As an added bonus, take profit levels have been added based on the mornnig range. The take profit distance is set by multiplying the range with a factor. The levels are then plotted that distance from the morning high and morning low.
MDX:
Mean Deviation IndexThe Mean Deviation Index (MDX) is used to see how much price is deviating from the mean. This indicator takes both volatility and mean deviation in consideration.
It uses the standard deviation of the ATR to filter an EMA, and uses this as the mean. It then only plots > or < 0 if price is more than one x ATR away from the mean. If index is positive, the background turns green, meaning price is more than 1 x ATR above the mean. If the index is negative, the background turns red, meaning price is more than 1 x ATR below the mean. This setting can be changed by changing the setting "ATR Multiplier", but the default is 1 x ATR.
There are two main ways to use this index.
1. Use it aggressively to find trends (by combining it with other indicators) by entereding each time the background changes color to green for longs or red for shorts.
2. Use it spot breakouts, waiting for a pullback, and then entering on the next move in the same direction. In this context for a short, you wait for the background color to turn green, then wait for the index to pull back, and then enter once it starts moving up again.
YJ Mean ReversionMean reversion strategy, based upon the price deviation (%) from a chosen moving average (bars). Do note that the "gains" are always relative to your starting capital, so if you set a smaller starting capital (e.g. $10000) your gains will look bigger. Also when the strategy tester has finished calculating, check the "Open P/L", as there could still be open trades.
Some Tips:
- Was designed firstly to work on an index like the S&P 500 , which over time tends to go up in value.
- Avoid trading too frequently (e.g. Daily, Weekly), to avoid getting eaten by fees.
- If you change the underlying asset, or time frame, tweaking the moving average may be necessary.
- Can work with a starting capital of just $1000, optimise the settings as necessary.
- Accepts floating point values for the amount of units to purchase (e.g. Bitcoin ).
- If price of units exceeds available capital, script will cancel the buy.
- Adjusted the input parameters to be more intuitive.
Mean Street V1script for mean reversion conditions - tweak-able based on the volatility of the asset its used on, and the time frame
Forecasting - Simple Mean MethodThis is a continuation of my series on forecasting techniques. The idea behind the Simple Mean method is to somehow extend historical mean to the future. In this case a forecast equals to last value plus average change.
Mean Reversion IndicatorThis is a mean reversion indicator that anticipates a local trend reversion. Basically, it is a channel with the mid-line serving as a moving mean baseline. Each of the two curves run up and down within this channel bouncing off from the top and bottom bounds. Touching the bounds serves as an indication of a local trend reversal. The reversal signal is stronger when there exists a resonance (symmetry) in the two curves. The background histogram shows a Karobein oscillator that contributes support or resistance for the signal.
Seasonality-Buschi
English:
This script shows the price development over the last year (default: green) and mean prices over the last three (default: light green), six (default: orange) and nine (default: red) years and is therefore at least some kind of approach towards true seasonality.
Thanks to user "apozdnyakov" for providing most of the code!
Deutsch:
Dieses Skript zeigt den Kursverlauf über das letzte Jahr (Standard: grün) und die durchschnittlichen Verläufe über die letzten drei (Standard: hellgrün), sechs (Standard: orange) und neun (Standard: rot) Jahre und stellt damit zumindest eine Annäherung zu einer echten Saisonalität dar.
Dank an User "apozdnyakov", der den Großteil des Codes zur Verfügung gestellt hat!
[RESEARCH] Mean Absolute DeviationHello traders and developers!
I was wondering how built-in "dev" function in Pine is calculated so I made a little research.
I examined 7 samples:
0) "dev" function itself
1) "dev" according to its description: series - sma(series)
2) Mean Absolute Deviation
3) ratio of the absolute difference from 1) divided by period
4) ratio of the difference from 1) divided by period
5) Median Absolute Deviation
6) tricky for-loop to calculate Mean Absolute Deviation
The results of the null and sixth samples are identical.
So, TV built-in "dev" function represents Mean Absolute Deviation and it's description is incorrect.
Where it is used? For example: Commodity Channel Index. You can check its original formula and if you used simple standard deviation instead of MAD in your CCIs - well guys, you were wrong.
Good luck!
MCI and VCI - Modified CCI FormulasFor private peeps only
- Takes a modified version of the CCI formula into 2 parts
VCI - Volume Channel Index (Yellow Histogram)
- Measures accurate accumulation and distribution levels and times
MCI - Modified Channel Index
- Measures (when compared to VCI) levels where clearly buys are interested vs not interested.
Example:
If VCI > MCI
- Shows buyer's are more than interested in buying, you've either hit a bottom or heavy resistance
if MCI > VCI
- Show's buyer's aren't interested and will most likely result in a dump/lower price
Great for monitoring accumulation and distribution, these auto buy and sells look for the transition points over 0, works on EVERY commodity/stock/FOREX/Crypto
Results are from trading 1 BTC x25 leveraging. Not all trades will get in if put in at limit, but it does survive with profits after the massive 0.075 fee (results shown are after fees)
Mean Reversion and Momentum - Updated with gaussiana smoothingMean Reversion and Momentum
Interpretation:
- Divergence means trend reversal
- Parallel movement means trend continuation
Squares above serve as a confirming signal
Mean Reversion and Momentum - Indicator versionMean Reversion and Momentum
Interpretation:
- Divergence means trend reversal
- Parallel movement means trend continuation
Squares above serve as a confirming signal
Moving Average Mean Reversion StrategyA basic mean-reversion strategy. Shorts when the close is 10% above the MA, and goes long when it's 10% below the MA.
[PW] Volume Standard DeviationHere is a nice little script that highlights areas of volume using standard deviation, you can choose the look back periods.
This script is based on the excellent script by: @SteynTrade -
I have simplified it a bit and made it readable to my taste using alpha to highlight high volume areas.
Enjoy.