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)
///////
//@version=5
lengthx = input.int(55, title="Length", minval = 1, maxval = 5000)
src = input.source(close, title="Source")
// ----------------------------------------------------------------------
upper_1_bool_input = input.bool(false, title="Upper +1", inline="abc", group = "channel")
upper_1_float_input = input.float(1.0, title="", inline="abc", group = "channel")
upper_2_bool_input = input.bool(false, title="Upper +2", inline="cde", group = "channel")
upper_2_float_input = input.float(2.0, title="", inline="cde", group = "channel")
upper_3_bool_input = input.bool(false, title="Upper +3", inline="ghi", group = "channel")
upper_3_float_input = input.float(3.0, title="", inline="ghi", group = "channel")
lower_1_bool_input = input.bool(false, title="Lower -1", inline="bcd", group = "channel")
lower_1_float_input = input.float(1.0, title="", inline="bcd", group = "channel")
lower_2_bool_input = input.bool(false, title="Lower -2", inline="def", group = "channel")
lower_2_float_input = input.float(2.0, title="", inline="def", group = "channel")
lower_3_bool_input = input.bool(false, title="Lower +3", inline="hij", group = "channel")
lower_3_float_input = input.float(3.0, title="", inline="hij", group = "channel")
// ----------------------------------------------------------------------
color_upper_1 = input.color(color.new(#2195f3, 90), "", inline = "colors", group = "colors")
color_upper_2 = input.color(color.new(#4caf4f, 100), "", inline = "colors", group = "colors")
color_upper_3 = input.color(color.new(#ff5252, 100), "", inline = "colors", group = "colors")
color_lower_1 = input.color(color.new(#2195f3, 90), "", inline = "colors", group = "colors")
color_lower_2 = input.color(color.new(#4caf4f, 100), "", inline = "colors", group = "colors")
color_lower_3 = input.color(color.new(#ff5252, 100), "", inline = "colors", group = "colors")
// ----------------------------------------------------------------------
visual_settings_group = "Visual Settings"
prinp = input.bool(false, "Show Pearson's R", group = visual_settings_group)
exl = input.bool(false, "Extend Lines Left", group = visual_settings_group)
exr = input.bool(true, "Extend Lines Right", group = visual_settings_group)
exs = switch
exl and exr => extend.both
exl => extend.left
exr => extend.right
=> extend.none
// ----------------------------------------------------------------------
slpclc(source, lengthx) =>
max_bars_back(source, 5000)
if not barstate.islast or lengthx <= 1
[float(na), float(na), float(na)]
else
sumX = 0.0
sumY = 0.0
sumXSqr = 0.0
sumXY = 0.0
for i = 0 to lengthx - 1 by 1
val = source[i]
per = i + 1.0
sumX += per
sumY += val
sumXSqr += per * per
sumXY += val * per
slope = (lengthx * sumXY - sumX * sumY) / (lengthx * sumXSqr - sumX * sumX)
average = sumY / lengthx
intercept = average - slope * sumX / lengthx + slope
[slope, average, intercept]
// ----------------------------------------------------------------------
[s, a, i] = slpclc(src, lengthx)
st_price = i + s * (lengthx - 1)
end_price = i
base_line = line.new(bar_index - lengthx + 1, st_price, bar_index, end_price, width=1, extend=exs, style=line.style_dashed, color=color.new(color.orange, 0))
// ----------------------------------------------------------------------
devcalc(source, lengthx, slope, average, intercept) =>
upDev = 0.0
dnDev = 0.0
stdDevAcc = 0.0
dsxx = 0.0
dsyy = 0.0
dsxy = 0.0
periods = lengthx - 1
daY = intercept + slope * periods / 2
val = intercept
for j = 0 to periods by 1
price = high[j] - val
if price > upDev
upDev := price
price := val - low[j]
if price > dnDev
dnDev := price
price := source[j]
dxt = price - average
dyt = val - daY
price -= val
stdDevAcc += price * price
dsxx += dxt * dxt
dsyy += dyt * dyt
dsxy += dxt * dyt
val += slope
stdDev = math.sqrt(stdDevAcc / (periods == 0 ? 1 : periods))
pearsonR = dsxx == 0 or dsyy == 0 ? 0 : dsxy / math.sqrt(dsxx * dsyy)
[stdDev, pearsonR, upDev, dnDev]
// ----------------------------------------------------------------------
[stdDev, pearsonR, upDev, dnDev] = devcalc(src, lengthx, s, a, i)
// ----------------------------------------------------------------------
create_line(bool_input, float_input, color, dev) =>
line_start_price = st_price + (bool_input ? float_input * stdDev : dev)
line_end_price = end_price + (bool_input ? float_input * stdDev : dev)
line.new(bar_index - lengthx + 1, line_start_price, bar_index, line_end_price, width=1, style=line.style_dashed, extend=exs, color=color.new(color, 0))
// ----------------------------------------------------------------------
upper_1_line = create_line(upper_1_bool_input, upper_1_float_input, color_upper_1, upDev)
//upper_2_line = create_line(upper_2_bool_input, upper_2_float_input, color_upper_2, upDev)
//upper_3_line = create_line(upper_3_bool_input, upper_3_float_input, color_upper_3, upDev)
lower_1_line = create_line(lower_1_bool_input, -lower_1_float_input, color_lower_1, -dnDev)
//lower_2_line = create_line(lower_2_bool_input, -lower_2_float_input, color_lower_2, -dnDev)
//lower_3_line = create_line(lower_3_bool_input, -lower_3_float_input, color_upper_3, -dnDev)
// ----------------------------------------------------------------------
linefill.new(upper_1_line, base_line, color = color_upper_1)
linefill.new(lower_1_line, base_line, color = color_lower_1)
// ----------------------------------------------------------------------
Yer İmleri