Indicator · Pine Script v6 · Own pane

Intrabar Efficiency Ratio

by regalouisei· code credited to TradingView

Intrabar Efficiency Ratio calculates an efficiency ratio indicator using lower timeframe intrabar data to measure price efficiency and market noise.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code261
Settings23inputs
LicenceNone statedfile: MPL-2.0
Last update8 months ago25 Feb 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

261 lines of Pine Script v6 from pinescript/editors_picks/intrabar-efficiency-ratio.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

intrabar-efficiency-ratio.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TradingView

//@version=6
indicator("Intrabar Efficiency Ratio", precision = 4)

// Intrabar Efficiency Ratio indicator
// v3, 2026.01.09

// This code's style is based on the recommendations from the Pine Script User Manual's Style guide:
//    https://www.tradingview.com/pine-script-docs/writing/style-guide/



import PineCoders/Time/5 as PCtime
import PineCoders/lower_tf/5 as PCltf



//#region ———————————————————— Constants and Inputs


// ————— Constants

// Colors
color  AQUA    = color.aqua
color  FUCHSIA = color.fuchsia
color  GRAY    = #80808080
color  GRAY_LT = #f5f3f3
color  LIME    = color.lime
color  MAROON  = color.maroon
color  ROYAL   = #3BB3E4
color  ROSE    = #FF0080
color  TEAL    = color.teal
color  WHITE   = color.white
color  YELLOW  = color.yellow

// MAs
string MA01 = "Simple"
string MA02 = "Exponential"
string MA03 = "Wilder (RMA)"
string MA04 = "Weighted"
string MA05 = "Volume-Weighted"
string MA06 = "Arnaud Legoux"
string MA07 = "Hull"

// LTF distinction
string LTF1  = "Covering most chart bars (least precise)"
string LTF2  = "Covering some chart bars (less precise)"
string LTF3  = "Covering less chart bars (more precise)"
string LTF4  = "Covering few chart bars (very precise)"
string LTF5  = "Covering the least chart bars (most precise)"
string LTF6  = "~12 intrabars per chart bar"
string LTF7  = "~24 intrabars per chart bar"
string LTF8  = "~50 intrabars per chart bar"
string LTF9  = "~100 intrabars per chart bar"
string LTF10 = "~250 intrabars per chart bar"

// Display types
string DT01 = "Line"
string DT02 = "Candles"
string DT03 = "Circles"

// Tooltips
string TT_DT = (
    "Three display options are available:"
    + "\n• 'Line' displays an IER-based moving average of the selected type using the medium length."
    + "\n• 'Candles' displays candles using the IER value and the short and long MAs."
    + "\n• 'Circles' displays circles to show the values of all three IER-based MAs."
)
string TT_LTF  = (
    "Controls the number of intrabars that the indicator analyzes per chart bar. "
    + "Increasing the intrabars per chart bar enables more precise calculations. However, it also reduces the number "
    + "of chart bars that the indicator can analyze. "
    + "The first five options determine the requested lower timeframe based on a desired relative amount of chart bar "
    + "coverage. The last five determine the timeframe based on an approximate number of intrabars per chart bar."
)
string TT_CDL = (
    "Specifies the colors for the 'Candle' display in the following order: "
    + "down body, down wick, up body, up wick."
)
string TT_CIR = (
    "Specifies the colors for the 'Circles' display in the following order: "
    + "extreme low, down color, up color, extreme high."
)
string TT_RW  = (
    "If selected, the indicator applies weighting to IER values based on the percentage rank of the close-to-close "
    + "price change over the specified number of bars."
)
string TT_LEN = (
    "The short, medium and long lengths for the moving averages. Different display modes use different "
    + "MAs. Only the 'Circles' display uses all three."
)

// ————— Inputs

string  GRP1 = "Visuals"
string  displayTypeInput        = input.string(DT01,     "Display",                  group = GRP1, inline = "10", options = [DT01, DT02, DT03], tooltip = TT_DT)
bool    isLine                  = displayTypeInput == DT01
bool    isCandles               = displayTypeInput == DT02
bool    isCircles               = displayTypeInput == DT03
color   lineColorInput          = input.color(AQUA,      "Line   ",                  group = GRP1, inline = "13", active =isLine)
color   bearBodyInput           = input.color(FUCHSIA,   "Candles",                  group = GRP1, inline = "11", active = isCandles, tooltip = TT_CDL)
color   bearWickInput           = input.color(MAROON,    "",                         group = GRP1, inline = "11", active = isCandles)
color   bullBodyInput           = input.color(LIME,      "",                         group = GRP1, inline = "11", active = isCandles)
color   bullWickInput           = input.color(TEAL,      "",                         group = GRP1, inline = "11", active = isCandles)
color   lowColorInput           = input.color(YELLOW,    "Circles ",                 group = GRP1, inline = "12", active = isCircles, tooltip = TT_CIR)
color   bearColorInput          = input.color(ROSE,      "",                         group = GRP1, inline = "12", active = isCircles)
color   bullColorInput          = input.color(ROYAL,     "",                         group = GRP1, inline = "12", active = isCircles)
color   highColorInput          = input.color(LIME,      "",                         group = GRP1, inline = "12", active = isCircles)
bool    showInfoBoxInput        = input.bool(true,       "Show information box ",    group = GRP1)
string  infoBoxSizeInput        = input.string("small",  "Size ",                    group = GRP1, inline = "14", active = showInfoBoxInput, options = ["tiny", "small", "normal", "large", "huge", "auto"])
string  infoBoxYPosInput        = input.string("bottom", "↕",                        group = GRP1, inline = "14", active = showInfoBoxInput, options = ["top", "middle", "bottom"])
string  infoBoxXPosInput        = input.string("right",  "↔",                        group = GRP1, inline = "14", active = showInfoBoxInput, options = ["left", "center", "right"])
color   infoBoxColorInput       = input.color(GRAY,      "",                         group = GRP1, inline = "14", active = showInfoBoxInput)
color   infoBoxTxtColorInput    = input.color(GRAY_LT,   "T",                        group = GRP1, inline = "14", active = showInfoBoxInput)

string  GRP2 = "Settings"
string  ltfModeInput            = input.string(LTF3,     "Intrabar precision",       group = GRP2, options = [LTF1, LTF2, LTF3, LTF4, LTF5, LTF6, LTF7, LTF8, LTF9, LTF10], tooltip = TT_LTF)
string  maTypeInput             = input.string(MA06,     "MA type ",                 group = GRP2, inline = "20", options = [MA01, MA02, MA03, MA04, MA05, MA06, MA07])
int     shortLengthInput        = input.int(10,          "MA lengths: S",            group = GRP2, inline = "21", active = isCandles or isCircles)
int     midLengthInput          = input.int(20,          "M",                        group = GRP2, inline = "21", active = isLine or isCircles)
int     longLengthInput         = input.int(40,          "L",                        group = GRP2, inline = "21", active = isCandles or isCircles, tooltip = TT_LEN)
bool    rankWeightInput         = input.bool(false,      "Weigh using relative close changes", group = GRP2, inline = "22")
int     rankLengthInput         = input.int(100,         "",                         group = GRP2, inline = "22", tooltip = TT_RW, active = rankWeightInput)
//#endregion



//#region ———————————————————— Functions


// @function        Calculates a moving average of a source series, with a specified type and length.
// @param source    (series float) The series of values to process.
// @param length    (simple int) The length value for the moving average.
// @param maType    (simple string) Specifies the type of moving average. Accepts the value of one of the `MA*`
//                  constants declared above.
// @returns         (float) The moving average of the `source` series.
ma(series float source, simple int length, simple string maType) =>
    float result = switch maType
        MA01 => ta.sma(source,  length)
        MA02 => ta.ema(source,  length)
        MA03 => ta.rma(source,  length)
        MA04 => ta.wma(source,  length)
        MA05 => ta.vwma(source, length)
        MA06 => ta.alma(source, length, 0.85, 6)
        MA07 => ta.hma(source,  length)
        => na


// @function        Selects an input color (`highColorInput`, `lowColorInput`, `bullColorInput`, or `bearColorInput`)
//                  based on the 100-bar percent rank of the specified value.
// @param value     (series float) The series of values for which to calculate the color.
// @returns         (color) The selected input color.
plotColor(series float value) =>
    float percent = ta.percentrank(value, 100)
    color result = switch
        percent > 90 => highColorInput
        percent < 10 => lowColorInput
        percent > 50 => bullColorInput
        =>              bearColorInput
//#endregion



//#region ———————————————————— Calculations


// @variable A string representing the lower timeframe for which to retrieve intrabar data.
var string ltfString = PCltf.ltf(ltfModeInput, LTF1, LTF2, LTF3, LTF4, LTF5, LTF6, LTF7, LTF8, LTF9, LTF10)

// Retrieve the absolute bar-to-bar change in the `close` value for each intrabar in the chart bar, and compute the sum.
array<float> travels = request.security_lower_tf(
    syminfo.tickerid, ltfString, math.abs(ta.change(close)), calc_bars_count = 200000
)
float totalTravels   = travels.sum()
// Calculate the one-bar change in the `close` value on the chart's timeframe.
float chartBarChange = nz(ta.change(close))

// Calculate a weight using the relative size of the one-bar price change.
float weight = rankWeightInput ? ta.percentrank(math.abs(chartBarChange), rankLengthInput) / 100.0 : 1.0

// Compute the IER and its MAs.
float ier     = nz(chartBarChange / totalTravels) * weight
float maLong  = ma(ier, longLengthInput,  maTypeInput)
float maMid   = ma(ier, midLengthInput,   maTypeInput)
float maShort = ma(ier, shortLengthInput, maTypeInput)

// Calculate candle data.
float o = maLong
float h = math.max(ier, maLong, maShort)
float l = math.min(ier, maLong, maShort)
float c = maShort
color candleColor = c > o ? bullBodyInput : bearBodyInput
color wickColor   = c > o ? bullWickInput : bearWickInput

// Retrieve intrabar and chart bar information for the table display.
[intrabars, chartBarsCovered, avgIntrabars] = PCltf.ltfStats(travels)
int chartBars = bar_index + 1
//#endregion



//#region ———————————————————— Visuals


// Declare variables to store display settings for the plots.
candlePlotDisplay = isCandles ? display.all  - display.pane : display.none
candleDisplay     = isCandles ? display.pane : display.none
circleDisplay     = isCircles ? display.all  : display.none
lineDisplay       = isLine    ? display.all  : display.none

// Plot the candle values.
plot(o, "IER candle open",  candleColor, display = candlePlotDisplay)
plot(h, "IER candle high",  wickColor,   display = candlePlotDisplay)
plot(l, "IER candle low",   wickColor,   display = candlePlotDisplay)
plot(c, "IER candle close", candleColor, display = candlePlotDisplay)
plotcandle(o, h, l, c, "IER candles", candleColor, wickColor, bordercolor = candleColor, display = candleDisplay)

// Plot the IER-based MAs.
plot(maLong,  "Long MA",  color.new(plotColor(maLong),  20), 2, plot.style_circles, display = circleDisplay)
plot(maMid,   "Mid MA",   color.new(plotColor(maMid),   10), 1, plot.style_circles, display = circleDisplay)
plot(maShort, "Short MA", color.new(plotColor(maShort),  0), 1, plot.style_circles, display = circleDisplay)
plot(maMid,   "Mid MA",   lineColorInput,                    1, plot.style_line,    display = lineDisplay)
hline(0)

// Plot key information in the status line and the Data Window.
displayLocations = display.status_line + display.data_window
plot(ier,               "Intrabar Efficiency Ratio", display = displayLocations)
plot(intrabars,         "Intrabars in chart bar",    display = displayLocations)
plot(avgIntrabars,      "Avg. intrabars",            display = displayLocations)
plot(chartBarsCovered,  "Chart bars covered",        display = displayLocations)
plot(chartBars,         "Total chart bars",          display = displayLocations)
plot(totalTravels,      "totalTravels",              display = displayLocations)
plot(chartBarChange,    "chartBarChange",            display = displayLocations)
plot(weight,            "weight",                    display = displayLocations)

// Logic for the information box display
if showInfoBoxInput
    var table infoBox = table.new(infoBoxYPosInput + "_" + infoBoxXPosInput, 1, 1)
    string formattedLtf = PCtime.formattedNoOfPeriods(timeframe.in_seconds(ltfString) * 1000)
    string txt = str.format(
        "Intrabar timeframe: {0}\nAvg intrabars per chart bar: {1,number,#.#}\nChart bars covered: {2} of {3}",
        formattedLtf, avgIntrabars, chartBarsCovered, chartBars
    )
    if barstate.isfirst
        table.cell(
            infoBox, 0, 0, txt, text_color = infoBoxTxtColorInput, text_size = infoBoxSizeInput,
            bgcolor = infoBoxColorInput
        )
    else if barstate.islast
        table.cell_set_text(infoBox, 0, 0, txt)

// Runtime errors
if ta.cum(intrabars) == 0 and barstate.islast
    runtime.error(str.format("No intrabar information available for the ''{0}'' timeframe.", ltfString))
else if shortLengthInput > midLengthInput
    runtime.error("The length of the short MA must be less than or equal to that of the medium MA.")
else if midLengthInput > longLengthInput
    runtime.error("The length of the medium MA must be less than or equal to that of the long MA.")
//#endregion

Overview

Intrabar Efficiency Ratio plots in a separate pane using customizable visual modes such as Line, Candles, or Circles based on moving averages of short, medium, and long lengths. Users can select from several moving average types, adjust intrabar resolution precision, and optionally weight values by relative price change rank. An optional info box displays key settings and metrics.

Details

Published by

regalouisei on GitHub

Code credit

TradingView, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Moving averages, Volatility & bands, Oscillators & momentum

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
DisplaystringDT01displayTypeInput
Line   colorAQUAlineColorInput
CandlescolorFUCHSIAbearBodyInput
bearWickInputcolorMAROONbearWickInput
bullBodyInputcolorLIMEbullBodyInput
bullWickInputcolorTEALbullWickInput
Circles colorYELLOWlowColorInput
bearColorInputcolorROSEbearColorInput
bullColorInputcolorROYALbullColorInput
highColorInputcolorLIMEhighColorInput
Show information box booltrueshowInfoBoxInput
Size stringsmallinfoBoxSizeInput
Show all 23 settings
SettingTypeDefaultVariable
↕stringbottominfoBoxYPosInput
↔stringrightinfoBoxXPosInput
infoBoxColorInputcolorGRAYinfoBoxColorInput
TcolorGRAY_LTinfoBoxTxtColorInput
Intrabar precisionstringLTF3ltfModeInput
MA type stringMA06maTypeInput
MA lengths: Sint10shortLengthInput
Mint20midLengthInput
Lint40longLengthInput
Weigh using relative close changesboolfalserankWeightInput
rankLengthInputint100rankLengthInput
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V

MultiIndicator

by capissimo
114 stars

MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator

PPO ATR Bands

by cryptorife
75 stars

PPO ATR Bands plots a percentage price oscillator in a separate pane. It compares a Hull average of typical price with a volume-weighted exponential average of Parabolic SAR, then scales three true-range bands around the slow average into matching oscillator l

Indicator v4 Oscillators & momentumMoving averages
Updated 3 years ago · GPL-3.0 GitHub repository of PPO ATR Bands

This indicator plots a relative strength index in a separate pane. It calculates RSI from the average of the previous ten opens rather than the current bar, so that source does not change during the live candle. A moving average of the RSI is plotted and can b

Indicator v5 Oscillators & momentumMoving averages
Updated 2 years ago · None stated GitHub repository of No Repaint - Relative Strength Index

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers