
先做成函數,未來取用都方便。
MultiCharts版的函數(_MAwithVol)的程式碼內容:
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-1 begin
AllPV = Price[step]*BarVol[step] + AllPV;
AllVol = Ticks[step] + AllVol;
end;
if BarNumber > length then
_MAwithVol= AllPV / AllVol;
做成指標,指標的程式碼(MultiCharts)內容:
input:length(10);
Value1= _MAwithVol(C,length);
plot1(Value1,"VolMA");
HTS版的函數(_MAwithVol)程式碼:
Param:Price(Numeric),length(Numeric);
Var:i(0),AllPV(1),AllVol(1);
AllPV=0;
AllVol=0;
for i=0 to length-1
AllPV = Price[i]*V[i] + AllPV;
AllVol = V[i] + AllVol;
end for
if BarNumber > length then
_MAwithVol=AllPV/AllVol;
end if