您好,我想選股找出最近五日有同時出現KD與MACD黃金交叉,以下是我的編碼,
編譯的時候出現了for i = 0 to 4 begin的i宣告錯誤,我該怎麼修改呢? 非常感謝
// 定義輸入參數
input: FastLength(12), SlowLength(26), MACDLength(9);
input: KLength(9), DLength(3), KDSmooth(3);
// 定義變量
variable: difValue(0), macdValue(0), oscValue(0);
variable: KValue(0), DValue(0);
variable: macdCrossRecent(false), kdCrossRecent(false);
// 設置數據回溯條數
SetTotalBar((maxlist(FastLength, SlowLength, 6) + MACDLength) * 4);
// 設置輸入參數名稱
SetInputName(1, "MACD快速週期");
SetInputName(2, "MACD慢速週期");
SetInputName(3, "MACD週期");
SetInputName(4, "KD週期");
SetInputName(5, "D值週期");
SetInputName(6, "KD平滑");
// 計算MACD值
MACD(weightedclose(), FastLength, SlowLength, MACDLength, difValue, macdValue, oscValue);
// 計算KD值
Stochastic(KLength, KDSmooth, DLength, KValue, DValue);
// 檢查最近五天內是否出現MACD黃金交叉
macdCrossRecent = false;
for i = 0 to 4 begin
if difValue[i] Crosses Above macdValue[i] then
macdCrossRecent = true;
end;
// 檢查最近五天內是否出現KD黃金交叉
kdCrossRecent = false;
for i = 0 to 4 begin
if KValue[i] Crosses Above DValue[i] then
kdCrossRecent = true;
end;
// 合併所有條件
Condition99 = macdCrossRecent and kdCrossRecent;
// 篩選
if Condition99 then Ret = 1;
else Ret = 0;
 
 
             
        
         
         
         
     
     分類
    分類
 
            
3 評論