Untitled
3169
plain_text
a year ago
22 kB
10
Indexable
//@version=5 indicator(".", overlay = true) src33 = input(close, title="Source") highlight = input(true, title="Highlighting?") showSignals = input(true, title="Show Signals?") Q1 = input.int(1, title="Q1") Q2 = input.float(1, title="Q2") Q3 = Q2/100 Q4 = ta.ema(src33, Q1) Q5 = 0.0 Q5 := (Q4*(1-Q3))>nz(Q5[1],0) ? Q4*(1-Q3) : (Q4*(1+Q3))<nz(Q5[1],0) ? Q4*(1+Q3) : nz(Q5[1],0) Z1 = input.int(5, title="Z1") Z2 = input.float(5, title="Z2") Z3 = Z2/100 Z4 = ta.ema(src33, Z1) Z5 = 0.0 Z5 := (Z4*(1-Z3))>nz(Z5[1],0) ? Z4*(1-Z3) : (Z4*(1+Z3))<nz(Z5[1],0) ? Z4*(1+Z3) : nz(Z5[1],0) BuySignal = ta.crossover(Q5,Z5) SellSignal = ta.crossunder(Q5,Z5) Q5pl=plot(int(Q5/1.025+1.50)*1.025, color=color.green, linewidth=1,title="Direnç") Z5pl=plot(int(Z5/1.025+1.50)*1.025, color=color.red, linewidth=1,title="Destek") //fill(Q5pl,Z5pl, color= highlight ? Q5>Z5 ? color.new(color.green,50) : color.new(color.red,50) : na) //plotshape(showSignals and BuySignal, title="Buy Signal", style=shape.labelup, text="AL", textcolor=color.white, color=color.green, location=location.belowbar) //plotshape(showSignals and SellSignal, title="Sell Signal", style=shape.labeldown, text="SAT", textcolor=color.white, color=color.red, location=location.abovebar) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ ToolTips { t1 = "Volatility Period defines the length of the look-back period for calculating volatility. Higher values make the bands adapt more slowly to volatility changes. Lower values make them adapt more quickly." t2 = "Trend Factor adjusts the sensitivity of the trend line to price movements. A higher value makes the trend line less sensitive and smoother. Lower values make it more sensitive and reactive to price changes." t3 = "Trend Step controls how quickly the trend line adjusts to sudden price changes. Higher values cause slower adjustments, leading to smoother trend lines. Lower values result in quicker adjustments to sudden changes." //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Inputs { volatilityPeriod = input.int(20, title="Period", step=10, minval=2, maxval=1000, inline="vol", group="Volatility Settings", tooltip=t1) trendFactor = input.float(9, step=0.1, title='Factor', minval = 0.1, inline="", group="Trend Settings", tooltip=t2) trendStep = input.float(1, "Step", step=0.1,minval = 0.5, maxval = 5.0, inline="", group="Trend Settings", tooltip=t3) color_trend = input.color(color.rgb(209, 245, 3), title="Trend Line ", inline="trend", group="Style") colorForUpperBand = input.color(color.new(#862458, 10), title="Upper Band", inline="band", group="Style") colorForLowerBand = input.color(color.new(#493893, 10), title="Lower Band", inline="band", group="Style") //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Initialize Variables var float currentTrend = 0.0 var int trendDirection = 0 averageTrueRange = ta.atr(200) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Function to determine the trend direction determineTrendDirection(direction) => direction - direction[1] > 0 ? 1 : (direction - direction[1] < 0 ? -1 : 0) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Calculate Trend Direction closingPrice = close scaledStandardDev = (nz(averageTrueRange) * trendFactor) trendDirection := determineTrendDirection(currentTrend) * int(scaledStandardDev) priceTrendDiff = closingPrice - currentTrend > 0 ? closingPrice - currentTrend : currentTrend - closingPrice reciprocalFactor = (scaledStandardDev * (1 / trendFactor)) * 1 / math.pow(2, 100) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Calculate the Current Trend trendAdjustment = priceTrendDiff > scaledStandardDev * trendStep ? math.avg(closingPrice, currentTrend) : trendDirection * reciprocalFactor + currentTrend currentTrend := trendAdjustment //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Calculate Upper and Lower Bands upperBand = currentTrend + scaledStandardDev - averageTrueRange - ta.ema(ta.stdev(closingPrice, volatilityPeriod), 200) lowerBand = currentTrend - scaledStandardDev + averageTrueRange + ta.ema(ta.stdev(closingPrice, volatilityPeriod), 200) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} // ~~ Plot isTrendConsistent = trendDirection == trendDirection[1] colorForPlot = trendDirection == 1 ? color_trend : color_trend plotTrend = plot(isTrendConsistent ? currentTrend : na, title="VTrend ", color=colorForPlot) plotUpper = plot(isTrendConsistent ? upperBand : na, title="VDirenç", color = color.new(color.black, 100)) plotLower = plot(isTrendConsistent ? lowerBand : na, title="VDestek", color = color.new(color.black, 100)) //fill(plotUpper, plotTrend, top_color = colorForLowerBand, bottom_color =color.new(na,100), top_value = upperBand, bottom_value = currentTrend, title="Background Upper") //fill(plotTrend, plotLower, top_color = color.new(na,100), bottom_color = colorForUpperBand, top_value = currentTrend, bottom_value = lowerBand, title="Background Lower") //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~} //Trend Sar psar(start1, inc1, maximum1) => out1 = float(na) isUpTrend1 = bool(na) maxMin1 = float(na) acc1 = float(na) prev1 = float(na) if bar_index >= 1 prev1 := out1[1] if bar_index == 1 if close > close[1] isUpTrend1 := true maxMin1 := math.max(high, high[1]) prev1 := math.min(low, low[1]) prev1 else isUpTrend1 := false maxMin1 := math.min(low, low[1]) prev1 := math.max(high, high[1]) prev1 acc1 := start1 acc1 else isUpTrend1 := isUpTrend1[1] acc1 := acc1[1] maxMin1 := maxMin1[1] maxMin1 if isUpTrend1 if high > maxMin1 maxMin1 := high acc1 := math.min(acc1 + inc1, maximum1) acc1 else if low < maxMin1 maxMin1 := low acc1 := math.min(acc1 + inc1, maximum1) acc1 if na(out1) out1 := prev1 + acc1 * (maxMin1 - prev1) out1 if isUpTrend1 if low <= out1 isUpTrend1 := false out1 := maxMin1 maxMin1 := low acc1 := start1 acc1 else if high >= out1 isUpTrend1 := true out1 := maxMin1 maxMin1 := high acc1 := start1 acc1 if na(out1) if isUpTrend1 out1 := math.min(out1, bar_index == 1 ? low[1] : math.min(low[1], low[2])) out1 else out1 := math.max(out1, bar_index == 1 ? high[1] : math.max(high[1], high[2])) out1 [out1, acc1, maxMin1, isUpTrend1] start1 = input(0) increment1 = input(0.01) maximum1 = input(0.02) [p1, AF1, EP1, isUpTrend1] = psar(start1, increment1, maximum1) newEP1 = EP1 != EP1[1] epNew1 = newEP1 ? EP1 : na plot(p1, 'STrend', style=plot.style_stepline, color=isUpTrend1 ? color.rgb(25, 248, 5, 100) : color.rgb(243, 5, 5, 100), linewidth=1) plot(EP1, 'STrend Devam', style=plot.style_circles, color=isUpTrend1 ? color.rgb(25, 248, 5, 100) : color.rgb(243, 5, 5, 100), linewidth=2) /// sar hesaplamasını 1 dakika üzerinden bar renlendirmesi.... x1 = input.timeframe('1', title='Periyot') z = ta.sar(0, 0.02, 0.02) y1 = request.security(syminfo.tickerid, x1, z) xz = input(true, title='Renk') //Functions Sar for support and resistance q3 = ta.sar(0.01, 0.02, 0.2) q2 = ta.sar(0.01, 0.04, 0.4) q1 = ta.sar(0.01, 0.06, 0.6) plot(q3, title='UVSar', style=plot.style_circles, color=xz ? y1 > close ? color.rgb(255, 82, 82, 100) : color.rgb(0, 230, 119, 100) : color.rgb(178, 181, 190, 100), linewidth=1) plot(q2, title='OVSar', style=plot.style_circles, color=xz ? y1 > close ? color.rgb(255, 82, 82, 100) : color.rgb(0, 230, 119, 100) : color.rgb(178, 181, 190, 100), linewidth=1) plot(q1, title='KVSar', style=plot.style_circles, color=xz ? y1 > close ? color.rgb(255, 82, 82, 100) : color.rgb(0, 230, 119, 100) : color.rgb(178, 181, 190, 100), linewidth=1) //Signal xyzq = (y1) plot(xyzq, title='Yörük', style=plot.style_linebr, color=xz ? y1 > close ? color.rgb(255, 82, 82, 100) : color.rgb(0, 230, 119, 100) : color.rgb(178, 181, 190, 100), linewidth=1) //bcolor = ta.crossunder(close,q3) ? color.red : ta.crossover(close,q3) ? color.green: close>q2 ? color.green : close<q2 ? color.red: color.rgb(216, 4, 253) // : color.black //barcolor(bcolor) //// //Function inp = input(title='Source', defval=close) res = input.timeframe(title='Resolution', defval='60') rep = input(title='Allow Repainting?', defval=true) ////////////////////////////////////////////////////// src1 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1] fastLength1 = input.int(title='FastLength', defval=12, minval=1) slowLength1 = input.int(title='SlowLength', defval=26, minval=1) signalLength1 = input.int(title='SignalLength', defval=9, minval=1) macdLevel1 = input.float(title='MacdLevel', defval=0, minval=0) fastAlpha1 = 2.0 / (1 + fastLength1) slowAlpha1 = 2.0 / (1 + slowLength1) fastEma1 = ta.ema(src1, fastLength1) slowEma1 = ta.ema(src1, slowLength1) pMacdEq1 = fastAlpha1 - slowAlpha1 != 0 ? ((nz(fastEma1[1]) * fastAlpha1) - (nz(slowEma1[1]) * slowAlpha1)) / (fastAlpha1 - slowAlpha1) : 0 pMacdEqSig1 = ta.ema(pMacdEq1, signalLength1) pMacdLevel1 = fastAlpha1 - slowAlpha1 != 0 ? (macdLevel1 - (nz(fastEma1[1]) * (1 - fastAlpha1)) + (nz(slowEma1[1]) * (1 - slowAlpha1))) / (fastAlpha1 - slowAlpha1) : 0 slo1 = src1 - pMacdEq1 sig1 = slo1 > 0 ? slo1 > nz(slo1[1]) ? 2 : 1 : slo1 < 0 ? slo1 < nz(slo1[1]) ? -2 : -1 : 0 rmacdColor = sig1 > 1 ? color.rgb(0, 230, 119, 100) : sig1 > 0 ? color.rgb(0, 230, 119, 100) : sig1 < -1 ? color.rgb(255, 82, 82, 100) : sig1 < 0 ? color.rgb(255, 82, 82, 100) : color.white plot(pMacdEq1, title='MacdTrend',style=plot.style_stepline, color=rmacdColor, linewidth=2) plot(pMacdEqSig1, title='MacdStop', color=color.rgb(255, 255, 255, 100), linewidth=1) /////////////////////////////////////////////////////////////////////////// lenxc20 = input(1) lenxc50 = input(1) z20(close, lenxc20) => hcx20 = 0.0 dxc20 = 0.0 for i = 0 to lenxc20 - 1 by 1 kxc20 = (lenxc20 - i) * lenxc20 hcx20 += kxc20 dxc20 += close[i] * kxc20 dxc20 dxc20 / hcx20 cxc20 = z20(close, math.floor(math.sqrt(lenxc20))) // z50(close, lenxc50) => hxc50 = 0.0 dxc50 = 0.0 for i = 0 to lenxc50 - 1 by 1 kxc50 = (lenxc50 - i) * lenxc50 hxc50 += kxc50 dxc50 += close[i] * kxc50 dxc50 dxc50 / hxc50 cxc50 = z50(close, math.floor(math.sqrt(lenxc50))) // // startsx20 = 0.1 incrementsx20 = 0.1 maximumsx20 = 0.1 ssx20 = ta.sar(startsx20, incrementsx20, maximumsx20) s1sx20 = z20(ssx20, lenxc20) pcsx20 = close < s1sx20 ? color.rgb(255, 82, 82, 100) : color.rgb(76, 175, 79, 100) plot(s1sx20, title="YavaşDöngü",style=plot.style_line, color=pcsx20, linewidth=1) startsx50 = 0 incrementsx50 = 0.1 maximumsx50 = 1 ssx50 = ta.sar(startsx50, incrementsx50, maximumsx50) s1sx50 = z50(ssx50, lenxc50) pcsx50 = close < s1sx50 ? color.rgb(255, 82, 82, 100) : color.rgb(76, 175, 79, 100) plot(s1sx50, title="HızlıDöngü",style=plot.style_line, color=pcsx50, linewidth=1) //// //Stop Function mult156 = input.float(3, 'Multiplicative Factor', minval = 0) slope156 = input.float(100, 'Slope', minval = 0) width156 = input.float(100, 'Width %', minval = 0, maxval = 100) / 100 //Style bullCss156 = input.color(color.rgb(0, 230, 119, 100), 'Average Color', inline = 'avg', group = 'Style') bearCss156 = input.color(color.rgb(255, 82, 82, 100), '' , inline = 'avg', group = 'Style') //Calculation //-----------------------------------------------------------------------------{ var float upper156 = na var float lower156 = na var float avg156 = close var hold156 = 0. var os156 = 1. atr156 = nz(ta.atr(200)) * mult156 avg156 := math.abs(close - avg156) > atr156 ? math.avg(close, avg156) : avg156 + os156 * (hold156 / mult156 / slope156) os156 := math.sign(avg156 - avg156[1]) hold156 := os156 != os156[1] ? atr156 : hold156 upper156 := avg156 + width156 * hold156 lower156 := avg156 - width156 * hold156 css156 = os156 == 1 ? bullCss156 : bearCss156 plot_avg156 = plot(avg156, 'Kırılım', os156 != os156[1] ? na : css156, style=plot.style_line,linewidth = 4) //END import TradingView/ta/5 lnt = input(50, "Lenght") lnt2 = lnt * 2 off = input(1, "Offset") reg = ta.linreg(close, lnt, 0) reg2 = ta.linreg(close, lnt2, 0) regavg = math.avg(reg, reg2) barc = reg > reg[1] and reg2 > reg2[1] ? #79f504 : reg < reg[1] and reg2 < reg2[1] ? #e91e63 : color.rgb(11, 7, 236) barcolor(barc, 0, true, title = "Bar Color") plot(regavg, "Regression", color.rgb(255, 255, 255, 100), 1, plot.style_line, offset = off) //End //2 Pole Super Smoother Function SSF(x, t) => omega = 2 * math.atan(1) * 4 / t a = math.exp(-math.sqrt(2) * math.atan(1) * 4 / t) b = 2 * a * math.cos(math.sqrt(2) / 2 * omega) c2 = b c3 = -math.pow(a, 2) c1 = 1 - c2 - c3 SSF = 0.0 SSF := c1 * x + c2 * nz(SSF[1], x) + c3 * nz(SSF[2], nz(SSF[1], x)) SSF //Getter Function For Pseudo 2D Matrix get_val(mat, row, col, rowsize) => array.get(mat, int(rowsize * row + col)) //Setter Function For Pseudo 2D Matrix set_val(mat, row, col, rowsize, val) => array.set(mat, int(rowsize * row + col), val) //LU Decomposition Function LU(A, B) => A_size = array.size(A) B_size = array.size(B) var L = array.new_float(A_size) var U = array.new_float(A_size) L_temp = 0.0 U_temp = 0.0 for c = 0 to B_size - 1 by 1 set_val(U, 0, c, B_size, get_val(A, 0, c, B_size)) for r = 1 to B_size - 1 by 1 set_val(L, r, 0, B_size, get_val(A, r, 0, B_size) / get_val(U, 0, 0, B_size)) for r = 0 to B_size - 1 by 1 for c = 0 to B_size - 1 by 1 if r == c set_val(L, r, c, B_size, 1) if r < c set_val(L, r, c, B_size, 0) if r > c set_val(U, r, c, B_size, 0) for r = 0 to B_size - 1 by 1 for c = 0 to B_size - 1 by 1 if na(get_val(L, r, c, B_size)) L_temp := get_val(A, r, c, B_size) for k = 0 to math.max(c - 1, 0) by 1 L_temp -= get_val(U, k, c, B_size) * get_val(L, r, k, B_size) L_temp set_val(L, r, c, B_size, L_temp / get_val(U, c, c, B_size)) if na(get_val(U, r, c, B_size)) U_temp := get_val(A, r, c, B_size) for k = 0 to math.max(r - 1, 0) by 1 U_temp -= get_val(U, k, c, B_size) * get_val(L, r, k, B_size) U_temp set_val(U, r, c, B_size, U_temp) [L, U] //Lower Triangular Solution Function (Forward Substitution) LT_solve(L_, B) => B_size = array.size(B) var Y = array.new_float(B_size) Y_temp = 0.0 array.set(Y, 0, array.get(B, 0) / get_val(L_, 0, 0, B_size)) for r = 1 to B_size - 1 by 1 Y_temp := array.get(B, r) for k = 0 to math.max(r - 1, 0) by 1 Y_temp -= get_val(L_, r, k, B_size) * array.get(Y, k) Y_temp array.set(Y, r, Y_temp / get_val(L_, r, r, B_size)) Y //Upper Triangular Solution Function (Backward Substitution) UT_solve(U_, Y_) => Y_size = array.size(Y_) U_rev = array.copy(U_) Y_rev = array.copy(Y_) array.reverse(U_rev) array.reverse(Y_rev) X_rev = LT_solve(U_rev, Y_rev) X = array.copy(X_rev) array.reverse(X) X //Regression Function regression_val(X_, index_, order_, offset_) => reg = 0.0 for i = 0 to order_ by 1 reg += array.get(X_, i) * math.pow(index_ - offset_, i) reg reg //Curve Segment Drawing Function draw_curve(Y, sdev, n, step_, col, ls, lw, draw, conf) => var line segment = line.new(x1=time[n * step_], y1=array.get(Y, n) + sdev, x2=time[(n - 1) * step_], y2=array.get(Y, n - 1) + sdev, xloc=xloc.bar_time) if draw if conf ? barstate.isconfirmed : 1 line.set_xy1(segment, time[n * step_], array.get(Y, n) + sdev) line.set_xy2(segment, time[(n - 1) * step_], array.get(Y, n - 1) + sdev) line.set_color(segment, col) line.set_width(segment, lw) line.set_style(segment, ls == 'Solid' ? line.style_solid : ls == 'Dotted' ? line.style_dotted : line.style_dashed) else line.delete(segment) //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Inputs //----------------------------------------------------------------------------------------------------------------------------------------------------------------- //Source Inputs src44 = input(defval=close, title='Input Source Value') use_filt = input(defval=true, title='Smooth Data Before Curve Fitting') filt_per = input.int(defval=10, minval=2, title='Data Smoothing Period ═══════════════════') //Calculation Inputs per = input.int(defval=50, minval=2, title='Regression Sample Period') order = input.int(defval=2, minval=1, title='Polynomial Order') calc_offs = input(defval=0, title='Regression Offset') ndev = input.float(defval=2.0, minval=0, title='Width Coefficient') equ_from = input.int(defval=0, minval=0, title='Forecast From _ Bars Ago ═══════════════════') //Channel Display Inputs show_curve = input(defval=true, title='Show Fitted Curve') show_high = input(defval=true, title='Show Fitted Channel High') show_low = input(defval=true, title='Show Fitted Channel Low') draw_step1 = input.int(defval=10, minval=1, title='Curve Drawing Step Size') auto_step = input(defval=true, title='Auto Decide Step Size Instead') draw_freq = input.string(defval='Close Only', options=['Continuous', 'Close Only'], title='Curve Update Frequency') poly_col_h = input(defval=color.yellow, title='Channel High Line Color') poly_lw_h = input.int(defval=1, minval=1, title='Channel High Line Width') poly_ls_h = input.string(defval='Dashed', options=['Solid', 'Dotted', 'Dashed'], title='Channel High Line Style') poly_col_m = input(defval=color.rgb(255, 235, 59, 100), title='Channel Middle Line Color') poly_lw_m = input.int(defval=1, minval=1, title='Channel Middle Line Width') poly_ls_m = input.string(defval='Dotted', options=['Solid', 'Dotted', 'Dashed'], title='Channel Middle Line Style') poly_col_l = input(defval=color.yellow, title='Channel Low Line Color') poly_lw_l = input.int(defval=1, minval=1, title='Channel Low Line Width') poly_ls_l = input.string(defval='Dashed', options=['Solid', 'Dotted', 'Dashed'], title='Channel Low Line Style ═══════════════════') //Smooth data and determine source type for calculation. filt = SSF(src44, filt_per) src144 = use_filt ? filt : src44 //Populate a period sized array with bar values. var x_vals = array.new_float(per) for i = 0 to per - 1 by 1 array.set(x_vals, i, i + 1) //Populate a period sized array with historical source values. var src_vals = array.new_float(per) for i = 0 to per - 1 by 1 array.set(src_vals, i, src144[per - 1 - i + equ_from]) //Populate an order*2 + 1 sized array with bar power sums. var xp_sums = array.new_float(order * 2 + 1) xp_sums_temp = 0.0 for i = 0 to order * 2 by 1 xp_sums_temp := 0 for j = 0 to per - 1 by 1 xp_sums_temp += math.pow(array.get(x_vals, j), i) xp_sums_temp array.set(xp_sums, i, xp_sums_temp) //Populate an order + 1 sized array with (bar power)*(source value) sums. var xpy_sums = array.new_float(order + 1) xpy_sums_temp = 0.0 for i = 0 to order by 1 xpy_sums_temp := 0 for j = 0 to per - 1 by 1 xpy_sums_temp += math.pow(array.get(x_vals, j), i) * array.get(src_vals, j) xpy_sums_temp array.set(xpy_sums, i, xpy_sums_temp) //Generate a pseudo square matrix with row and column sizes of order + 1 using bar power sums. var xp_matrix = array.new_float(int(math.pow(order + 1, 2))) for r = 0 to order by 1 for c = 0 to order by 1 set_val(xp_matrix, r, c, order + 1, array.get(xp_sums, r + c)) //Factor the power sum matrix into lower and upper triangular matrices with order + 1 rows and columns. [lower, upper] = LU(xp_matrix, xpy_sums) //Find lower triangular matrix solutions using (bar power)*(source value) sums. l_solutions = LT_solve(lower, xpy_sums) //Find upper triangular matrix solutions using lower matrix solutions. This gives us our regression coefficients. reg_coefs = UT_solve(upper, l_solutions) //Define curve drawing step size. draw_step = auto_step ? math.ceil(per / 10) : draw_step1 //Calculate curve values. var inter_vals = array.new_float(11) for i = 0 to 10 by 1 array.set(inter_vals, i, regression_val(reg_coefs, per, order, calc_offs - equ_from + draw_step * i))
Editor is loading...
Leave a Comment