Indicator · Pine Script v5 · On the chart

Price and Date Forecast V1

by mikeyhu70· code credited to congacindy

This early indicator uses the Goertzel algorithm to estimate a dominant cycle from the chosen price source, then projects the cycle forward for a set number of periods.

View on GitHub

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

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

Price and Date Forecast V1.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 V1)', overlay=true)

// Input parameters
cycle_length = input.int(12, title='Dominant Cycle Length', minval=1)
forecast_periods = input.int(10, title='Number of Periods to Forecast', minval=1)
price = input.source(hl2)

// 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_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')


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

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

// Convert cycle to integer
cycle_int = int(cycle_length)

//forecast_price(periods) =>
//    [real, imag, magnitude] = goertzel(price, cycle_length)
//    phase = math.atan(imag/ real)
//    amplitude = magnitude / 2
//    center = (ta.highest(price, cycle_int) + ta.lowest(price, cycle_int)) / 2
//    forecast = center + amplitude * math.sin(phase + 2 * math.pi * periods / cycle_int)
//    forecast

forecast_price(periods) =>
    [real, imag, magnitude] = goertzel(price, cycle_length)
    phase = math.atan(imag / real)
    amplitude = (ta.highest(price, cycle_int) - ta.lowest(price, cycle_int)) / 2
    center = (ta.highest(price, cycle_int) + ta.lowest(price, cycle_int)) / 2
    
    historical_volatility = ta.stdev(price, cycle_int) / center
    
    sine_wave = amplitude * math.sin(phase + 2 * math.pi * periods / cycle_int)
    
    pattern_length = cycle_int
    pattern = true
    for i = 1 to pattern_length - 1
        if price[i] <= price[i-1]
            pattern := false
            break
    
    var forecast = 0.0
    
    if pattern
        forecast := center + sine_wave * (1 + historical_volatility * (math.random() - 0.5))
    else
        forecast := center + sine_wave * (1 - historical_volatility * (math.random() - 0.5))
    
    current_close = close
    forecast_adjusted = (forecast + current_close) / 2
    
    forecast_adjusted





//forecast_price(periods) =>
//    [real, imag, magnitude] = goertzel(price, cycle_length)
//    phase = math.atan(imag / real)
//    amplitude = (ta.highest(price, cycle_int) - ta.lowest(price, cycle_int)) / 2
//    center = (ta.highest(price, cycle_int) + ta.lowest(price, cycle_int)) / 2
//    
//    historical_volatility = ta.stdev(price, cycle_int) / center
//    
//    sine_wave = amplitude * math.sin(phase + 2 * math.pi * periods / cycle_int)
//    forecast = center + sine_wave * (1 + historical_volatility * (math.random() - 0.5))
//    forecast



//forecast_price(periods) =>
//    [real, imag, magnitude] = goertzel(price, cycle_length)
//    phase = math.atan(imag / real)
//    amplitude = (ta.highest(price, cycle_int) - ta.lowest(price, cycle_int)) / 2
//    center = (ta.highest(price, cycle_int) + ta.lowest(price, cycle_int)) / 2
//    sine_wave = amplitude * math.sin(phase + 2 * math.pi * periods / cycle_int)
//    forecast = center + sine_wave
//    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


// Forecast future dates
//forecast_date(periods) =>
//    timestamp(year(timenow) + math.floor((month(timenow) + periods - 1) / 12), (month(timenow) + periods - 1) % 12 + 1, dayofmonth(timenow), hour(timenow), minute(timenow), second(timenow))

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


// Plot the dominant cycle
//plot(cycle, color=color.new(color.blue, 0), title='Dominant Cycle')

// Display the prices following the matching price pattern
//var table forecast_table = table.new(position.bottom_right, 1, forecast_length + 1, border_width=1)
//table.cell(forecast_table, 0, 0, 'Forecasted Prices', text_color=color.white, bgcolor=color.gray)

//for i = 1 to forecast_length by 1
//    if similar_pattern_index + pattern_length + i - 1 < bar_index
//        forecasted_price = close[similar_pattern_index + pattern_length + i - 1]
//        table.cell(forecast_table, 0, i, str.tostring(forecasted_price, '#.##'), bgcolor=color.white)
//    else
//        table.cell(forecast_table, 0, i, 'N/A', bgcolor=color.white)


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, 2, forecast_periods + 1, border_width=1, border_color=txt_col,frame_color=txt_col,frame_width=1)

// Add table headers
//table.cell(forecast_table, 0, 0, 'Period', text_color=txt_col, text_size=table_text_size)
table.cell(forecast_table, 0, 0, 'Price', text_color=txt_col, text_size=table_text_size)
table.cell(forecast_table, 1, 0, 'Date', text_color=txt_col, text_size=table_text_size)

// Populate the table with forecasted prices and dates
for i = 1 to forecast_periods by 1
    forecast_price_value = forecast_price(i)
    forecast_date_value = forecast_date(i)
    //table.cell(forecast_table, 0, i, str.tostring(i), text_color=txt_col, text_size=table_text_size)
    table.cell(forecast_table, 0, i, str.tostring(forecast_price_value, '#.##'), text_color=txt_col_price, text_size=table_text_size)
    table.cell(forecast_table, 1, i, str.format("{0,date,yyyy-MM-dd}", forecast_date_value), text_color=txt_col_date, text_size=table_text_size)

Overview

Projected prices and dates are shown in a dashboard table on the price chart. The cycle length, forecast periods, source, table position and colours are adjustable. The projection is a mathematical estimate and may not hold as new bars form.

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 Lengthint12cycle_length
Number of Periods to Forecastint10forecast_periods
pricesourcehl2price
Text/Frame Colorcolorcolor.rgb(208, 227, 62)txt_col_price
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
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