Price Ratio Indicator
Updated
May 14, 2024
TradingView

For free use on the TradingView platform

◈ User Inputs:

  • MA Length: Specifies the length of the moving average used in the calculation.
  • MA Type Fast: Allows users to choose from various types of moving averages such as Exponential Moving Average (EMA), Simple Moving Average (SMA), Weighted Moving Average (WMA), Volume Weighted Moving Average (VWMA), Relative Moving Average (RMA), Double Exponential Moving Average (DEMA), Triple Exponential Moving Average (TEMA), Zero-Lag Exponential Moving Average (ZLEMA), and Hull Moving Average (HMA).
  • Upper Level and Lower Level: Define the threshold levels for identifying overbought and oversold conditions.
  • Signal Line Length: Determines the length of the signal line used for smoothing the indicator's values.

◈ Indicator Calculation:

The indicator calculates the ratio between the price of the asset and the selected moving average, subtracts 1 from the ratio, and then smooths the result using the chosen signal line length.


// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
//@ Moving Average's Function
ma(src, ma_period, ma_type) =>
    ma = 
     ma_type == 'EMA' ? ta.ema(src, ma_period) :
     ma_type == 'SMA' ? ta.sma(src, ma_period) :
     ma_type == 'WMA' ? ta.wma(src, ma_period) :
     ma_type == 'VWMA' ? ta.vwma(src, ma_period) :
     ma_type == 'RMA' ? ta.rma(src, ma_period) :
     ma_type == 'DEMA' ? ta.ema(ta.ema(src, ma_period), ma_period) :
     ma_type == 'TEMA' ? ta.ema(ta.ema(ta.ema(src, ma_period), ma_period), ma_period) :
     ma_type == 'ZLEMA' ? ta.ema(src + src - src[math.round(ma_period / 2)], ma_period) :
     ma_type == 'HMA' ? ta.hma(src, ma_period) 
     : na
    ma


//@ Smooth of Source
src = math.sum(source, 5)/5

//@ Ratio Price / MA's
p_ratio = src / ma(src, ma_period, ma_type) - 1

◈ Visualization:

  • The main plot displays the price ratio, with color gradients indicating the strength and direction of the ratio.
  • The bar color changes dynamically based on the ratio, providing a visual representation of market conditions.
  • Invisible Horizontal lines indicate the upper and lower threshold levels for overbought and oversold conditions.
  • A signal line, smoothed using the specified length, helps identify trends and potential reversal points.
  • High and low value regions are filled with color gradients, enhancing visualization of extreme price movements.

MA type HMA gives faster changes of the indicator (Each MA has its own specifics):

MA type TEMA:

◈ Additional Features:

A symbol displayed at the bottom right corner of the chart provides a quick visual reference to the current state of the indicator, with color intensity indicating the strength of the ratio.

Overall, the Price Ratio Indicator offers traders valuable insights into price dynamics and helps them make informed trading decisions based on the relationship between price and moving averages. Adjusting the input parameters allows for customization according to individual trading preferences and market conditions.

May 13

Release Notes:

The Price Ratio Indicator is a versatile tool designed to analyze the relationship between the price of an asset and its moving average. It helps traders identify overbought and oversold conditions in the market, as well as potential trend reversals.



◈ User Inputs:

  • MA Length: Specifies the length of the moving average used in the calculation.
  • MA Type Fast: Allows users to choose from various types of moving averages such as Exponential Moving Average (EMA), Simple Moving Average (SMA), Weighted Moving Average (WMA), Volume Weighted Moving Average (VWMA), Relative Moving Average (RMA), Double Exponential Moving Average (DEMA), Triple Exponential Moving Average (TEMA), Zero-Lag Exponential Moving Average (ZLEMA), and Hull Moving Average (HMA).
  • Upper Level and Lower Level: Define the threshold levels for identifying overbought and oversold conditions.
  • Signal Line Length: Determines the length of the signal line used for smoothing the indicator's values.




◈ Indicator Calculation:
The indicator calculates the ratio between the price of the asset and the selected moving average, subtracts 1 from the ratio, and then smooths the result using the chosen signal line length.


// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
//@ Moving Average's Function
ma(src, ma_period, ma_type) =>
    ma = 
     ma_type == 'EMA' ? ta.ema(src, ma_period) :
     ma_type == 'SMA' ? ta.sma(src, ma_period) :
     ma_type == 'WMA' ? ta.wma(src, ma_period) :
     ma_type == 'VWMA' ? ta.vwma(src, ma_period) :
     ma_type == 'RMA' ? ta.rma(src, ma_period) :
     ma_type == 'DEMA' ? ta.ema(ta.ema(src, ma_period), ma_period) :
     ma_type == 'TEMA' ? ta.ema(ta.ema(ta.ema(src, ma_period), ma_period), ma_period) :
     ma_type == 'ZLEMA' ? ta.ema(src + src - src[math.round(ma_period / 2)], ma_period) :
     ma_type == 'HMA' ? ta.hma(src, ma_period) 
     : na
    ma


//@ Smooth of Source
src = math.sum(source, 5)/5

//@ Ratio Price / MA's
p_ratio = src / ma(src, ma_period, ma_type) - 1

◈ Visualization:

  • The main plot displays the price ratio, with color gradients indicating the strength and direction of the ratio.
  • The bar color changes dynamically based on the ratio, providing a visual representation of market conditions.
  • Invisible Horizontal lines indicate the upper and lower threshold levels for overbought and oversold conditions.
    It is important to know that when changing an asset or timeframe, you must always adjust the range of levels:
  • A signal line, smoothed using the specified length, helps identify trends and potential reversal points.
  • High and low value regions are filled with color gradients, enhancing visualization of extreme price movements.

MA type HMA gives faster changes of the indicator (Each MA has its own specifics):

MA type TEMA:

◈ Additional Features:

A symbol displayed at the bottom right corner of the chart provides a quick visual reference to the current state of the indicator, with color intensity indicating the strength of the ratio.

Overall, the Price Ratio Indicator offers traders valuable insights into price dynamics and helps them make informed trading decisions based on the relationship between price and moving averages. Adjusting the input parameters allows for customization according to individual trading preferences and market conditions.

May 14

Release Notes:

Normalization Range (No need to adjust levels when changing asset or timeframe)


// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ChartPrime

//@version=5
indicator('Price Ratio Indicator [ChartPrime]', shorttitle = "Price Ratio [ChartPrime]")

// 𝙄𝙉𝙋𝙐𝙏𝙎
//@ User Inputs
int ma_period            = input.int(100, "MA Length", group = "MA's Settings")
series float source      = input.source(close, group = "MA's Settings")
string ma_type           = input.string('RMA', 'MA Type Fast',
                                         options=['EMA', 'SMA', 'WMA', 'VWMA', 'RMA', 'DEMA', 'TEMA', 'ZLEMA', 'HMA'],
                                         group = "MA's Settings")
float h_level            = input.float(1.5, step = 0.1,  title = "Upper Level", group = "Levels")
float l_level            = input.float(-1.5, step = 0.1, title = "Lower Level", group = "Levels")
int sigline              = input.int(25, "Signal Line Length")

// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
//@ Moving Average's Function
ma(src, ma_period, ma_type) =>
    ma = 
     ma_type == 'EMA' ? ta.ema(src, ma_period) :
     ma_type == 'SMA' ? ta.sma(src, ma_period) :
     ma_type == 'WMA' ? ta.wma(src, ma_period) :
     ma_type == 'VWMA' ? ta.vwma(src, ma_period) :
     ma_type == 'RMA' ? ta.rma(src, ma_period) :
     ma_type == 'DEMA' ? ta.ema(ta.ema(src, ma_period), ma_period) :
     ma_type == 'TEMA' ? ta.ema(ta.ema(ta.ema(src, ma_period), ma_period), ma_period) :
     ma_type == 'ZLEMA' ? ta.ema(src + src - src[math.round(ma_period / 2)], ma_period) :
     ma_type == 'HMA' ? ta.hma(src, ma_period) 
     : na
    ma


//@ Smooth of Source
src = math.sum(source, 5)/5

//@ Ratio Price / MA's
p_ratio = src / ma(src, ma_period, ma_type) - 1
//@ Normalization
p_ratio := (p_ratio - 0) / ta.stdev(p_ratio, 200)/4

//@ Color Gradient Function
color_(src) => 
    src > 0 ? color.from_gradient(src, 0, ta.highest(src, 250), color.rgb(113, 189, 69), color.red)
     : color.from_gradient(src, ta.lowest(src, 150), 0, color.aqua, color.green)

// 𝙑𝙄𝙎𝙐𝘼𝙇𝙄𝙕𝘼𝙏𝙄𝙊𝙉
//@ Ratio Plot
p1 = plot(p_ratio, color = color_(p_ratio), linewidth = 2)

//@ Bar HeatColor
barcolor(color_(p_ratio))

//@ Valuation Levels
p3 = plot(l_level, color = na)
p2 = plot(h_level, color = na)
//@ Mid Line
hline(0, color = color.gray)
// Signal Line
plot(ta.sma(p_ratio, sigline), color = #787b8648)

//@ High Value Color
fill(p1, p2, h_level, p_ratio, color.from_gradient(p_ratio, h_level/3, p_ratio, na, color.red), na)

//@ Low Value Color
fill(p1, p3, l_level, p_ratio, p_ratio < l_level/3 ? color.from_gradient(p_ratio, p_ratio, l_level/3, color.aqua, na) : na, na)

// 
var table tbl = table.new(position.bottom_right, 1, 1)
tbl.cell(0,0,"◈", text_color = color.new(color_(p_ratio), 50), text_size = size.huge)

Get access to our Exclusive
premium indicators