수고 하십니다.
아래 식 변환 부탁드립니다.
수고하세요...
#########################
input length = 5;
def n = length;
def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def x = bn;
def y = close;
# calculate summation values
def startBar = lastBar - (n - 1);
def sumX = if bn < startBar then 0 else x + sumX[1];
def sumY = if bn < startBar then 0 else y + sumY[1];
def sumX2 = if bn < startBar then 0 else Power(x, 2) + sumX2[1];
def sumX3 = if bn < startBar then 0 else Power(x, 3) + sumX3[1];
def sumX4 = if bn < startBar then 0 else Power(x, 4) + sumX4[1];
def sumXY = if bn < startBar then 0 else x * y + sumXY[1];
def sumX2Y = if bn < startBar then 0 else Power(x, 2) * y + sumX2Y[1];
# intermediary calculations
def xx = sumX2 - Power(sumX, 2) / n;
def xy = sumXY - (sumX * sumY / n);
def xx2 = sumX3 - (sumX2 * sumX / n);
def x2y = sumX2Y - (sumX2 * sumY / n);
def x2x2 = sumX4 - (Power(sumX2, 2) / n);
# calculate coefficients
def a0 = (x2y * xx - xy * xx2) / (xx * x2x2 - Power(xx2, 2));
def b0 = (xy * x2x2 - x2y * xx2) / (xx * x2x2 - Power(xx2, 2));
def c0 = sumY / n - b0 * sumX / n - a0 * sumX2 / n;
# for a, b, and c use the final value on the last bar of the chart for all calculations
def a = GetValue(a0, bn - lastBar);
def b = GetValue(b0, bn - lastBar);
def c = GetValue(c0, bn - lastBar);
# calculate and plot
plot theCurve = if bn < startBar then Double.NaN else a * Power(x, 2) + b * x + c;
답변 1
예스스탁
예스스탁 답변
2022-06-29 14:07:45
안녕하세요
예스스탁입니다.
올려주신 내용은 전반적인 내용파악이 어려워 변환이 가능하지 않습니다.
도움을 드리지 못해 죄송합니다.
즐거운 하루되세요
> 오이도인 님이 쓴 글입니다.
> 제목 : 수식 변환 문의
> 수고 하십니다.
아래 식 변환 부탁드립니다.
수고하세요...
#########################
input length = 5;
def n = length;
def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def x = bn;
def y = close;
# calculate summation values
def startBar = lastBar - (n - 1);
def sumX = if bn < startBar then 0 else x + sumX[1];
def sumY = if bn < startBar then 0 else y + sumY[1];
def sumX2 = if bn < startBar then 0 else Power(x, 2) + sumX2[1];
def sumX3 = if bn < startBar then 0 else Power(x, 3) + sumX3[1];
def sumX4 = if bn < startBar then 0 else Power(x, 4) + sumX4[1];
def sumXY = if bn < startBar then 0 else x * y + sumXY[1];
def sumX2Y = if bn < startBar then 0 else Power(x, 2) * y + sumX2Y[1];
# intermediary calculations
def xx = sumX2 - Power(sumX, 2) / n;
def xy = sumXY - (sumX * sumY / n);
def xx2 = sumX3 - (sumX2 * sumX / n);
def x2y = sumX2Y - (sumX2 * sumY / n);
def x2x2 = sumX4 - (Power(sumX2, 2) / n);
# calculate coefficients
def a0 = (x2y * xx - xy * xx2) / (xx * x2x2 - Power(xx2, 2));
def b0 = (xy * x2x2 - x2y * xx2) / (xx * x2x2 - Power(xx2, 2));
def c0 = sumY / n - b0 * sumX / n - a0 * sumX2 / n;
# for a, b, and c use the final value on the last bar of the chart for all calculations
def a = GetValue(a0, bn - lastBar);
def b = GetValue(b0, bn - lastBar);
def c = GetValue(c0, bn - lastBar);
# calculate and plot
plot theCurve = if bn < startBar then Double.NaN else a * Power(x, 2) + b * x + c;