自訂函數 tset,程式碼如下
input: i(numericref),j(numericref),n(numericref);
variable: EMAPeriod(8);
i=0;
if close < EMA(Close, EMAPeriod) then i=1;
j = EMA(Close, EMAPeriod);
n = close;
==========================
自訂指標,程式碼如下
variable: EMAPeriod(8),i(0),j(0),n(0);
test(i,j,n);
plot1(i,"close<EMA8");
plot2(j,"EMA8");
plot3(n,"收盤價");
=======================
變數j的值沒錯,如下圖

但是另一個自訂函數及指標,卻出現錯誤,不知原因為何?
自訂函數AAA,程式碼如下
input: TV(numericref),_BuyOPValue(numericref),EMA8(numericref);
variable: EMAPeriod(8);
EMA8 = EMA(Close, EMAPeriod);
if TV = 2 then
begin
if Close < EMA8 then
begin
_BuyOPValue = 1;
end
else _BuyOPValue = -1;
end;
====================================================
自訂指標,程式碼如下
variable: TV(0), _BuyOPValue(0), EMA8(0);
variable: TowerLength(4), TowerValue(0);
variable: i(0);
variable: EMAPeriod(8);
Tower(Close, TowerLength, TowerValue);
if TowerValue = 1 then
begin
TV = 2;
AAA(TV, _BuyOPValue, EMA8);
plot1(_BuyOPValue);
plot2(EMA8,"EMA8");
end;
===========================================
自訂函數Tower,程式碼如下
input: price(numericseries), TowerLength(numericsimple);
input: TowerValue(numericref);
variable: _Index(0), HV(0), LV(0), i(0);
TowerValue = 0;
HV = High[1];
LV = Low[1];
for _Index = 2 to TowerLength
begin
if HV <= High[_Index] then HV = High[_Index];
if LV >= Low[_Index] then LV = Low[_Index];
end;
if Close >= HV then TowerValue = 1
else if Close <= LV then TowerValue = -1;
if TowerValue = 0 then
begin
i = 1;
while i < 100000
Begin
if TowerValue[i] <> 0 then Break;
i = i + 1;
End;
TowerValue = TowerValue[i];
end;
===================================================
結果EMA8的值有錯誤



3 評論