안녕하세요.
아래의 TV수식을 YS수식으로 바꿀 수 있을까요?
부탁드립니다.
수식명 : Gaussian Moving Average (GA)
//@version=5
indicator("GA", overlay = true)
// Define a function to calculate the Gaussian weight for a given 'k' and 'smooth_per'
gaussian_weight(k, smooth_per) =>
// Calculate the standard deviation (sigma) based on the smoothing period
sigma = smooth_per / 2.0
// Calculate the exponent part of the Gaussian function
exponent = -0.5 * math.pow(k / sigma, 2)
// Calculate and return the Gaussian weight
math.exp(exponent)
// Define a function that takes an array of values as input
// and returns the Gaussian moving average of the data
gaussianma(values, length) =>
// Create an array to store the Gaussian weights
weights_array = array.new_float(length)
for i = 0 to length - 1
array.set(weights_array, i, gaussian_weight(i, length))
// Create an array to store the values
values_array = array.new_float(length)
for i = 0 to length - 1
array.set(values_array, i, values[length - 1 - i])
// Calculate the weighted sum of the values and weights
sum = 0.0
sumw = 0.0
for i = 0 to length - 1
sum += array.get(values_array, i) * array.get(weights_array, i)
sumw += array.get(weights_array, i)
// Return the moving average
sum / sumw
source = input.source(close, "Source")
length = input.int(20, "Length", 1)
// Plot the Gaussian moving average on the chart
plot(gaussianma(source, length), color = color.orange)
답변 1
예스스탁
예스스탁 답변
2023-11-20 16:42:34
안녕하세요
예스스탁입니다.
input : source(close),length(20);
var : i(0),sigma(0),exponent(0),gaussian_weight(0),sum(0),sumw(0),gaussianma(0);
Array : weights_array[100](0),values_array[100](0);
for i = 0 to length - 1
{
sigma = length / 2.0;
exponent = -0.5 * pow(i / sigma, 2);
gaussian_weight = exp(exponent);
weights_array[i] = gaussian_weight;
values_array[i] = source[length - 1 - i];
}
sum = 0.0;
sumw = 0.0;
for i = 0 to length - 1
{
sum = sum + values_array[i]*weights_array[i];
sumw = sumw + weights_array[i];
}
gaussianma = sum / sumw;
plot1(gaussianma,"gaussianma",orange);
즐거운 하루되세요
> 기찬주 님이 쓴 글입니다.
> 제목 : 부탁드립니다
> 안녕하세요.
아래의 TV수식을 YS수식으로 바꿀 수 있을까요?
부탁드립니다.
수식명 : Gaussian Moving Average (GA)
//@version=5
indicator("GA", overlay = true)
// Define a function to calculate the Gaussian weight for a given 'k' and 'smooth_per'
gaussian_weight(k, smooth_per) =>
// Calculate the standard deviation (sigma) based on the smoothing period
sigma = smooth_per / 2.0
// Calculate the exponent part of the Gaussian function
exponent = -0.5 * math.pow(k / sigma, 2)
// Calculate and return the Gaussian weight
math.exp(exponent)
// Define a function that takes an array of values as input
// and returns the Gaussian moving average of the data
gaussianma(values, length) =>
// Create an array to store the Gaussian weights
weights_array = array.new_float(length)
for i = 0 to length - 1
array.set(weights_array, i, gaussian_weight(i, length))
// Create an array to store the values
values_array = array.new_float(length)
for i = 0 to length - 1
array.set(values_array, i, values[length - 1 - i])
// Calculate the weighted sum of the values and weights
sum = 0.0
sumw = 0.0
for i = 0 to length - 1
sum += array.get(values_array, i) * array.get(weights_array, i)
sumw += array.get(weights_array, i)
// Return the moving average
sum / sumw
source = input.source(close, "Source")
length = input.int(20, "Length", 1)
// Plot the Gaussian moving average on the chart
plot(gaussianma(source, length), color = color.orange)