Indicator · Pine Script v5 · On the chart

Electrocardiogram Chart

by regalouisei· code credited to HeWhoMustNotBeNamed

This indicator reimagines price action as an electrocardiogram wave directly on the main chart pane.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code134
Settings1inputs
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

134 lines of Pine Script v5 from pinescript/editors_picks/electrocardiogram-chart.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

electrocardiogram-chart.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HeWhoMustNotBeNamed

//   __    __            __       __  __                  __       __                        __      __    __              __      _______             __    __                                          __ 
//  /  |  /  |          /  |  _  /  |/  |                /  \     /  |                      /  |    /  \  /  |            /  |    /       \           /  \  /  |                                        /  |
//  $$ |  $$ |  ______  $$ | / \ $$ |$$ |____    ______  $$  \   /$$ | __    __   _______  _$$ |_   $$  \ $$ |  ______   _$$ |_   $$$$$$$  |  ______  $$  \ $$ |  ______   _____  ____    ______    ____$$ |
//  $$ |__$$ | /      \ $$ |/$  \$$ |$$      \  /      \ $$$  \ /$$$ |/  |  /  | /       |/ $$   |  $$$  \$$ | /      \ / $$   |  $$ |__$$ | /      \ $$$  \$$ | /      \ /     \/    \  /      \  /    $$ |
//  $$    $$ |/$$$$$$  |$$ /$$$  $$ |$$$$$$$  |/$$$$$$  |$$$$  /$$$$ |$$ |  $$ |/$$$$$$$/ $$$$$$/   $$$$  $$ |/$$$$$$  |$$$$$$/   $$    $$< /$$$$$$  |$$$$  $$ | $$$$$$  |$$$$$$ $$$$  |/$$$$$$  |/$$$$$$$ |
//  $$$$$$$$ |$$    $$ |$$ $$/$$ $$ |$$ |  $$ |$$ |  $$ |$$ $$ $$/$$ |$$ |  $$ |$$      \   $$ | __ $$ $$ $$ |$$ |  $$ |  $$ | __ $$$$$$$  |$$    $$ |$$ $$ $$ | /    $$ |$$ | $$ | $$ |$$    $$ |$$ |  $$ |
//  $$ |  $$ |$$$$$$$$/ $$$$/  $$$$ |$$ |  $$ |$$ \__$$ |$$ |$$$/ $$ |$$ \__$$ | $$$$$$  |  $$ |/  |$$ |$$$$ |$$ \__$$ |  $$ |/  |$$ |__$$ |$$$$$$$$/ $$ |$$$$ |/$$$$$$$ |$$ | $$ | $$ |$$$$$$$$/ $$ \__$$ |
//  $$ |  $$ |$$       |$$$/    $$$ |$$ |  $$ |$$    $$/ $$ | $/  $$ |$$    $$/ /     $$/   $$  $$/ $$ | $$$ |$$    $$/   $$  $$/ $$    $$/ $$       |$$ | $$$ |$$    $$ |$$ | $$ | $$ |$$       |$$    $$ |
//  $$/   $$/  $$$$$$$/ $$/      $$/ $$/   $$/  $$$$$$/  $$/      $$/  $$$$$$/  $$$$$$$/     $$$$/  $$/   $$/  $$$$$$/     $$$$/  $$$$$$$/   $$$$$$$/ $$/   $$/  $$$$$$$/ $$/  $$/  $$/  $$$$$$$/  $$$$$$$/ 
//                                                                                                                                                                                                          
//                                                                                                                                                                                                          
//
//@version=5
indicator("Electrocardiogram Chart", "ECG", overlay = true, max_lines_count=500, max_boxes_count = 100)

numberOfBars = input.int(25, "Number Of Bars", minval=25, maxval=100, step=25)

type HeartBeatCandle
    float _open
    float _first
    float _second
    float _close
    int _time
    color _lineColor
    color _borderColor
    color _bodyColor

type HeartBeatCandleDrawing
    line _open_open
    line _open_first
    line _first_second
    line _second_close
    line _close_close
    box _envelope
    label _info

getStrTime(int _time)=>
    _year = str.tostring(year(_time))
    _month = str.tostring(month(_time))
    _day = str.tostring(dayofmonth(_time))
    _hour = str.tostring(hour(_time))
    _minute = str.tostring(minute(_time))
    _second = str.tostring(second(_time))
    strTime = _year + '-' + _month + '-'+_day+ 'T' + _hour + ':' + _minute + ':' + _second
    strTime

unshift(array<HeartBeatCandle> heartBeatCandles, HeartBeatCandle heartBeatCandle, simple int maxItems=100)=>
    array.unshift(heartBeatCandles, heartBeatCandle)
    if(array.size(heartBeatCandles) > maxItems)
        array.pop(heartBeatCandles)

clear(array<HeartBeatCandleDrawing> heartBeatDrawings)=>
    size = array.size(heartBeatDrawings)
    for i=1 to size!=0? size : na
        drawing = array.pop(heartBeatDrawings)
        line.delete(drawing._open_open)
        line.delete(drawing._open_first)
        line.delete(drawing._first_second)
        line.delete(drawing._second_close)
        line.delete(drawing._close_close)
        box.delete(drawing._envelope)
        label.delete(drawing._info)

maxItems = 100

[lo, lh, ll, lc, lv] = request.security_lower_tf(syminfo.tickerid, '1', [open, high, low, close, volume], true)

var heartBeatCandles = array.new<HeartBeatCandle>()
if(bar_index >= last_bar_index-maxItems)
    hIndices = array.sort_indices(lh, order.descending)
    highestIndex = array.size(hIndices) > 0? array.get(hIndices, 0) : na
    lIndices = array.sort_indices(ll, order.ascending)
    lowestIndex = array.size(lIndices) > 0? array.get(lIndices, 0) : na

    nOpen = array.size(hIndices) > 0? array.get(lo, 0) : na
    nClose = array.size(hIndices) > 0? array.get(lc, array.size(lc)-1) : na

    firstPeak = highestIndex <= lowestIndex? high : low
    secondPeak = highestIndex <= lowestIndex? low : high

    lineColor =  highestIndex >= lowestIndex? color.green : color.red

    borderColor = close >= close[1]? color.green : color.red
    bodyColor = close >= open? color.green : color.red

    if(array.size(lo) > 0 and array.min(ll) == low and array.max(lh) == high)
        heartBeatCandle = HeartBeatCandle.new(nOpen, firstPeak, secondPeak, nClose, time, lineColor, borderColor, bodyColor)
        unshift(heartBeatCandles, heartBeatCandle, numberOfBars)

var startBarIndex = 0
var heartBeatDrawings = array.new<HeartBeatCandleDrawing>()
lowOffset = 2*(ta.highest(numberOfBars)[1] - ta.lowest(numberOfBars*5)[1])

bgcolor(color.new(color.aqua, 90), show_last = numberOfBars)
clear(heartBeatDrawings)

if(barstate.islast)
    endBar = bar_index
    for candle in heartBeatCandles
        boxEnd = endBar
        closeEndBar = boxEnd-1
        closeStartBar = closeEndBar -1
        secondPeakBar = closeStartBar -1
        firstPeakBar = secondPeakBar -1
        openEndBar = firstPeakBar -1
        openStartBar = openEndBar -1
        boxStart = openStartBar -1
        endBar := boxStart - 1

        cOpen = candle._open - lowOffset
        cFirstBar = candle._first - lowOffset
        cSecondBar = candle._second - lowOffset
        cClose = candle._close - lowOffset

        _open_open = line.new(openStartBar, cOpen, openEndBar, cOpen, color=candle._lineColor, style=line.style_solid, width=1)
        _open_first = line.new(openEndBar, cOpen, firstPeakBar, cFirstBar,color=candle._lineColor, style=line.style_solid, width=1)
        _first_second = line.new(firstPeakBar, cFirstBar, secondPeakBar, cSecondBar,color=candle._lineColor, style=line.style_solid, width=1)
        _second_close = line.new(secondPeakBar, cSecondBar, closeStartBar, cClose,color=candle._lineColor, style=line.style_solid, width=1)
        _close_close = line.new(closeStartBar, cClose, closeEndBar, cClose, color=candle._lineColor, style=line.style_solid, width=1)
        adj = 0.2*math.abs(cFirstBar-cSecondBar)
        
        _high = math.max(cFirstBar, cSecondBar)
        _low = math.min(cFirstBar, cSecondBar)
        boxHigh = _high+adj
        boxLow = _low-adj
        strInfo = str.tostring(array.from(candle._open, _high, _low, candle._close))+'\n'+str.format_time(candle._time, 'yyyy-MM-dd / hh:mm:ss', syminfo.timezone)
        _envelope = box.new(boxStart, boxHigh, boxEnd, boxLow, candle._borderColor, bgcolor=color.new(candle._bodyColor, 80))
                 //,text = strInfo, text_valign = text.align_bottom, text_color = color.yellow, text_size = size.tiny)
        _info = label.new((boxStart+boxEnd+1)/2, boxLow, yloc = yloc.price, style = label.style_none, tooltip = strInfo, text='   \n   \n   \n   \n   \n   \n   ', textalign = text.align_center)
        heartBeatDrawing = HeartBeatCandleDrawing.new(_open_open, _open_first, _first_second, _second_close, _close_close, _envelope, _info)
        array.push(heartBeatDrawings, heartBeatDrawing)

Overview

Electrocardiogram Chart converts standard bar data into heartbeat-style paths using custom data structures, plotting interconnected line segments that link open, internal swing, and close levels inside bounding box envelopes. The primary setting adjusts the total number of historical bars rendered. It functions purely as an alternative chart visualization tool without trade signals, alerts, or execution logic.

Details

Published by

regalouisei on GitHub

Code credit

HeWhoMustNotBeNamed, as written in the script's header

Draws

On the price chart

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
Number Of Barsint25numberOfBars
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

947 stars

The Heikin-Ashi Chart Identifier is an indicator that checks if the current chart uses Heikin-Ashi candles. It tracks matched candles where open equals the average of previous open and close, and verifies no gaps between bars. When conditions match, it display

Indicator v4 Candlestick patterns
Updated 12 days ago · GPL-3.0 GitHub repository of Heikin-Ashi Chart Identifier
575 stars

The indicator plots ICT displacement candles on the price chart and can switch to retracement scanning. Displacement requires a move larger than a set share of the 14-bar average high-low range, lasting at least a chosen number of bars, with optional close, pr

Indicator v6 SMC / ICT / price actionCandlestick patterns
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Displacement Candles Indicator

All Candlestick Patterns

by shunjizhan
292 stars

All Candlestick Patterns detects and highlights a wide range of bullish, bearish, and neutral candlestick patterns directly on the price chart. It features optional trend filtering using either a 50-period simple moving average or a combination of 50-period an

Indicator v4 Candlestick patternsTrend
Updated 3 years ago · None stated GitHub repository of All Candlestick Patterns
285 stars

Mean Reversion Study is an indicator that identifies trade setups combining exponential moving averages, RSI extremes, and engulfing candlestick patterns. It highlights bullish setups when a bullish engulfing candle forms below the EMA while RSI is oversold, a

Indicator v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Study

[RS]MTF Candle Sticks

by ricardosantos79
261 stars

This indicator overlays up to five higher-timeframe candlestick groups on the price chart. For each enabled timeframe it requests open, high, low, and close and can show up to five candles, offset by a spacing setting. The main inputs set the candle count, the

Indicator v4 Candlestick patternsSupport & resistance Repaints
Updated 4 years ago · None stated GitHub repository of [RS]MTF Candle Sticks
257 stars

This indicator detects a large set of classic candlestick patterns and plots colored labels on the price chart. Trend context uses a 50-period simple moving average, or the 50 and 200 averages stacked together, and can be switched off. Users filter bullish, be

Indicator v4 Candlestick patternsTrend
Updated 7 weeks ago · None stated GitHub repository of Snag - All Candlestick Patterns

More Candlestick patterns scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers