Hi 小幫手,
謝謝你的回覆,
我依你的作法, 修改我的程式, 但數值仍然不一樣, 我不知那裡有錯 ~
以 2457, 6/19 為例, 其 UB 值為 85.57,
但 我的程式, 在 6/19 13:25 的值卻是 86.1
另建一個涵式 xf_ATR(),
//============================
SetBarMode(1);
{
傳回平均真實區間
Length: 計算期數
}
input: Length(numeric);
value1 = 0;
for value2 = 0 to Length begin
value1 += maxlist((getfield("High", "D")[value2] - getfield("Low", "D")[value2]), absvalue(getfield("High", "D")[value2] - getfield("Close", "D")[value2 + 1]), absvalue(getfield("Low", "D")[value2] - getfield("Close", "D")[value2 + 1]));
end;
xf_ATR = round(value1/Length,2);
//============================
var: Length(20), UpperBand(2), LowerBand(2);
var: UB(0),LB(0),midline(0);
midline = xf_XAverage("D",GetField("Close","D"),Length);
UB = midline + xf_ATR(Length) * UpperBand;
LB = midline - xf_ATR(Length) * LowerBand;
Print(File("d:\Print\[Date]_[ScriptName]_[Symbol]_[Freq]_.log"), date, time, symbol, symbolname, close, round(midline,2), round(UB,2));
ret=1;
5 評論