Indicator · Pine Script v5 · Own pane

Tesla Coil

by CounterPly· code credited to veryfid

Tesla Coil is a market cycle oscillator based on digital signal processing concepts from John Ehlers, including Instantaneous Frequency Measurement and In-Phase and Quadrature principles.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code158
Settings7inputs
LicenceMPL-2.0
Last update4 years ago10 Feb 2022

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

158 lines of Pine Script v5 from teslacoil.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

teslacoil.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © veryfid
// contribution by @KryptoBeau 

//@version=5

indicator(title='Tesla Coil', overlay=false, timeframe='')
src = input(title='Source', defval=close)
mirror = true

//////////
//The Cosine IFM
//Copyright DasanC 2019
range_1 = input(title='Scanning Range', defval=100)
len2 = input(40)
PI = 3.14159265359
s2 = 0.0
s3 = 0.0
delta1 = 0.0
inst1 = 0.0
len1 = 0.0
v1 = 0.0
v2 = 0.0
v4 = 0.0

v1 := src - src[7]
s2 := 0.2 * (v1[1] + v1) * (v1[1] + v1) + 0.8 * nz(s2[1])
s3 := 0.2 * (v1[1] - v1) * (v1[1] - v1) + 0.8 * nz(s3[1])
if s2 != 0
    v2 := math.sqrt(s3 / s2)
    v2
if s3 != 0
    delta1 := 2 * math.atan(v2)
    delta1
for i = 0 to range_1 by 1
    v4 += delta1[i]
    if v4 > 2 * PI and inst1 == 0.0
        inst1 := i - 1
        inst1
if inst1 == 0.0
    inst1 := inst1[1]
    inst1
len1 := 0.25 * inst1 + 0.75 * nz(len1[1])



//Robust Cycle Measurement Function (I-Q Principles)
//Args: src is the series you want to find the period of
// I cant remember where I got this code from...
//##############################################################################
getRCM(src) =>
    Price = src
    alpha = 0.1
    //Optional Parameters if the user wishes to change
    //alpha := input(title="Alpha", type=float, defval=0.07)
    Cycle = 0.0
    Q1 = 0.0
    I1 = 0.0
    I2 = 0.0
    Q2 = 0.0
    DeltaPhase = 0.0
    MedianDelta = 0.0
    DC = 0.0
    InstPeriod = 0.0
    Period = 0.0


    Smooth = (Price + 2 * Price[1] + 2 * Price[2] + Price[3]) / 6
    Cycle := (1 - 0.5 * alpha) * (1 - 0.5 * alpha) * (Smooth - 2 * Smooth[1] + Smooth[2]) + 2 * (1 - alpha) * nz(Cycle[1]) - (1 - alpha) * (1 - alpha) * nz(Cycle[2])
    if bar_index < 7
        Cycle := (Price - 2 * Price[1] + Price[2]) / 4
        Cycle
    Q1 := (0.0962 * Cycle + 0.5769 * Cycle[2] - 0.5769 * Cycle[4] - 0.0962 * Cycle[6]) * (0.5 + 0.08 * InstPeriod[1])
    I1 := Cycle[3]
    if Q1 != 0 and Q1[1] != 0
        DeltaPhase := (I1 / Q1 - I1[1] / Q1[1]) / (1 + I1 * I1[1] / (Q1 * Q1[1]))
        DeltaPhase
    if DeltaPhase < 0.1
        DeltaPhase := 0.1
        DeltaPhase
    if DeltaPhase > 1.1
        DeltaPhase := 1.1
        DeltaPhase
    MedianDelta := ta.percentile_nearest_rank(DeltaPhase, 5, 50)
    if MedianDelta == 0
        DC := 15
        DC
    else
        DC := 6.28318 / MedianDelta + 0.5
        DC
    InstPeriod := 0.33 * DC + 0.67 * nz(InstPeriod[1])
    Period := 0.15 * InstPeriod + 0.85 * nz(Period[1])
    Period := math.round(Period)
    Period
//##############################################################################

rcm = getRCM(src)


//#############################################################################
//The In-phase & quadrature IFM
//Copyright DasanC 2019
//#############################################################################

imult = 0.635
qmult = 0.338
inphase = 0.0
quadrature = 0.0
re = 0.0
im = 0.0
delta = 0.0
inst = 0.0
len = 0.0
V = 0.0

P = src - src[7]

inphase := 1.25 * (P[4] - imult * P[2]) + imult * nz(inphase[3])
quadrature := P[2] - qmult * P + qmult * nz(quadrature[2])
re := 0.2 * (inphase * inphase[1] + quadrature * quadrature[1]) + 0.8 * nz(re[1])
im := 0.2 * (inphase * quadrature[1] - inphase[1] * quadrature) + 0.8 * nz(im[1])
if re != 0.0
    delta := math.atan(im / re)
    delta

for i = 0 to 100 by 1
    V += delta[i]
    if V > 2 * PI and inst == 0.0
        inst := i
        inst

if inst == 0.0
    inst := nz(inst[1])
    inst

len := 0.25 * inst + 0.75 * nz(len[1])

average = math.avg(len1 * 3, rcm, len)
tfig = input(50)
tfig2 = len1 * 3 > len1 * 3 * -1 + len2 ? 50 : 0
tfig3 = average > average * -1 + len2 ? 50 : 0
tfig4 = len <= len * -1 + len2 ? 90 : 50
cola= input.color(color.blue)
colb= input.color(#bbd9fb)
colc= input.color(#9575cd)
plot(len, 'len', color=color.new(cola, tfig4))
//plot(len1 * 3 ,"3xlen1", color=#bbd9fb)//original line
len1x3 = len1 * 3  //KB edit
plot(len1x3, '3xlen1', color=color.new(colb, tfig2))  //KB edit

//Mirror
plot(mirror ? len * -1 + len2 : na, 'len mirror', color=color.new(cola, tfig4))
plot(mirror ? len1 * 3 * -1 + len2 : na, 'len1 mirror', color=color.new(colb, tfig2))
plot(mirror ? average * -1 + len2 : na, 'average mirror', color=color.new(colc, tfig3))
plot(average, 'average', color=color.new(colc, tfig3))

alertcond = ta.cross(len1 * 3, 20) or ta.cross(average, average * -1 + len2) or ta.cross(len, len * -1 + len2 )
alertcondition(alertcond, title='Tesla Coil', message='Tesla Coil Crossover')

Overview

Tesla Coil treats price movements as wave frequencies to track cycle periods dynamically over a user-defined scanning range. Plotted in a separate pane, the indicator helps traders visualize dominant cyclic patterns and detect potential market turning points or momentum exhaustion.

Details

Published by

CounterPly on GitHub

Code credit

veryfid, as written in the script's header

Draws

Separate pane below the 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
Sourcesourceclosesrc
Scanning Rangeint100range_1
len2int40len2
tfigint50tfig
colacolorcolor.bluecola
colbcolor#bbd9fbcolb
colccolor#9575cdcolc
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

Asymmetrical RSI

by everget
947 stars

Asymmetrical RSI is an indicator that computes a custom relative strength index from the rate of change of a user-selected source. It plots the resulting ARSI line in a separate pane with color coding that turns green above the overbought level and red below t

Indicator v4 Oscillators & momentum
Updated 12 days ago · GPL-3.0 GitHub repository of Asymmetrical RSI

This indicator calculates momentum setups based on the Relative Strength Index (RSI) and plots in a separate pane. It offers multiple scanning modes such as Continuous Break, Continuous Retracement, Flip Break, Flip Retracement, and both regular and hidden div

Indicator v6 Oscillators & momentumDivergence Repaints
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - RSI Directional Momentum Indicator

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop
261 stars

This indicator demonstrates an experimental graph-style scatter visualization within a separate pane using Pine Script arrays. It tracks two features across recent bars: the single-bar price change and a scaled 14-period Relative Strength Index. Values are loa

Indicator v4 Oscillators & momentum
Updated 4 years ago · None stated GitHub repository of Example: Graph Style - 4th Dimension RSI
228 stars

This indicator detects a Bollinger Band squeeze when the bands sit inside Keltner Channels, marking low volatility. It plots red dots during a squeeze and green dots when the bands are outside, in a separate pane. An optional histogram shows momentum as the cl

Indicator v6 Volatility & bandsOscillators & momentum
Updated 3 months ago · None stated GitHub repository of Bollinger Band Squeeze Detector

More Oscillators & momentum 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