close

http://www.yctseng.net/2011/11/blog-post_5852.html

2011年11月28日

帶成交量的均線於 16:45

 
因為朋友提問,要計算每一根K棒裡面把成交量的作為價格權重的均線,雖然印象中我以前有分享過,不過...連我自己都找不到,乾脆就寫一個放上來。

先做成函數,未來取用都方便。

0

函數的程式碼(MultiCharts)內容:
   input:Price(Numeric),length(Numeric);
   Var:step(0),AllPV(1),AllVol(1),BarVol(1);

   AllPV=0;
   AllVol=0;
   BarVol=Ticks;
 
   for step=0 to length begin
     AllPV = Price[step]*BarVol[step] + AllPV;
     AllVol = Ticks[step] + AllVol;
   end;

   if BarNumber > length then
     _MAwithVol=AllPV/AllVol;

做成指標:
1

指標的程式碼(MultiCharts)內容:
   input:length(10);

   Value1= _MAwithVol(C,length);

   plot1(Value1,"VolMA");
 

HTS版的函數程式碼:
 
     Param:Price(Numeric),length(Numeric);
     Var:i(0),AllPV(1),AllVol(1);

     AllPV=0;
     AllVol=0;
 
     for i=0 to length 
       AllPV = Price[i]*V[i] + AllPV;
       AllVol = V[i] + AllVol;
     end for

     if BarNumber > length then
       _MAwithVol=AllPV/AllVol;
     end if

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 QQ 的頭像
    QQ

    w28822的部落格

    QQ 發表在 痞客邦 留言(0) 人氣()