0% found this document useful (0 votes)
24 views2 pages

Predict Future Price

According to RSI

Uploaded by

future7gg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Predict Future Price

According to RSI

Uploaded by

future7gg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//@version=5

indicator("Price Prediction with Linear Regression and Additional Indicators",


overlay=true)

// Input Parameters
lookback = input.int(20, minval=5, title="Linear Regression Lookback Period")
forecast_bars = input.int(5, minval=1, maxval=20, title="Number of Bars to Forecast
(1-20)")
vertical_offset = input.float(0.0, title="Vertical Offset for Forecasted Line",
step=0.1)

// EMA Parameters
ema_length = input.int(14, minval=1, title="EMA Length")

// MACD Parameters
fast_length = input.int(12, minval=1, title="MACD Fast Length")
slow_length = input.int(26, minval=1, title="MACD Slow Length")
signal_length = input.int(9, minval=1, title="MACD Signal Length")

// Calculate EMA
ema_value = ta.ema(close, ema_length)
plot(ema_value, color=color.green, title="EMA")

// Calculate MACD
[macd_line, signal_line, hist_line] = ta.macd(close, fast_length, slow_length,
signal_length)
plot(macd_line, color=color.blue, title="MACD Line")
plot(signal_line, color=color.orange, title="Signal Line")
plot(hist_line, color=color.gray, style=plot.style_histogram, title="MACD
Histogram")

// Calculate Linear Regression


linreg = ta.linreg(close, lookback, 0)

// Calculate the Slope


slope = ta.linreg(close, lookback, 1) - linreg

// Adjust the Slope Based on EMA and MACD


momentum_factor = 1.0
if (ema_value > linreg) and (macd_line > signal_line)
momentum_factor := 1.05 // Upward adjustment
else if (ema_value < linreg) and (macd_line < signal_line)
momentum_factor := 0.95 // Downward adjustment

adjusted_slope = slope * momentum_factor

// Plot the Historical Linear Regression Line


plot(linreg, color=color.orange, title="Linear Regression")

// Declare the Line Variable


var line forecast_line = na

// Delete Previous Line if It Exists


if not na(forecast_line)
line.delete(forecast_line)

// Draw a New Line Representing the Forecast


forecast_line := line.new(x1=bar_index,y1=linreg + vertical_offset, x2=bar_index +
forecast_bars,y2=(linreg + adjusted_slope * forecast_bars) + vertical_offset,
xloc=xloc.bar_index, extend=extend.none, color=color.blue, style=line.style_dotted,
width=2)

// Prepare Forecasted Values for Plotting


var float[] forecast_values = array.new_float(forecast_bars)

// Calculate Forecasted Values Once per Bar


if barstate.islast
for i = 0 to forecast_bars - 1
future_value = linreg + adjusted_slope * (i + 1) + vertical_offset
array.set(forecast_values, i, future_value)

// Plot Forecasted Values


for i = 0 to forecast_bars - 1
plot_value = array.get(forecast_values, i)
offset_index = i + 1
label.new(x=bar_index + offset_index, y=plot_value,text="",
style=label.style_none, color=color.new(color.red, 50))

You might also like