請檢查腳本是否分母為0....

  •   138 
  • 最後發表   Edward Chou  2024 五月 03
Edward Chou 發文於   2024/05/03

請問要如何解決下列分母為0的方式?

 Inputs: FastLength_MACD(8), SlowLength_MACD(13), SignalLength_MACD(5);

Inputs: KDJLength(8), MA_Length(3);

Inputs: RSILength_short(5), RSILength_long(13);

Inputs: LWRLength(13), LWR2Length(3);

Inputs: MA1(3), MA2(5), MA3(8), MA4(13);

Inputs: MTMLength(12);

 

Vars: DIFF_MACD(0), DEA_MACD(0), MACD_Cross(False);

Vars: RSV1(0),K(0), D(0), KDJ_Cross(False);

Vars: Highest_high(0), Lowest_low(0), RSI_short(0), RSI_long(0), RSI_Cross(False);

Vars: LWR1(0), LWR2(0), LWR_Cross(False);

Vars: BBI(0), BBI_Cross(False);

Vars: MTM(0), MMS(0), MMM(0), MTM_Cross(False);

 

DIFF_MACD = XAverage(Close, FastLength_MACD) - XAverage(Close, SlowLength_MACD);

DEA_MACD = XAverage(DIFF_MACD, SignalLength_MACD);

 

 

if DIFF_MACD > DEA_MACD then

    MACD_Cross = True

else

    MACD_Cross = False;

 

 

RSV1 = (Close - Lowest(Low, KDJLength)) / (Highest(High, KDJLength) - Lowest(Low, KDJLength)) * 100;

K = XAverage(RSV1, MA_Length);

D = XAverage(K, MA_Length);

 

 

if K > D then

    KDJ_Cross = True

else 

    KDJ_Cross = False;

 

 

RSI_short = RSI(Close, RSILength_short);

RSI_long = RSI(Close, RSILength_long);

 

 

if RSI_short > RSI_long then

    RSI_Cross = True

else

    RSI_Cross = False;

 

 

LWR1 = XAverage((Highest_high - Close) / (Highest_high - Lowest_low) * 100, LWRLength);

LWR2 = XAverage(LWR1, LWR2Length);

 

 

if LWR1 > LWR2 then

    LWR_Cross = True

else

    LWR_Cross = False;

 

 

BBI = (XAverage(Close, MA1) + XAverage(Close, MA2) + XAverage(Close, MA3) + XAverage(Close, MA4)) / 4;

 

 

if Close > BBI then

    BBI_Cross = True

else

    BBI_Cross = False;

 

MTM = Close - Close[1];

MMS = 100 * XAverage(XAverage(MTM, 5), 3) / XAverage(XAverage(AbsValue(MTM), 5), 3);

MMM = 100 * XAverage(XAverage(MTM, 13), 8) / XAverage(XAverage(AbsValue(MTM), 13), 8);

 

 

 

if MMS > MMM then

    MTM_Cross = True

else

    MTM_Cross = False;

 

 

Plot1(MACD_Cross, "MACD_Cross");

Plot2(KDJ_Cross, "KDJ_Cross");

Plot3(RSI_Cross, "RSI_Cross");

Plot4(LWR_Cross, "LWR_Cross");

Plot5(BBI_Cross, "BBI_Cross");

Plot6(MTM_Cross, "MTM_Cross");

 

 

排序方式: 標準 | 最新
貓市 發文於   2024/05/03

可以檢查程式中有做除法的地方, 有沒有可能出現分母為0的狀況

可能出現分母為0的話, 補上 if XXX <> 0 then OOO=OOO/XXX; 

虎科大許教授 發文於   2024/05/03

LWR1 = XAverage((Highest_high - Close) / (Highest_high - Lowest_low) * 100, LWRLength);

這行裡面的Highest_high及Lowest_low沒有賦予數值,預設值是0,所以會有除以0的錯誤。

發表回覆
Close