커뮤니티

수식 변환 부탁 드립니다.

프로필 이미지
cooparoo
2024-04-29 16:57:02
768
글번호 179043
답변완료
안녕하세요. 다음은 파인스크립트로 작성된 지표식입니다. 예스로 변환 부탁드립니다. 감사합니다. /@version=5 indicator("Hybrid EMA AlgoLearner", shorttitle="Hybrid EMA AlgoLearner", overlay=false) // Parameters for EMAs shortTermPeriod = 50 longTermPeriod = 200 // k-NN parameter k = input.int(5, 'K - Number of neighbors') // Calculate EMAs shortTermEma = ta.ema(close, shortTermPeriod) longTermEma = ta.ema(close, longTermPeriod) // Custom k-NN Algorithm for weighted EMA var float[] distances = array.new_float(0) array.clear(distances) for i = 1 to 100 by 1 // Loop through past 100 data points distance = math.abs(shortTermEma - longTermEma[i]) array.push(distances, distance) array.sort(distances) k_distances = array.new_float(0) for i = 0 to k - 1 by 1 array.push(k_distances, array.get(distances, i)) // Calculate weighted EMA based on closest k distances weightShortTermEma = 0.0 totalWeight = 0.0 for i = 0 to k - 1 by 1 weight = array.get(k_distances, i) weightShortTermEma += shortTermEma[i] * weight totalWeight += weight weightShortTermEma /= totalWeight // Scale weightShortTermEma between 0 - 100 var float minEma = na var float maxEma = na // Instead of all the history, only look at the last N bars. lookbackPeriod = input.int(400, 'lookbackPeriod') minEma := ta.lowest(weightShortTermEma, lookbackPeriod) maxEma := ta.highest(weightShortTermEma, lookbackPeriod) scaledWeightShortTermEma = (weightShortTermEma - minEma) / (maxEma - minEma) * 100 //== plot emaplot = plot(scaledWeightShortTermEma, title='Scaled Weighted Short-Term EMA', color = color.new(#a6a8a3, 0), linewidth = 1) midLinePlot = plot(50, color = na, editable = false, display = display.none) // Fill between plots and add horizontal lines fill(emaplot, midLinePlot, 105, 85, top_color = color.new(#057ec4, 0), bottom_color = color.new(#6ca800, 100), title = "Overbought Gradient Fill") fill(emaplot, midLinePlot, 15, -5, top_color = color.new(#a83c91, 100), bottom_color = color.new(#fcf801, 0), title = "Oversold Gradient Fill") hline(15, color = color.new(#8b3131, 50)) hline(50, color = color.new(color.gray, 49)) hline(85, color = color.new(#2c5c2e, 50))
지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2024-04-30 13:26:05

안녕하세요 예스스탁입니다. // Parameters for EMAs input : shortTermPeriod(50),longTermPeriod(200); input : k(5); input : lookbackPeriod(400); var : shortTermEma(0),longTermEma(0),i(0),distance(0); var : weightShortTermEma(0),totalWeight(0),weight(0); var : minEma(0),maxEma(0),scaledWeightShortTermEma(0); Array : distances[100](0),k_distances[100](0); shortTermEma = ema(close, shortTermPeriod); longTermEma = ema(close, longTermPeriod); for i = 1 to 100 step 1 { distance = abs(shortTermEma - longTermEma[i]); distances[i-1] = distance; } SortArray(distances,100,1); for i = 0 to k - 1 step 1 { k_distances[i] = distances[i]; } weightShortTermEma = 0; totalWeight = 0; for i = 0 to k - 1 step 1 { weight = k_distances[i]; weightShortTermEma = weightShortTermEma+(shortTermEma[i] * weight); totalWeight = totalWeight+ weight; } weightShortTermEma = weightShortTermEma/totalWeight; minEma = lowest(weightShortTermEma, lookbackPeriod); maxEma = highest(weightShortTermEma, lookbackPeriod); scaledWeightShortTermEma = (weightShortTermEma - minEma) / (maxEma - minEma) * 100; plot1(scaledWeightShortTermEma,"Scaled Weighted Short-Term EMA",Gray); PlotBaseLine1(15); PlotBaseLine2(50); PlotBaseLine3(85); 즐거운 하루되세요 > cooparoo 님이 쓴 글입니다. > 제목 : 수식 변환 부탁 드립니다. > 안녕하세요. 다음은 파인스크립트로 작성된 지표식입니다. 예스로 변환 부탁드립니다. 감사합니다. /@version=5 indicator("Hybrid EMA AlgoLearner", shorttitle="Hybrid EMA AlgoLearner", overlay=false) // Parameters for EMAs shortTermPeriod = 50 longTermPeriod = 200 // k-NN parameter k = input.int(5, 'K - Number of neighbors') // Calculate EMAs shortTermEma = ta.ema(close, shortTermPeriod) longTermEma = ta.ema(close, longTermPeriod) // Custom k-NN Algorithm for weighted EMA var float[] distances = array.new_float(0) array.clear(distances) for i = 1 to 100 by 1 // Loop through past 100 data points distance = math.abs(shortTermEma - longTermEma[i]) array.push(distances, distance) array.sort(distances) k_distances = array.new_float(0) for i = 0 to k - 1 by 1 array.push(k_distances, array.get(distances, i)) // Calculate weighted EMA based on closest k distances weightShortTermEma = 0.0 totalWeight = 0.0 for i = 0 to k - 1 by 1 weight = array.get(k_distances, i) weightShortTermEma += shortTermEma[i] * weight totalWeight += weight weightShortTermEma /= totalWeight // Scale weightShortTermEma between 0 - 100 var float minEma = na var float maxEma = na // Instead of all the history, only look at the last N bars. lookbackPeriod = input.int(400, 'lookbackPeriod') minEma := ta.lowest(weightShortTermEma, lookbackPeriod) maxEma := ta.highest(weightShortTermEma, lookbackPeriod) scaledWeightShortTermEma = (weightShortTermEma - minEma) / (maxEma - minEma) * 100 //== plot emaplot = plot(scaledWeightShortTermEma, title='Scaled Weighted Short-Term EMA', color = color.new(#a6a8a3, 0), linewidth = 1) midLinePlot = plot(50, color = na, editable = false, display = display.none) // Fill between plots and add horizontal lines fill(emaplot, midLinePlot, 105, 85, top_color = color.new(#057ec4, 0), bottom_color = color.new(#6ca800, 100), title = "Overbought Gradient Fill") fill(emaplot, midLinePlot, 15, -5, top_color = color.new(#a83c91, 100), bottom_color = color.new(#fcf801, 0), title = "Oversold Gradient Fill") hline(15, color = color.new(#8b3131, 50)) hline(50, color = color.new(color.gray, 49)) hline(85, color = color.new(#2c5c2e, 50))