Indicator · Pine Script v5 · On the chart

Price and Date Forecast V4

by mikeyhu70· code credited to congacindy

This indicator combines three dominant cycle lengths, pivot highs and lows, and candlestick pattern matching to project future turning prices and dates.

View on GitHub

Repaints

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code551
Settings32inputs
LicenceNone statedfile: MPL-2.0
Last update6 months ago15 Apr 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

551 lines of Pine Script v5 from Forecast/Price and Date Forecast (2024 V4).ps, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Price and Date Forecast (2024 V4).ps
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © congacindy

//@version=5
indicator('Price and Date Forecast (2024 V4)', overlay=true,max_bars_back=5000)


// Input parameters
length1 = input.int(68, title='Dominant Cycle Length #1', minval=1)
length2 = input.int(34, title='Dominant Cycle Length #2', minval=1)
length3 = input.int(17, title='Dominant Cycle Length #3', minval=1)
length_sf = input.bool(true, title="Shift cycle its length")
length_cycle_sf = input.float(1.0, title='# of cycle to shift', minval=0)
leftBars = input.int(12, "Left Bars to get Pivot High/Low", minval=1)
rightBars = input.int(12, "Right Bars to get Pivot High/Low", minval=1)
kp = input(5, title="Candlestick matching Red/Green pattern length (kp)")
kp_iteration=input.int(1,title="Max number of (kp) iterations (have to be less than kp)")
kp_trend=input.bool(true,title="Include Up/Down candlestick pattern (kp_trend)")
kp_auto=input.bool(true,title="Auto match up/down pattern if there is no match (will nullify previous setting i.e kp_trend)")
td = input.bool(false, title="TD demark flip setup? (if not contineous bar patten in kp length)")
td_trend = input.bool(false, title="TD demark trend flip setup? (all first bars vs last bar logic)")
lookback = input.int(4, "TD Demark Lookback Flip Bars", minval=4)
y = input.int(5000, title='Lookback Bars', maxval=5000)
forecast_periods = input.int(10, title='Number of Periods to Forecast', minval=1)
_debug = input.bool(false, title="Show debug information?")

price = input.source(hl2)

bb_length = input.int(20, title='Bollinger Bands Length', minval=1)
bb_stddev = input.float(2.0, title='Bollinger Bands Standard Deviation', minval=0.1, step=0.1)
kc_length = input.int(20, title='Keltner Channel Length', minval=1)
kc_mult = input.float(1.0, title='Keltner Channel Multiplier', minval=0.1, step=0.1)
volatility_length = input.int(20, title="Volatility Length") // Adjust the length as needed


// Calculate the dominant cycle using time series analysis
//price = close
//cycle = ta.sma(price, cycle_length)

txt_col_price = input.color(color.rgb(208, 227, 62), 'Text/Frame Color', group='Dashboard')
txt_col_price_adj = input.color(color.rgb(231, 37, 237), 'Text/Frame Color', group='Dashboard')
txt_col_date = input.color(color.rgb(48, 228, 241), 'Text/Frame Color', group='Dashboard')
txt_col_pattern = input.color(color.rgb(238, 232, 166), 'Text/Frame Color', group='Dashboard')
txt_col = input.color(color.rgb(182, 186, 200), 'Text/Frame Color', group='Dashboard')
dash_loc = input.string('Mid Right', 'Dashboard Location', options=['Top Right', 'Bottom Right', 'Top Left', 'Mid Left', 'Mid Right'], group='Dashboard')
text_size = input.string('Tiny', 'Dashboard Size', options=['Tiny', 'Small', 'Normal', 'Large'], group='Dashboard')
debugtext_size = input.string('Tiny', 'Debug Dashboard Size', options=['Tiny', 'Small', 'Normal', 'Large'], group='Dashboard')
debugdash_loc = input.string('Bottom Center', 'Debug Dashboard Location', options=['Top Left', 'Top Center', 'Top Right', 'Mid Left', 'Mid Center', ' Mid Right', 'Bottom Left', 'Bottom Center', 'Bottom Right'], group='Dashboard')

// ****************************************************

// Goertzel algorithm to detect the dominant cycle
goertzel(price, length) =>
    k = 0.0
    w = 2 * math.pi / length
    cosine = math.cos(w)
    sine = math.sin(w)
    coeff = 2 * cosine
    q0 = 0.0
    q1 = 0.0
    q2 = 0.0
    for i = 0 to length - 1
        q0 := coeff * q1 - q2 + price[i]
        q2 := q1
        q1 := q0
    real = (q1 - q2 * cosine)
    imag = (q2 * sine)
    magnitude = math.sqrt(real * real + imag * imag)
    [real, imag, magnitude]

//goertzel(price, length) =>
//    k = 0.0
//    w = 2 * math.pi / length
//    cosine = math.cos(w)
//    sine = math.sin(w)
//    coeff = 2 * cosine
//    q0 = 0.0
//    q1 = 0.0
//    q2 = 0.0
//    for i = 0 to length - 1
//        q0 := coeff * q1 - q2 + price[i]
//        q2 := q1
//        q1 := q0
//    real = (q1 - q2 * cosine)
//    imag = (q2 * sine)
//    magnitude = math.sqrt(real * real + imag * imag)
//    
//    // Calculate the phase adjustment based on the current price position
//    price_position = ta.barssince(price == ta.lowest(price, length)) / length
//    phase_adjustment = 2 * math.pi * price_position
//    
//    // Adjust the phase by adding the phase adjustment
//    phase = math.atan(imag / real) + phase_adjustment
//    
//    [real, imag, magnitude, phase]


// Calculate the dominant cycle using Goertzel algorithm
//[real, imag, cycle] = goertzel(price, cycle_length)

// ****************************************************

// Find Matching Pattern based on k last bar 

get_bar_direction(i) =>
    ret=""
    if (close[i] >  close[i + 1])
        ret := 'U'
    else
        ret := 'D'
    ret

get_bar_color(i) =>
    ret = ""
    if (close[i] - open[i] > 0)
        ret := 'G'
    else
        ret := 'R'
    ret

// *********************** POPULATE ARRAY*****************************

last_j_bars = array.new_string(kp)
last_j_dates = array.new_string(kp)
last_jud_bars = array.new_string(kp)
last_jud_dates = array.new_string(kp)

for i = 0 to kp - 1
    array.set(last_j_bars, i, get_bar_color(i))
    array.set(last_j_dates, i, str.format("{0,date,yyyy-MM-dd}", time[i]))
    array.set(last_jud_bars, i, get_bar_direction(i))
    array.set(last_jud_dates, i, str.format("{0,date,yyyy-MM-dd}", time[i]))


// ********************** TD Count ******************************

// Function to check for Bullish TD Price Flip


bullishFlip(i,match) =>
    bool isBullish = true
    if match
        //isBullish := (open [i+2] > close[i+2])  and (open [i+3] > close[i+3]) and (open [i+4] > close[i+4]) and (open [i+5] > close[i+5]) and close[i+2] > close[i+3] and close[i+3] > close[i+4] and close[i+4] > close[i+5] and close[i] > close[i+1+lookback] and close[i+1] < close[i+lookback]
        //isBullish := close[i+2] > close[i+3] and close[i+3] > close[i+4] and close[i+4] > close[i+5] and close[i] > close[i+1+lookback] and close[i+1] < close[i+lookback]
        isBullish := (high [i+5] > low[i+2]) and close[i+2] > close[i+3] and close[i+3] > close[i+4] and close[i+4] > close[i+5] and close[i] > close[i+1+lookback] and close[i+1] < close[i+lookback]
    else
        isBullish := close[i] > close[i+1+lookback] and close[i+1] < close[i+lookback]

    [isBullish,i]

// Function to check for Bearish TD Price Flip (AI Generated ??????)

bearishFlip(i,match) =>
    bool isBearish = true
    if match
        //isBearish :=  (open [i+2] < close[i+2])  and (open [i+3] < close[i+3]) and (open [i+4] < close[i+4]) and (open [i+5] < close[i+5]) and close[i+2] < close[i+3] and close[i+3] < close[i+4] and close[i+4] < close[i+5] and close[i] < close[i+lookback] and close[i+1] > close[i+lookback+1]
        //isBearish :=  close[i+2] < close[i+3] and close[i+3] < close[i+4] and close[i+4] < close[i+5] and close[i] < close[i+lookback] and close[i+1] > close[i+lookback+1]
        isBearish :=  (high [i+5] < low[i+2])  and close[i+2] < close[i+3] and close[i+3] < close[i+4] and close[i+4] < close[i+5] and close[i] < close[i+lookback] and close[i+1] > close[i+lookback+1]
    else
        isBearish := close[i] < close[i+lookback] and close[i+1] > close[i+lookback+1]
    [isBearish,i]

tdPriceFlip(length = 4, source = close) =>
    flip = array.new_bool(length)
    for i = 0 to length - 1
        if i >= length - 1
            array.push(flip, source[i] > source[i - length])
        else
            array.push(flip, na)
    flip

// Usage:
// Bearish TD Price Flip
//bearishFlip = tdPriceFlip()[0] and not tdPriceFlip()[1]

// Bullish TD Price Flip
//bullishFlip = not tdPriceFlip()[0] and tdPriceFlip()[1]

// *********************** FIND PATTERN *****************************

match_found = false
match_dates = array.new_string(forecast_periods)
match_prices = array.new_float(forecast_periods)
var match_bar_index = 0
_found1 = false
_found2 = false
var _weak_setup = ""
var _loop_index = 0

if barstate.islast
    if not td
        for t = 0 to kp_iteration
            if (match_bar_index == 0)
                for i = kp - t  to y
                    match = true
                    // match t less than oroginal kp
                    for j = 0 to kp - 1 - t
                        if get_bar_color(i + j) != array.get(last_j_bars, j) 
                            match := false
                            break
                    if kp_trend
                        for j = 0 to kp - 1 - t
                            if get_bar_direction(i + j) != array.get(last_jud_bars, j) 
                                match := false
                                break
                    else
                        _weak_setup := "*"

                    if match
                        match_found := true
                        match_bar_index := i 
                        for m = 0 to kp - 1 - t 
                            array.set(match_dates, m, str.format("{0,date,yyyy-MM-dd}", time[i + m]))
                            array.set(match_prices, m, close[i + m - kp])
                        break
                _loop_index := t
    else
        for i = kp+lookback to y
            match = true
            for j = 0 to 0
            //for j = 0 to kp - 1
                //if get_bar_color(i + j) != array.get(last_j_bars, j)
                [_res1, _pos1] = bullishFlip(i,true)
                [_res2, _pos2] = bearishFlip(i,true) 
                [_res3, _pos3] = bullishFlip(i,false) 
                [_res4, _pos4] = bearishFlip(i,false)  


                //var table myTable = table.new(position = position.bottom_right, columns = 4, rows = 1, bgcolor = color.gray, border_width = 1)

                // Adding headers to the table
                //table.cell(table_id = myTable, column = 0, row = 0, text = str.tostring(_pos1), bgcolor = color.blue, text_color = color.white)
                //table.cell(table_id = myTable, column = 1, row = 0, text = str.tostring(_pos2), bgcolor = color.blue, text_color = color.white)
                //table.cell(table_id = myTable, column = 2, row = 0, text = str.tostring(_pos3), bgcolor = color.blue, text_color = color.white)
                //table.cell(table_id = myTable, column = 3, row = 0, text = str.tostring(_pos4), bgcolor = color.blue, text_color = color.white)

                if td_trend 
                    // if it return y (i.e 2000) then there is no match
                    if not _res1 
                        match := false
                        if (_pos1 > kp+ lookback) and (_pos1 < y)
                            //found a position
                            _found1 := true
                        break
                    else if not _res2 and not _found1
                        // bullish pattern not found
                        match := false
                        break
                else
                    if not _res3 
                        match := false
                        if (_pos2 > kp+ lookback) and (_pos1 < y)
                            _found2 := true
                        break
                    else if not _res4 and not _found2
                        match := false
                        break
            if match
                match_found := true
                match_bar_index := i
                for m = 0 to kp - 1
                    array.set(match_dates, m, str.format("{0,date,yyyy-MM-dd}", time[i + m]))
                    array.set(match_prices, m, close[i + m - kp])
                break

// if still no match (majority of case shoudl have match), try without up/down vs previous bar match

if barstate.islast and (match_bar_index == 0) and kp_auto
    for i = kp to y
        match = true
        for j = 0 to kp - 1
            if get_bar_color(i + j) != array.get(last_j_bars, j) 
                match := false
                break

        if match
            match_found := true
            _weak_setup := "*"
            match_bar_index := i
            for m = 0 to kp - 1
                array.set(match_dates, m, str.format("{0,date,yyyy-MM-dd}", time[i + m]))
                array.set(match_prices, m, close[i + m - kp])
            break

// ******************** DEBUG ********************************

if _debug
    var debugtable_position = debugdash_loc == 'Top Left' ? position.top_left : debugdash_loc == 'Top Center' ? position.top_center : debugdash_loc == 'Top Right' ? position.top_right : debugdash_loc == 'Mid Left' ? position.middle_left : debugdash_loc == 'Mid Center' ? position.middle_center : debugdash_loc == 'Mid Right' ? position.middle_right : debugdash_loc == 'Bottom Left' ? position.bottom_left: debugdash_loc == 'Bottom Center' ? position.bottom_center : position.bottom_right
    var debugtable_text_size = debugtext_size == 'Tiny' ? size.tiny : debugtext_size == 'Small' ? size.small : debugtext_size == 'Normal' ? size.normal : size.large

    // Display table
    if barstate.islast
        table_id = table.new(debugtable_position, rows=3, columns = kp + 1)
        table.cell(table_id, 0, 0, "Date {" + str.tostring(match_bar_index) + "}", bgcolor=color.gray, text_color=color.white,text_size=debugtable_text_size)
        table.cell(table_id, 0, 1, "Candlestick", bgcolor=color.gray, text_color=color.white,text_size=debugtable_text_size)
        table.cell(table_id, 0, 2, "Pattern", bgcolor=color.gray, text_color=color.white,text_size=debugtable_text_size)
    
        for i = 0 to kp - 1
            table.cell(table_id,i + 1, 0, array.get(last_j_dates, i), text_color=txt_col, text_size=debugtable_text_size)
            table.cell(table_id,i + 1, 1, array.get(last_j_bars, i), text_color=txt_col, text_size=debugtable_text_size, bgcolor=color.new(array.get(last_j_bars, i) == 'G' ? color.green : color.red, 90))
            table.cell(table_id,i + 1, 2, array.get(last_jud_bars, i), text_color=txt_col, text_size=debugtable_text_size, bgcolor=color.new(array.get(last_jud_bars, i) == 'U' ? color.rgb(13, 144, 225) : color.rgb(202, 68, 222), 90))


// ****************************************************

// Dominant Cycles
// Convert cycle to integer
cycle_int = int(length1)

// Calculate Bollinger Bands
bb_basis = ta.sma(price, bb_length)
bb_upper = bb_basis + bb_stddev * ta.stdev(price, bb_length)
bb_lower = bb_basis - bb_stddev * ta.stdev(price, bb_length)

// Calculate Keltner Channels
kc_basis = ta.ema(price, kc_length)
kc_upper = kc_basis + kc_mult * ta.atr(kc_length)
kc_lower = kc_basis - kc_mult * ta.atr(kc_length)

// Calculate TTM Squeeze
linreg = ta.linreg(price, kc_length, 0)
linreg_slope = linreg - linreg[1]
squeeze_on = (bb_upper - bb_lower) / (kc_upper - kc_lower) < 1

// Forecast future dates
forecast_date(periods) =>
    timestamp(year(timenow), month(timenow), dayofmonth(timenow) + periods, hour(timenow), minute(timenow), second(timenow))


forecast_price(periods) =>
   
    [real1, imag1, magnitude1] = goertzel(price, length1)
    [real2, imag2, magnitude2] = goertzel(price, length2)
    [real3, imag3, magnitude3] = goertzel(price, length3)

    // Calculate the phase adjustment based on the current price position
    price_position1 = ta.barssince(price == ta.lowest(price, length1)) / length1
    price_position2 = ta.barssince(price == ta.lowest(price, length2)) / length2
    price_position3 = ta.barssince(price == ta.lowest(price, length3)) / length3

    phase_adjustment1 = 2 * math.pi * price_position1
    phase_adjustment2 = 2 * math.pi * price_position2
    phase_adjustment3 = 2 * math.pi * price_position3
    
    phase1 = math.atan(imag1 / real1)
    phase2 = math.atan(imag2 / real2)
    phase3 = math.atan(imag3 / real3)
    
    amplitude1 = magnitude1 / 2
    amplitude2 = magnitude2 / 2
    amplitude3 = magnitude3 / 2
    
    center1 = (ta.highest(price, length1) + ta.lowest(price, length1)) / 2
    center2 = (ta.highest(price, length2) + ta.lowest(price, length2)) / 2
    center3 = (ta.highest(price, length3) + ta.lowest(price, length3)) / 2

    forecast1 = 0.0
    forecast2 = 0.0
    forecast3 = 0.0
    if length_sf
         // Add a phase shift of π (pi) radians to each sine wave
        // To shift the composite cycle by 1/2 of its length, you can add a phase shift of π (pi) radians 
        //to each of the individual sine waves in the composite forecast.
        forecast1 := center1 + amplitude1 * math.sin(phase1 + 2*length_cycle_sf*math.pi + 2 * math.pi * periods / length1)
        forecast2 := center2 + amplitude2 * math.sin(phase2 + 2*length_cycle_sf*math.pi + 2 * math.pi * periods / length2)
        forecast3 := center3 + amplitude3 * math.sin(phase3 + 2*length_cycle_sf*math.pi + 2 * math.pi * periods / length3)
    else
        forecast1 := center1 + amplitude1 * math.sin(phase1 + 2 * math.pi * periods / length1)
        forecast2 := center2 + amplitude2 * math.sin(phase2 + 2 * math.pi * periods / length2)
        forecast3 := center3 + amplitude3 * math.sin(phase3 + 2 * math.pi * periods / length3)
    
    weight1 = length1 / (length1 + length2 + length3)
    weight2 = length2 / (length1 + length2 + length3)
    weight3 = length3 / (length1 + length2 + length3)
    
    composite_forecast = forecast1 * weight1 + forecast2 * weight2 + forecast3 * weight3

    volatility = ta.stdev(price, volatility_length) / price
    
    // Adjust the composite forecast based on volatility
    volatility_factor = 1 + volatility
    composite_forecast := composite_forecast * volatility_factor
    
    //composite_forecast = (forecast1 + forecast2 + forecast3) / 3

    //Adjust the forecast price based on TTM Squeeze
    if squeeze_on and linreg_slope > 0
        composite_forecast := composite_forecast * 1.05
    else if squeeze_on and linreg_slope < 0
        composite_forecast := composite_forecast * 0.95
    
    composite_forecast


// Forecast future prices using time series analysis
forecast_price2(periods) =>
    slope = ta.linreg(price, cycle_int, 0)
    intercept = price[0] - slope * bar_index
    forecast2 = intercept + slope * (bar_index + periods)
    forecast2

// Forecast future prices using a sine wave
forecast_price3(periods) =>
    amplitude = (ta.highest(price, cycle_int) - ta.lowest(price, cycle_int)) / 2
    center = (ta.highest(price, cycle_int) + ta.lowest(price, cycle_int)) / 2
    phase = 2 * math.pi /cycle_int
    forecast3 = center + amplitude * math.sin(phase * (bar_index + periods))
    forecast3

// Define the lookback periods
lookbackSetup = 4
lookbackBonusSetup = 2

// Initialize counters
var int setupCountF = na
var int setupCountR = na
var int bonusCountF = na
var int bonusCountR = na

// Define the setup and bonus phases
setupPhaseF = close < close[lookbackSetup]
setupPhaseR = close > close[lookbackSetup]
bonusPhaseF = close < close[lookbackBonusSetup]
bonusPhaseR = close > close[lookbackBonusSetup]

// Increment the setup counter when the setup phase is triggered and price is falling
if setupPhaseF
    setupCountF := na(setupCountF) ? 1 : setupCountF + 1
    setupCountF
else
    setupCountF := na
    setupCountF

// Bonus increment to the bonus counter when the phase is triggered and price is falling
if setupCountF > 9 and bonusPhaseF
    bonusCountF := na(bonusCountF) ? 1 : bonusCountF + 1
    bonusCountF
else
    bonusCountF := na
    bonusCountF



// Increment the setup counter when setup phase is triggered and price is rising
if setupPhaseR
    setupCountR := na(setupCountR) ? 1 : setupCountR + 1
    setupCountR
else
    setupCountR := na
    setupCountR

// Bonus increment to the bonus counter when the phase is triggered and price is rising
if setupCountR > 9 and bonusPhaseR
    bonusCountR := na(bonusCountR) ? 1 : bonusCountR + 1
    bonusCountR
else
    bonusCountR := na
    bonusCountR

// Get swing high and low
pivotHigh = ta.pivothigh(high, leftBars, rightBars)
pivotLow = ta.pivotlow(low, leftBars, rightBars)


distance_to_pivot_high = ta.barssince(pivotHigh[match_bar_index+lookback+1])
distance_to_pivot_low = ta.barssince(pivotLow[match_bar_index+lookback+1])


distance_to_pivot_1 = "T/P (" + str.tostring(leftBars) + "/" + str.tostring(rightBars)  + ") " + str.tostring(distance_to_pivot_low) + "/" + str.tostring(distance_to_pivot_high) + "\n"

var table_position = dash_loc == 'Top Left' ? position.top_left : dash_loc == 'Bottom Left' ? position.bottom_left : dash_loc == 'Top Right' ? position.top_right : dash_loc == 'Mid Left' ? position.middle_left : dash_loc == 'Mid Right' ? position.middle_right : position.bottom_right
var table_text_size = text_size == 'Tiny' ? size.tiny : text_size == 'Small' ? size.small : text_size == 'Normal' ? size.normal : size.large

// Create a table to display the forecasted prices and dates
var table forecast_table = table.new(table_position, 3, forecast_periods + 1, border_width=1, border_color=txt_col,frame_color=txt_col,frame_width=1)

_delta4 = ""

if (open[match_bar_index] - close[match_bar_index]) < 0
    _delta4 := "g"
else
    _delta4 := "r"


bar_timestamp = time[match_bar_index]

//Specify the bar index for the vertical line
barIndex = bar_index[match_bar_index]

//Get the highest and lowest price in the visible chart to span the vertical line
highestPrice = request.security(syminfo.tickerid, "D", high, lookahead=barmerge.lookahead_on)
lowestPrice = request.security(syminfo.tickerid, "D", low, lookahead=barmerge.lookahead_on)

if match_bar_index > 0
    // Draw the vertical line if we are on the last bar (ensures highestPrice and lowestPrice are updated)
    if (barstate.islast)
        line.new(x1=barIndex, y1=lowestPrice, x2=barIndex, y2=highestPrice, width=2, color=color.rgb(224, 235, 101), style=line.style_solid,extend=extend.both)



// Calculate the number of bars since the start date
bars_since_start = bar_index - match_bar_index

_kp_str = "(" + _weak_setup + str.tostring(kp - _loop_index) + ")" 

// Add table headers
table.cell(forecast_table, 0, 0, 'Price [' + str.tostring(length1) + ',' + str.tostring(length2) + ',' + str.tostring(length3) + ']' +  "\n["  + str.tostring(setupCountR) + "," + str.tostring(bonusCountR) + "]", text_color=txt_col, text_size=table_text_size)
table.cell(forecast_table, 1, 0, 'Date' + "\n[" + str.tostring(setupCountF) + "," + str.tostring(bonusCountF) + "]" , text_color=txt_col, text_size=table_text_size)
if match_bar_index > 0
   
    table.cell(forecast_table, 2, 0,  distance_to_pivot_1 + str.format("{0,date,yyyy-MM-dd}", bar_timestamp) +  "\n" + _kp_str + '[' + str.tostring(match_bar_index) + '] ' + '(' + str.tostring(_delta4) + str.tostring(close[match_bar_index]) + ')', text_color=txt_col, text_size=table_text_size)
else
    table.cell(forecast_table, 2, 0,  _kp_str + '[' + str.tostring(match_bar_index) + '] ' + '(' + str.tostring(_delta4) + str.tostring(close[match_bar_index]) + ')', text_color=txt_col, text_size=table_text_size)    

// Populate the table with forecasted prices and dates
delta1 = 0.0
delta2 = 0.0


if match_bar_index + math.max(lookback,kp) < y
    for i = 1 to forecast_periods by 1
        forecast_price_value = forecast_price(i)
        forecast_date_value = forecast_date(i)
    
        //delta2 := close[match_bar_index] 
        if barstate.islast and match_bar_index > 0
            //delta2 := close[match_bar_index-i] 
            if (match_bar_index > lookback)
                //delta2 := close[match_bar_index-i] - close[match_bar_index-i+1]
                delta2 := close[match_bar_index-i]
            else
                delta2 := 0

            if (open[match_bar_index-i] - close[match_bar_index-i]) < 0
                _delta4 := "g"
            else
                _delta4 := "r"

    

        if close[match_bar_index+i] > close[match_bar_index+i+1]
            delta1 := math.abs(high[match_bar_index+i] - low[match_bar_index+i+1])
        else
            delta1 := -math.abs(high[match_bar_index+i] - low[match_bar_index+i+1])

        table.cell(forecast_table, 0, i, str.tostring(forecast_price_value+delta1, '#.##') + ' (' + str.tostring(delta1, '#.##') + ')', text_color=txt_col_price, text_size=table_text_size)
        table.cell(forecast_table, 1, i, str.format("{0,date,YY-M-dd}", forecast_date_value), text_color=txt_col_date, text_size=table_text_size)
        if match_bar_index > 0
            table.cell(forecast_table, 2, i, str.tostring(_delta4) + str.tostring(delta2, '#.##') + ' (' + str.tostring(forecast_price_value, '#.##') + ')', text_color=txt_col_price_adj, text_size=table_text_size)
        else
            table.cell(forecast_table, 2, i, ' (' + str.tostring(forecast_price_value, '#.##') + ')', text_color=txt_col_price_adj, text_size=table_text_size)

Overview

Bollinger Band, Keltner Channel and volatility lengths are also available as inputs. Projected values appear in a dashboard table on the chart. Projections are estimates and can change as new bars form. Version 4 adds cycle shifting and extra pattern matching options.

Details

Published by

mikeyhu70 on GitHub

Code credit

congacindy, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Settings

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

SettingTypeDefaultVariable
Dominant Cycle Length #1int68length1
Dominant Cycle Length #2int34length2
Dominant Cycle Length #3int17length3
Shift cycle its lengthbooltruelength_sf
# of cycle to shiftfloat1.0length_cycle_sf
Left Bars to get Pivot High/Lowint12leftBars
Right Bars to get Pivot High/Lowint12rightBars
Candlestick matching Red/Green pattern length (kp)int5kp
Max number of (kp) iterations (have to be less than kp)int1kp_iteration
Include Up/Down candlestick pattern (kp_trend)booltruekp_trend
Auto match up/down pattern if there is no match (will nullify previous setting i.e kp_trend)booltruekp_auto
TD demark flip setup? (if not contineous bar patten in kp length)boolfalsetd
Show all 32 settings
SettingTypeDefaultVariable
TD demark trend flip setup? (all first bars vs last bar logic)boolfalsetd_trend
TD Demark Lookback Flip Barsint4lookback
Lookback Barsint5000y
Number of Periods to Forecastint10forecast_periods
Show debug information?boolfalse_debug
pricesourcehl2price
Bollinger Bands Lengthint20bb_length
Bollinger Bands Standard Deviationfloat2.0bb_stddev
Keltner Channel Lengthint20kc_length
Keltner Channel Multiplierfloat1.0kc_mult
Volatility Lengthint20volatility_length
Text/Frame Colorcolorcolor.rgb(208, 227, 62)txt_col_price
Text/Frame Colorcolorcolor.rgb(231, 37, 237)txt_col_price_adj
Text/Frame Colorcolorcolor.rgb(48, 228, 241)txt_col_date
Text/Frame Colorcolorcolor.rgb(238, 232, 166)txt_col_pattern
Text/Frame Colorcolorcolor.rgb(182, 186, 200)txt_col
Dashboard LocationstringMid Rightdash_loc
Dashboard SizestringTinytext_size
Debug Dashboard SizestringTinydebugtext_size
Debug Dashboard LocationstringBottom Centerdebugdash_loc
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

Moving Average Channel plots separate simple moving averages for upper and lower bands on the price chart. It fills the space between bands with semi-transparent color and colors bars green above the upper band, red below the lower band, or gray in between. Us

Indicator v4 Moving averagesSupport & resistance
Updated 12 days ago · GPL-3.0 GitHub repository of Moving Average Channel

ICT Equal Highs and Lows

by ArunKBhaskar
575 stars

This overlay indicator finds pivot highs and lows on the price chart and compares the last two highs and the last two lows. When the percentage difference between a pair is below the Equal HL threshold, it treats them as equal levels and draws a box. Left and

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows
330 stars

This indicator monitors multiple cryptocurrency symbols for trading signals. It calculates and plots entry prices, take profit, and stop loss levels for each symbol including BTCUSDT, ETHUSDT, BNBUSDT and others. Price crossovers trigger buy, sell or close ale

Indicator v5 Support & resistanceScreeners & dashboards
Updated 2 months ago · None stated GitHub repository of Multi Alert Long/Short [Alorse]

This overlay indicator draws a fixed-range volume profile on the price chart, splitting traded activity into up and down volume at each price level. It also plots a sentiment profile, a developing point of control, and value-area high and low around a configur

Indicator v5 VolumeSupport & resistance
Updated 2 months ago · MIT GitHub repository of Volume Profile and Indicator by DGT

BZ-tracker

by Allen1212
303 stars

The BZ-tracker indicator marks ARK Invest buy and sell transactions on stock charts with labels. It plots green labels for purchases and red labels for sales, each annotated with a multiplier such as X1 or X2 to show the number of ARK ETFs trading the stock on

Indicator v4 Support & resistanceScreeners & dashboards
Updated 2 years ago · None stated GitHub repository of BZ-tracker

Function - Linear Regression

by ricardosantos79
261 stars

This indicator fits a linear regression through stored pivot highs and lows and draws the resulting channel on the price chart. A function returns predicted values, maximum and minimum deviations, and the average absolute deviation. Confirmed two-bar pivots up

Indicator v5 TrendSupport & resistance
Updated 4 years ago · None stated GitHub repository of Function - Linear Regression

More Support & resistance 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