月線布林通道

  •   210 
  • 最後發表   dammlin  2023 九月 07
dammlin 發文於   2023/08/27

 請問一下高手

這是選股的腳本

//抓本月成交量

CurrentMVolume=xf_GetValue("M",GetField("成交量","M"),0);

//計算18個月的布林
For k=0 to 18
begin Sum18MClose=Sum18MClose+CloseM(k);     
end;
Average18MPrice=Sum18MClose/18;
For mm=0 to 17
Begin SumSquare=(CloseM(mm)-Average18MPrice)*(CloseM(mm)-Average18MPrice);
end;
Xigma=squareRoot(sumSquare/17);

 

//布林設定
BbandUp[1] = Average18MPrice+XigmaBand*Xigma;
BbandUp[2] = (BbandUp[1]+BbandUp[3])/2;
BbandUp[3]= Average18MPrice-XigmaBand*Xigma;
bbandwidth=100*(BbandUp[1] +BbandUp[3])/BbandUp[2];

 

好像抓出來的月成交量跟Xigma值會不斷累加阿~~

哪裡有問提咧??謝謝大大

XQ小幫手 發文於   2023/09/07

Hello dammlin,

 

您的變數如 Sum18MClose 之類的都沒有在for迴圈前重置,所以每經過一根Bar都會持續累加上去。

簡單來說,第一根Bar計算時累加了近19根Bar的資料,第二根Bar運算時又多加上了19根Bar的資料。

 

要抓取本月的成交量,直接使用 Getfield("Volume", "M") 即可, xf_getvalue 是給變數跨頻率時使用的 (因為變數會跟著執行頻率)。

要計算布林通道可以使用系統內建的函數 BollingerBand,若您對如何撰寫有興趣,可以在XS編輯器裡找到該函數腳本。

發表回覆
Close