PHP Code:
//@version=5
indicator("Foxy's Acceleration Bands", overlay=true)
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
factor= input(0.001382)
length = input(100)
mult = input.float(0.382, title="Mult")
show_middle_bands = input.bool(true, title="Show Middle Bands")
show_upper_bands = input.bool(true, title="Show Upper Bands")
maTypeInput = input.string("EMA", title="Band MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
middleTypeInput = input.string("EMA", title="Middle MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
logHigh = math.log10(high)
logLow = math.log10(low)
logClose = math.log10(close)
logAvg = math.log10((high + low) / 2)
logUppestband = ma(logHigh * (1 + 2 * (((logHigh - logLow) / (logAvg)) * 1000) * factor * (1+mult)), length, maTypeInput)
logUpperband = ma(logHigh * (1 + 2 * (((logHigh - logLow) / (logAvg)) * 1000) * factor), length, maTypeInput)
logLowerband = ma(logLow * (1 - 2 * (((logHigh - logLow) / (logAvg)) * 1000) * factor), length, maTypeInput)
logLowestband = ma(logLow * (1 - 2 * (((logHigh - logLow) / (logAvg)) * 1000) * factor / (1-mult)), length, maTypeInput)
logCentral = ma(logClose, length, middleTypeInput)
Uppestband = math.pow(10, logUppestband)
Upperband = math.pow(10, logUpperband)
Central = math.pow(10, logCentral)
Lowerband = math.pow(10, logLowerband)
Lowestband = math.pow(10, logLowestband)
//plot(Uppestband, color=color.red, linewidth=2, display=show_upper_bands ? display.all : display.none)
//plot(Upperband, color=color.red, linewidth=1, display=show_middle_bands ? display.all : display.none)
//plot(Central, color=color.orange, linewidth=1, display=show_middle_bands ? display.all : display.none)
//plot(Lowerband, color=color.green, linewidth=1, display=show_middle_bands ? display.all : display.none)
//plot(Lowestband, color=color.green, linewidth=2, display=show_upper_bands ? display.all : display.none)
draw_prediction = input.bool(true, title="Draw Prediction Lines")
slope_length_type = input.bool(true, title="Use Fixed Slope Length?")
fixed_slope_length = input(55, title = "Slope Length") // Useful for Prediction Upto Next (80% * Slope Length) Candles
slope_length = slope_length_type ? fixed_slope_length : last_bar_index - length
customLogarithmicRegression(_data, _color, _width) =>
logData = math.log10(_data)
linreg = ta.linreg(logData, slope_length, 0)
linreg_p = ta.linreg(logData, slope_length, 0 + 1)
x = bar_index
slope = linreg - linreg_p
intercept = linreg - x * slope
deviationSum = 0.0
for i = 0 to slope_length - 1 by 1
deviationSum += math.pow(logData[i] - (slope * (x - i) + intercept), 2)
deviation = math.sqrt(deviationSum / slope_length)
x1 = x - slope_length
x2 = x
y1 = slope * (x - slope_length) + intercept
y2 = linreg
var line b = na
updating = timestamp("20 Jul 2050 00:00 +0300") >= time
displacement = false
if draw_prediction
if updating
b := line.new(x1, math.pow(10, y1), x2, math.pow(10, y2), xloc.bar_index, extend.right, _color, style=line.style_dotted, width=_width)
if not displacement
line.delete(b[1])
if show_upper_bands
customLogarithmicRegression(Uppestband, color.rgb(1, 219, 248), 2)
customLogarithmicRegression(Lowestband, color.rgb(2, 219, 248), 2)
if show_middle_bands
//customLogarithmicRegression(Upperband, color.red, 1)
customLogarithmicRegression(Central, color.rgb(2, 221, 250), 1)
//customLogarithmicRegression(Lowerband, color.green, 1)
Yer İmleri