Repaints Hurst Spectral Analysis Oscillator For ThinkOrSwim

Repaints

Luckyspirit

New member
I found this cycle indicator on trading view
https://www.tradingview.com/script/iBrqYMSe-Hurst-Spectral-Analysis-Oscillator/
, Hurst's spectral analysis. This is what it looks like with every cycle turned on.
Screenshot-2023-03-19-at-3-38-17-AM.png


I turned off everything except the 20 day cycle (the real SPY cycle is between 20-25 days, but there was no option for a 25 day). and here's what it looks like.
Screenshot-2023-03-19-at-3-14-15-AM.png


It could be a possible strategy, similar to the TTM Squeeze. The closer the sine wave is to the 0 line, or the longer it consolidates near the 0 line, the bigger the impulse is. The problem is figuring out if it fires to the upside or the downside.
Screenshot-2023-03-19-at-3-11-37-AM.png


A possible solution to anticipate if it fires up or down, is by turning on longer dominant cycles. Such as the 40 week and the 6 month. There's even a 18 year line in there. But the longer dominant cycles behave more like moving averages, instead of up and down cyclical patterns.
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

I found this cycle indicator on trading view
https://www.tradingview.com/script/iBrqYMSe-Hurst-Spectral-Analysis-Oscillator/
, Hurst's spectral analysis. This is what it looks like with every cycle turned on.
Screenshot-2023-03-19-at-3-38-17-AM.png


I turned off everything except the 20 day cycle (the real SPY cycle is between 20-25 days, but there was no option for a 25 day). and here's what it looks like.
Screenshot-2023-03-19-at-3-14-15-AM.png


It could be a possible strategy, similar to the TTM Squeeze. The closer the sine wave is to the 0 line, or the longer it consolidates near the 0 line, the bigger the impulse is. The problem is figuring out if it fires to the upside or the downside.
Screenshot-2023-03-19-at-3-11-37-AM.png


A possible solution to anticipate if it fires up or down, is by turning on longer dominant cycles. Such as the 40 week and the 6 month. There's even a 18 year line in there. But the longer dominant cycles behave more like moving averages, instead of up and down cyclical patterns.

BTW, if anyone knows what chart or trading platform this is, I would like to know and much appreciated. This chart has an upper cycle bracket which is mind blowing to me TOS only has cycle brackets for bottom nesting.
Screenshot-2023-03-19-at-4-02-24-AM.png


Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BarefootJoey

// ██████████████████████████████████████████████████████████████████████
// █▄─▄─▀██▀▄─██▄─▄▄▀█▄─▄▄─█▄─▄▄─█─▄▄─█─▄▄─█─▄─▄─███▄─▄█─▄▄─█▄─▄▄─█▄─█─▄█
// ██─▄─▀██─▀─███─▄─▄██─▄█▀██─▄███─██─█─██─███─███─▄█─██─██─██─▄█▀██▄─▄██
// █▄▄▄▄██▄▄█▄▄█▄▄█▄▄█▄▄▄▄▄█▄▄▄███▄▄▄▄█▄▄▄▄██▄▄▄██▄▄▄███▄▄▄▄█▄▄▄▄▄██▄▄▄██

//@version=5
indicator('Hurst Spectral Analysis Oscillator', overlay=false, format=format.price, precision=3)

//-------------------------------Inputs-------------------------------//
source = input(hl2, 'Source', group="Bandpass Settings")
bandWidth = input.float(0.025, 'Bandwidth', minval=0.0, maxval=1.0, group="Bandpass Settings")
periodBandpassh = input.float(4.3, '5 Day      ', minval=2, inline="1", group="Cycle Settings")
periodBandpassf = input.float(8.5, '10 Day    ', minval=2, inline="2", group="Cycle Settings")
periodBandpass2 = input.float(17, '20 Day    ', minval=2, inline="3", group="Cycle Settings")
periodBandpass4 = input.float(34.1, '40 Day    ', minval=2, inline="4", group="Cycle Settings")
periodBandpass8 = input.float(68.2, '80 Day    ', minval=2, inline="5", group="Cycle Settings")
periodBandpass16 = input.float(136.4, '20 Week ', minval=2, inline="6", group="Cycle Settings")
periodBandpass32 = input.float(272.8, '40 Week ', minval=2, inline="7", group="Cycle Settings")
periodBandpass64 = input.float(545.6, '18 Month', minval=2, inline="8", group="Cycle Settings")
periodBandpass128 = input.float(1636.8, '54 Month', minval=2, inline="9", group="Cycle Settings")
periodBandpass256 = input.float(3273.6, '9 Year    ', minval=2, inline="10", group="Cycle Settings")
periodBandpass512 = input.float(6547.2, '18 Year  ', minval=2, inline="11", group="Cycle Settings")
// Color Selection
colh = input.color(color.purple, " ", inline="1", group="Cycle Settings")
colf = input.color(color.blue, " ", inline="2", group="Cycle Settings")
col2 = input.color(color.aqua, " ", inline="3", group="Cycle Settings")
col4 = input.color(color.green, " ", inline="4", group="Cycle Settings")
col8 = input.color(color.yellow, " ", inline="5", group="Cycle Settings")
col16 = input.color(color.orange, " ", inline="6", group="Cycle Settings")
col32 = input.color(color.red, " ", inline="7", group="Cycle Settings")
col64 = input.color(#856c44, " ", inline="8", group="Cycle Settings")
col128 = input.color(color.black, " ", inline="9", group="Cycle Settings")
col256 = input.color(color.gray, " ", inline="10", group="Cycle Settings")
col512 = input.color(color.white, " ", inline="11", group="Cycle Settings")
colcompu = input.color(color.new(#00ff0a, 70), "Composite Model Candle Colors", inline="12", group="Cycle Settings")
colcompd = input.color(color.new(#ff0000, 70), " ", inline="12", group="Cycle Settings")
// Composite Selection
comph = input.bool(true, "Composite", inline="1", group="Cycle Settings")
compf = input.bool(true, "Composite", inline="2", group="Cycle Settings")
comp2 = input.bool(true, "Composite", inline="3", group="Cycle Settings")
comp4 = input.bool(true, "Composite", inline="4", group="Cycle Settings")
comp8 = input.bool(true, "Composite", inline="5", group="Cycle Settings")
comp16 = input.bool(true, "Composite", inline="6", group="Cycle Settings")
comp32 = input.bool(true, "Composite", inline="7", group="Cycle Settings")
comp64 = input.bool(true, "Composite", inline="8", group="Cycle Settings")
comp128 = input.bool(true, "Composite", inline="9", group="Cycle Settings")
comp256 = input.bool(true, "Composite", inline="10", group="Cycle Settings")
comp512 = input.bool(true, "Composite", inline="11", group="Cycle Settings")
// Analysis Inputs
sig_in = input.string("None", "Bandpass for Analysis", options=["5 Day", "10 Day", "20 Day", "40 Day", "80 Day", "20 Week", "40 Week", "18 Month", "54 Month", "9 Year", "18 Year", "None"], group="Analysis Settings")
decimals = input.int(2, 'Price Decimals', minval=0, maxval=10, group="Analysis Settings")
position = input.string(position.bottom_right, "Analysis Position", [position.top_center, position.top_right, position.middle_right, position.bottom_right, position.bottom_center, position.bottom_left, position.middle_left, position.top_left], group="Analysis Settings")
size = input.string(size.small, "Text Size", [size.tiny, size.small, size.normal, size.large, size.huge], group="Analysis Settings")

//-------------------------------Functions & Calculations-------------------------------//
// @TMPascoe found & offered this bandpass by @HPotter found here https://www.tradingview.com/script/A1jhw5fG-Bandpass-Filter/
//      @BarefootJoey turned the code into a function and made it accept float Period
bpf(Series, float Period, Delta) =>
    float tmpbpf = na
    var beta = math.cos(3.14 * (360 / Period) / 180)
    var gamma = 1 / math.cos(3.14 * (720 * Delta / Period) / 180)
    var alpha = gamma - math.sqrt(gamma * gamma - 1)
    tmpbpf := 0.5 * (1 - alpha) * (Series - Series[2]) + beta * (1 + alpha) * nz(tmpbpf[1]) - alpha * nz(tmpbpf[2])
// Individual Bandpass Filters
BPFh = bpf(source, periodBandpassh, bandWidth)
BPFf = bpf(source, periodBandpassf, bandWidth)
BPF2 = bpf(source, periodBandpass2, bandWidth)
BPF4 = bpf(source, periodBandpass4, bandWidth)
BPF8 = bpf(source, periodBandpass8, bandWidth)
BPF16 = bpf(source, periodBandpass16, bandWidth)
BPF32 = bpf(source, periodBandpass32, bandWidth)
BPF64 = bpf(source, periodBandpass64, bandWidth)
BPF128 = bpf(source, periodBandpass128, bandWidth)
BPF256 = bpf(source, periodBandpass256, bandWidth)
BPF512 = bpf(source, periodBandpass512, bandWidth)
// Composite
compBPF = (comph?BPFh:0) + (compf?BPFf:0) + (comp2?BPF2:0) + (comp4?BPF4:0) + (comp8?BPF8:0) + (comp16?BPF16:0) + (comp32?BPF32:0) + (comp64?BPF64:0) + (comp128?BPF128:0) + (comp256?BPF256:0) + (comp512?BPF512:0)
col = ta.change(compBPF) > 0 ? colcompu : colcompd

// Cycle Analysis
// Truncate Decimals
truncate(number, pricedecimals) =>
    factor = math.pow(10, pricedecimals)
    int(number * factor) / factor
// Switch output/plot for analytics
sig_out = sig_in == "5 Day" ? BPFh : sig_in == "10 Day" ? BPFf : sig_in == "20 Day" ? BPF2 : sig_in == "40 Day" ? BPF4 : sig_in == "80 Day" ? BPF8 : sig_in == "20 Week" ? BPF16 : sig_in == "40 Week" ? BPF32 : sig_in == "18 Month" ? BPF64 : sig_in == "54 Month" ? BPF128 : sig_in == "9 Year" ? BPF256 : sig_in == "18 Year" ? BPF512 : na
period_out = sig_in == "5 Day" ? periodBandpassh : sig_in == "10 Day" ? periodBandpassf : sig_in == "20 Day" ? periodBandpass2 : sig_in == "40 Day" ? periodBandpass4 : sig_in == "80 Day" ? periodBandpass8 : sig_in == "20 Week" ? periodBandpass16 : sig_in == "40 Week" ? periodBandpass32 : sig_in == "18 Month" ? periodBandpass64 : sig_in == "54 Month" ? periodBandpass128 : sig_in == "9 Year" ? periodBandpass256 : sig_in == "18 Year" ? periodBandpass512 : 1 // :na
col_out = sig_in == "5 Day" ? colh : sig_in == "10 Day" ? colf : sig_in == "20 Day" ? col2 : sig_in == "40 Day" ? col4 : sig_in == "80 Day" ? col8 : sig_in == "20 Week" ? col16 : sig_in == "40 Week" ? col32 : sig_in == "18 Month" ? col64 : sig_in == "54 Month" ? col128 : sig_in == "9 Year" ? col256 : sig_in == "18 Year" ? col512 : color.gray
// Highs/Lows
hi = sig_out[2]<sig_out[1] and sig_out[1]>sig_out
lo = sig_out[2]>sig_out[1] and sig_out[1]<sig_out
// Define Crosses
midcross = ta.cross(sig_out, 0)
midcrossbars = ta.barssince(midcross)
midcrossbars2 = ta.barssince(midcross)[1]
last_wavelength = ta.barssince(midcross) - ta.barssince(midcross)
// Bars Since Last Amp Hi & Lo
xhi = ta.barssince(hi)
xlo = ta.barssince(lo)
// Wavelength
wavelength = math.round(math.abs(xhi-xlo)*2)
// Last Amp Hi & Lo
bpfphi = ta.highest(sig_out,math.round(period_out))
bpfamphi = ta.valuewhen(bpfphi, sig_out, 0)
bpfplo = ta.lowest(sig_out,math.round(period_out))
bpfamplo = ta.valuewhen(bpfplo, sig_out, 0)
tot_amp = bpfphi - bpfplo
// Estimates/Forecasts
next_peak = -math.abs(xhi-wavelength)
next_trough = -math.abs(xlo-wavelength)
next_node = math.abs(xhi-xlo)-midcrossbars
// Highlight background of next peak/node/trough
next_peak_col = color.new(color.red,hi?75:100)
next_node_col = color.new(color.gray, midcross?75:100)
next_trough_col = color.new(color.green, lo?75:100)
// Sentiment
amp_sent = bpfphi>math.abs(bpfplo)?"🟢":bpfphi<math.abs(bpfplo)?"🔴":"⚪"
bbwavelen = wavelength>period_out?"🟢":wavelength<period_out?"🔴":"⚪"
bbpt = -next_peak<-next_trough?"Bullish🟢":-next_peak>-next_trough?"Bearish🔴":"Neutral⚪"
// Analytics Tooltip 📏🧮⏳🎰🤖🎭🔮📈📉🔁🌊🔴🟢⚪
labeltt= "🔄 Cycle: " + str.tostring(sig_in) + "/" + str.tostring(period_out) + " bars" +
 "\n📏 Period (⊺): ~" + str.tostring(math.abs(xhi-xlo)) + " bars" +
 "\n🌊 Wavelength (λ): ~" + str.tostring(wavelength) + " bars " + bbwavelen +
 "\n⚖ Delta (∆) Amplitude (ª): " + str.tostring(truncate(tot_amp, decimals)) + " " + amp_sent +
 "\n📈 Peak (ª): " + str.tostring(truncate(bpfphi, decimals)) + ", " + str.tostring(xhi) + " bars ago" +
 "\n🔀 Node: " + str.tostring(midcrossbars) + " bars ago" +
 "\n📉 Trough (ª): " + str.tostring(truncate(bpfplo, decimals)) + ", " + str.tostring(xlo) + " bars ago" +
 "\n\n🔮 Estimates: " + bbpt +
 "\n📈 Next Peak: " + str.tostring(-next_peak) + "ish bars " +
 "\n🔀 Next Node: " + str.tostring(next_node) + "ish bars" +
 "\n📉 Next Trough: " + str.tostring(-next_trough) + "ish bars "

// ------------------------------- Plots, Displays, Outputs -------------------------------//
plot(0, "Midline", color.new(color.gray,30), style=plot.style_histogram)
plot(BPFh, '5 Day', color=color.new(colh, 0), linewidth=sig_in == "5 Day" ? 3 : 1)
plot(BPFf, '10 Day', color=color.new(colf, 0), linewidth=sig_in == "10 Day" ? 3 : 1)
plot(BPF2, '20 Day', color=color.new(col2, 0), linewidth=sig_in == "20 Day" ? 3 : 1)
plot(BPF4, '40 Day', color=color.new(col4, 0), linewidth=sig_in == "40 Day" ? 3 : 1)
plot(BPF8, '80 Day', color=color.new(col8, 0), linewidth=sig_in == "80 Day" ? 3 : 1)
plot(BPF16, '20 Week', color=color.new(col16, 0), linewidth=sig_in == "20 Week" ? 3 : 1)
plot(BPF32, '40 Week', color=color.new(col32, 0), linewidth=sig_in == "40 Week" ? 3 : 1)
plot(BPF64, '18 Month', color=color.new(col64, 0), linewidth=sig_in == "18 Month" ? 3 : 1)
plot(BPF128, '54 Month', color=color.new(col128, 0), linewidth=sig_in == "54 Month" ? 3 : 1, display=display.none)
plot(BPF256, '9 Year', color=color.new(col256, 0), linewidth=sig_in == "9 Year" ? 3 : 1, display=display.none)
plot(BPF512, '18 Year', color=color.new(col512, 0), linewidth=sig_in == "18 Year" ? 3 : 1, display=display.none)

plotcandle(compBPF[1], ta.lowest(compBPF,1), math.min(compBPF,compBPF[1]), compBPF, color=col, wickcolor=color.new(col,100), bordercolor=col, title='Composite Candles', display=display.none)

bgcolor(color=next_peak_col, title="Peak Estimate", offset=wavelength)
bgcolor(color=next_node_col, title="Node Estimate", offset=wavelength)
bgcolor(color=next_trough_col, title="Trough Estimate", offset=wavelength)

plotshape(hi, "Actual Peak", shape.triangledown, location.top, color.rgb(255, 0, 0, 33), size=size.tiny)
plotshape(lo, "Actual Trough", shape.triangleup, location.bottom, color.rgb(0, 255, 8, 33), size=size.tiny)

var table Ticker = na
table.delete(Ticker)
Ticker := table.new(position, 1, 1)
if barstate.islast
    table.cell(Ticker, 0, 0,
      text = "🔄 Cycle Analysis",
      text_size = size,
      text_color = color.new(col_out,0),
      tooltip = sig_in!="None"?labeltt:"No Bandpass selected. Double click to open & change Settings.")

// EoS made w/ ❤ by @BarefootJoey ✌💗📈
check this. May not be a typical convertsion.

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © BarefootJoey
#indicator('Hurst Spectral Analysis Oscillator', overlay=false, format=format.price, precision=3)
# Converted by Sam4Cok@Samer800    - 04/2023 - not typical conversion
declare lower;
#//-------------------------------Inputs-------------------------------//
input source = hl2;#, 'Source', group="Bandpass Settings")
input bandWidth = 0.025;#, 'Bandwidth', minval=0.0, maxval=1.0, group="Bandpass Settings")
input CompositeCandles = no;
input sig_in = {default "None", "5 Day", "10 Day", "20 Day", "40 Day", "80 Day", "20 Week", "40 Week", "18 Month"};
input periodBandpassh = 4.3;#, '5 Day      ', minval=2, inline="1", group="Cycle Settings")
input periodBandpassf = 8.5;#, '10 Day    ', minval=2, inline="2", group="Cycle Settings")
input periodBandpass2 = 17.0;#, '20 Day    ', minval=2, inline="3", group="Cycle Settings")
input periodBandpass4 = 34.1;#, '40 Day    ', minval=2, inline="4", group="Cycle Settings")
input periodBandpass8 = 68.2;#, '80 Day    ', minval=2, inline="5", group="Cycle Settings")
input periodBandpass16 = 136.4;#, '20 Week ', minval=2, inline="6", group="Cycle Settings")
input periodBandpass32 = 272.8;#, '40 Week ', minval=2, inline="7", group="Cycle Settings")
input periodBandpass64 = 545.6;#, '18 Month', minval=2, inline="8", group="Cycle Settings")
#// Composite Selection
input comph = yes;#(true, "Composite", inline="1", group="Cycle Settings")
input compf = yes;#(true, "Composite", inline="2", group="Cycle Settings")
input comp2 = yes;#(true, "Composite", inline="3", group="Cycle Settings")
input comp4 = yes;#(true, "Composite", inline="4", group="Cycle Settings")
input comp8 = yes;#(true, "Composite", inline="5", group="Cycle Settings")
input comp16 = yes;#(true, "Composite", inline="6", group="Cycle Settings")
input comp32 = yes;#(true, "Composite", inline="7", group="Cycle Settings")
input comp64 = yes;#(true, "Composite", inline="8", group="Cycle Settings")
input decimals = 2;#, 'Price Decimals', minval=0, maxval=10, group="Analysis Settings")

def na = Double.NaN;
def last  = isNaN(close);
def candle = CompositeCandles;
def day5  = sig_in == sig_in."5 Day";
def day10 = sig_in == sig_in."10 Day";
def day20 = sig_in == sig_in."20 Day";
def day40 = sig_in == sig_in."40 Day";
def day80 = sig_in == sig_in."80 Day";
def week20 = sig_in == sig_in."20 Week";
def week40 = sig_in == sig_in."40 Week";
def month18 = sig_in == sig_in."18 Month";

#// Color Selection
DefineGlobalColor("colh"     , Color.PLUM);#CreateColor(156,39,176));
DefineGlobalColor("colf"     , Color.VIOLET);#CreateColor(33,150,243));
DefineGlobalColor("col2"     , Color.CYAN);#CreateColor(0,188,212));
DefineGlobalColor("col4"     , CreateColor(76,175,80));
DefineGlobalColor("col8"     , CreateColor(255,235,59));
DefineGlobalColor("col16"    , CreateColor(255,152,0));
DefineGlobalColor("col32"    , CreateColor(255,82,82));
DefineGlobalColor("col64"    , CreateColor(133,108,68));
DefineGlobalColor("col128"   , CreateColor(54,58,69));
DefineGlobalColor("col256"   , CreateColor(120,123,134));
DefineGlobalColor("col512"   , CreateColor(255,255,255));
DefineGlobalColor("colcompu" , Color.DARK_GREEN);
DefineGlobalColor("colcompd" , Color.DARK_RED);

#//--------Functions & Calculations-------------------------------//
script nz {
    input data  = close;
    def ret_val = if IsNaN(data) then 0 else data;
    plot return = ret_val;
}
#barssince(Condition) =>
script barssince {
    input Condition = 0;
    def barssince = if Condition then 1 else barssince[1] + 1;
    plot return = barssince;
}
#// @TMPascoe found & offered this bandpass by @HPotter found here https://www.tradingview.com/script/A1jhw5fG-Bandpass-Filter/
#//      @BarefootJoey turned the code into a function and made it accept float Period
#bpf(Series, float Period, Delta) =>
script bpf {
    input Series = hl2;
    input Period = 10;
    input Delta = 0.025;
    def Pi = Double.Pi;
    def tmpbpf;
    def beta = Cos(Pi * (360 / Period) / 180);
    def gamma = 1 / Cos(Pi * (720 * Delta / Period) / 180);
    def alpha = gamma - Sqrt(gamma * gamma - 1);
    tmpbpf = CompoundValue(1,0.5 * (1-alpha) * (Series-Series[2]) + beta * (1+alpha) * nz(tmpbpf[1]) - alpha * nz(tmpbpf[2]),
                             0.5 * (1-alpha) * (Series-Series[2]));
    plot out = tmpbpf;
}
#// Individual Bandpass Filters
def BPFh = bpf(source, periodBandpassh, bandWidth);
def BPFf = bpf(source, periodBandpassf, bandWidth);
def BPF2 = bpf(source, periodBandpass2, bandWidth);
def BPF4 = bpf(source, periodBandpass4, bandWidth);
def BPF8 = bpf(source, periodBandpass8, bandWidth);
def BPF16 = bpf(source, periodBandpass16, bandWidth);
def BPF32 = bpf(source, periodBandpass32, bandWidth);
def BPF64 = bpf(source, periodBandpass64, bandWidth);

#// Composite
def compBPF = If(comph, BPFh, 0) + If(compf, BPFf, 0) + If(comp2, BPF2, 0) + If(comp4, BPF4, 0) + If(comp8, BPF8, 0) + If(comp16, BPF16, 0) + If(comp32, BPF32, 0) + If(comp64, BPF64, 0);# + If(comp128, BPF128, 0) + If(comp256, BPF256, 0) + If(comp512, BPF512, 0);
def col = (compBPF - compBPF[1]) > 0;

#// Cycle Analysis
#// Truncate Decimals
#truncate(number, pricedecimals) =>
script truncate {
    input number = 0;
    input pricedecimals = 2;
    def factor = Power(10, pricedecimals);
    def truncate = Floor(number * factor) / factor;
    plot out = truncate;
}
#// Switch output/plot for analytics
def sig_out = if day5 then BPFh else if day10 then BPFf else if day20 then BPF2 else if day40 then BPF4 else
              if day80 then BPF8 else if week20 then BPF16 else if week40 then BPF32 else if month18 then BPF64 else na;

def period_out = if day5 then periodBandpassh else if day10 then periodBandpassf else if day20 then periodBandpass2 else
                 if day40 then periodBandpass4 else if day80 then periodBandpass8 else if week20 then periodBandpass16 else
                 if week40 then periodBandpass32 else if month18 then periodBandpass64 else 1;
#// Highs/Lows
def hi = sig_out[2] < sig_out[1] and sig_out[1] > sig_out;
def lo = sig_out[2] > sig_out[1] and sig_out[1] < sig_out;

#// Define Crosses
def midcross = (sig_out>0 and sig_out[1]<=0) or (sig_out<0 and sig_out[1]>=0);#Crosses(sig_out, 0, CrossingDirection.ANY);
def midcrossbars = barssince(midcross);

#// Bars Since Last Amp Hi & Lo
def xhi = barssince(hi);
def xlo = barssince(lo);
#// Wavelength  
def wavelength = Round(AbsValue(xhi - xlo) * 2, 0);
#// Last Amp Hi & Lo
def bpfphi = Highest(sig_out, Round(period_out, 0));
def bpfamphi = if bpfphi then sig_out else bpfamphi[1];
def bpfplo = Lowest(sig_out, Round(period_out, 0));
def bpfamplo = if bpfplo then sig_out else bpfamplo[1];
def tot_amp = bpfphi - bpfplo;
#// Estimates/Forecasts
def next_peak = -AbsValue(xhi - wavelength);
def next_trough = -AbsValue(xlo - wavelength);
def next_node = AbsValue(xhi - xlo) - midcrossbars;
#// Highlight background of next peak/node/trough
#// ---- Plots, Displays, Outputs -------------------------------//
plot Day_5 = if Day5 or candle then na else BPFh;    # '5 Day'
plot Day5_ = if Day5 and !candle then BPFh else na;    # '5 Day'
plot Day_10 = if Day10 or candle then na else BPFf;  # '10 Day'
plot Day10_ = if Day10 and !candle then BPFf else na;  # '10 Day'
plot Day_20 = if Day20 or candle then na else BPF2;  # '20 Day'
plot Day20_ = if Day20 and !candle then BPF2 else na;  # '20 Day'
plot Day_40 = if Day40 or candle then na else BPF4;  # '40 Day'
plot Day40_ = if Day40 and !candle then BPF4 else na;  # '40 Day'
plot Day_80 = if Day80 or candle then na else BPF8;  # '80 Day'
plot Day80_ = if Day80 and !candle then BPF8 else na;  # '80 Day'
plot Week_20 = if Week20 or candle then na else BPF16;     # '20 Week'
plot Week20_ = if Week20 and !candle then BPF16 else na;     # '20 Week'
plot Week_40 = if Week40 or candle then na else BPF32;     # '40 Week'
plot Week40_ = if Week40 and !candle then BPF32 else na;     # '40 Week'
plot Month_18 = if Month18 or candle then na else BPF64;   # '18 Month'
plot Month18_ = if Month18 and !candle then BPF64 else na;   # '18 Month'

plot Midline = if last then na else 0;#, "Midline", color.new(color.gray,30), style=plot.style_histogram)
Midline.SetDefaultColor(Color.DARK_GRAY);
Midline.SetStyle(Curve.SHORT_DASH);
Day_5.SetDefaultColor(GlobalColor("colh"));
Day_10.SetDefaultColor(GlobalColor("colf"));
Day_20.SetDefaultColor(GlobalColor("col2"));
Day_40.SetDefaultColor(GlobalColor("col4"));
Day_80.SetDefaultColor(GlobalColor("col8"));
Week_20.SetDefaultColor(GlobalColor("col16"));
Week_40.SetDefaultColor(GlobalColor("col32"));
Month_18.SetDefaultColor(GlobalColor("col64"));
Day5_.SetDefaultColor(GlobalColor("colh"));
Day10_.SetDefaultColor(GlobalColor("colf"));
Day20_.SetDefaultColor(GlobalColor("col2"));
Day40_.SetDefaultColor(GlobalColor("col4"));
Day80_.SetDefaultColor(GlobalColor("col8"));
Week20_.SetDefaultColor(GlobalColor("col16"));
Week40_.SetDefaultColor(GlobalColor("col32"));
Month18_.SetDefaultColor(GlobalColor("col64"));
Day5_.SetLineWeight(3);
Day10_.SetLineWeight(3);
Day20_.SetLineWeight(3);
Day40_.SetLineWeight(3);
Day80_.SetLineWeight(3);
Week20_.SetLineWeight(3);
Week40_.SetLineWeight(3);
Month18_.SetLineWeight(3);

# Plot the new Chart

AddChart(high = if col and candle then lowest(compBPF,1) else na, low = min(compBPF,compBPF[1]) , open = compBPF,  close = compBPF[1],
         type = ChartType.CANDLE, growcolor =  CreateColor(38,166,154));
AddChart(high = if col or !candle then na else lowest(compBPF,1), low = min(compBPF,compBPF[1]) , open = compBPF[1],  close = compBPF,
         type = ChartType.CANDLE, growcolor =  CreateColor(239,83,80));

def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def hii = !Candle and hi;
def loo = !Candle and lo;
def midc = !Candle and midcross;

AddChart(high = if hii then pos else na, low = neg , open = pos,  close = neg,
         type = ChartType.CANDLE, growcolor =  CreateColor(39,0,0));
AddChart(high = if midc then pos else na, low = neg , open = pos,  close = neg,
         type = ChartType.CANDLE, growcolor =  CreateColor(30,30,30));
AddChart(high = if loo then pos else na, low = neg , open = pos,  close = neg,
         type = ChartType.CANDLE, growcolor =  CreateColor(0,39,0));

plot ActualPeak = if !Candle and hi then 0.4 else na;#, "Actual Peak"
plot ActualTrough = if !Candle and lo then -0.4 else na;#, "Actual Trough"
ActualPeak.SetPaintingStrategy(PaintingStrategy.SQUARES);
ActualTrough.SetPaintingStrategy(PaintingStrategy.SQUARES);
ActualPeak.SetDefaultColor(Color.RED);
ActualTrough.SetDefaultColor(Color.GREEN);


#--- END of CODE
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
574 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top