OPEN-SOURCE SCRIPT

The "Moving Average Ratio" (MAR) indicator is a versatile tool designed for valuation, mean-reversion, and long-term trend analysis. This indicator provides multiple display modes to cater to different analytical needs, allowing traders and investors to gain deeper insights into the market dynamics.

- Calculates the ratio of the chosen source (close, open, ohlc4, hl2 …) to a longer-term moving average of choice (SMA, EMA, HMA, WMA, DEMA)
- Useful for identifying overbought or oversold conditions, aiding in mean-reversion strategies and valuation of assets.
- For some high beta asset classes, like cryptocurrencies, you might want to use logarithmic scale for the raw MAR, below you can see the visual difference of using Linear and Logarithmic scale on BTC

- Computes the Z-Score of the MAR to standardize the ratio over chosen time period, making it easier to identify extreme values relative to the historical mean.
- Helps in detecting significant deviations from the mean, which can indicate potential reversal points and buying/selling opportunities

- Uses a combination of short-term (default 1, raw MAR) and long-term moving averages of the MAR to identify trend changes.
- Provides a visual representation of bullish and bearish trends based on moving average crossings.
- Using Logarithmic scale can improve the visuals for some asset classes.

- Measures the momentum of the MAR by calculating the difference over a specified period.
- Useful for detecting changes in the market momentum and potential trend reversals.

- Calculates the rate of change of the MAR to assess the speed and direction of price movements.
- Helps in identifying accelerating or decelerating trends.

MAR Momentum and Rate of Change are very similar, the only difference is that the Momentum is expressed in units of the MAR change and ROC is expressed as % change of MAR over chosen time period.

- Display Mode: Select the display mode from MAR, MAR Z-Score, MAR Trend, MAR Momentum, or MAR ROC.
- Color Bars: Option to color the bars based on the current display mode.
- Wait for Bar Close: Toggle to wait for the bar to close before updating the MAR value.

- Length: Period for the moving average calculation.
- Source: Data source for the moving average calculation.
- Moving Average Type: Select the type of moving average (SMA, EMA, WMA, HMA, DEMA).

- Z-Score Length: Period for the Z-Score calculation.

- Moving Average Type: Select the type of moving average for trend analysis (SMA, EMA).
- Longer Moving Average: Period for the longer moving average.
- Shorter Moving Average: Period for the shorter moving average.

- Momentum Length: Period for the momentum calculation.

- ROC Length: Period for the rate of change calculation.

- Calculates the ratio of the price to the selected moving average type and length.
- Plots the MAR with a gradient color based on its Z-Score, aiding in visual identification of extreme values.

- Computes the Z-Score of the MAR and plots it with a color gradient indicating the magnitude of deviation from the mean.

- Plots the MAR along with its short-term and long-term moving averages.
- Uses color changes to indicate bullish or bearish trends based on moving average crossings.

- Plots the momentum of the MAR, coloring the bars to indicate increasing or decreasing momentum.

- Plots the ROC of the MAR, using color changes to show the direction and strength of the rate of change.

This multi-purpose indicator provides a comprehensive toolset for various trading strategies, including valuation, mean-reversion, and trend analysis. By offering multiple display modes and customizable settings, it allows users to tailor the indicator to their specific analytical needs and market conditions.

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.