Indicator · Pine Script v5 · On the chart

Price and Date Forecast V3 Debug

by mikeyhu70· code credited to congacindy

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

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code274
Settings27inputs
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

274 lines of Pine Script v5 from Forecast/Price and Date Forecast (2024 V3 DEBUG).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 V3 DEBUG).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 V3 DEBUG)', 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)
leftBars = input.int(8, "Left Bars to get Pivot High/Low", minval=1)
rightBars = input.int(8, "Right Bars to get Pivot High/Low", minval=1)
kp = input(5, title="Candlestick Matching Pattern Length")
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 firs 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(true, 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]))

match_found = false
match_dates = array.new_string(forecast_periods)
match_prices = array.new_float(forecast_periods)
var match_bar_index = 0

// ********************** 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 *****************************


_found1 = false
_found2 = false

if barstate.islast
    if not td
        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

            for j = 0 to kp - 1
                if get_bar_direction(i + j) != array.get(last_jud_bars, j) 
                    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
    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 match_bar_index == 0
    match_bar_index := kp

// ******************** 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))

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. Debug information is switched on by default.

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

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
Dominant Cycle Length #1int68length1
Dominant Cycle Length #2int34length2
Dominant Cycle Length #3int17length3
Left Bars to get Pivot High/Lowint8leftBars
Right Bars to get Pivot High/Lowint8rightBars
Candlestick Matching Pattern Lengthint5kp
TD demark flip setup? (if not contineous bar patten in kp length)boolfalsetd
TD demark trend flip setup? (all firs bars vs last bar logic)boolfalsetd_trend
TD Demark Lookback Flip Barsint4lookback
Lookback Barsint5000y
Number of Periods to Forecastint10forecast_periods
Show debug information?booltrue_debug
Show all 27 settings
SettingTypeDefaultVariable
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