編譯成功,回測無數據

  •   175 
  • 最後發表   Eric369  2024 六月 25
Eric369 發文於   2024/06/24

// 定義參數

input: volumePercentThreshold(5, "主力持股百分比"); 

input: jumpOpenPercent(3, "開盤跳空高開百分比"); 

input: priceDropPercent(2, "進場放空的股價下跌百分比"); 

input: priceRallyPercent(2, "回補出場的股價急拉百分比"); 

input: forcedCoverTime(132000, "強制平倉時間"); 

 

variable: shortEntryPrice(0), shortExitPrice(0), shortEntryDate(0);

variable: initialCapital(1000000), currentCapital(1000000); 

variable: isHighVolume(false), isJumpOpen(false), isShortPosition(false), isCoverSignal(false);

variable: prevVolume(0), currentVolume(0);

 

if date > 1 then begin

    variable: prevClose(0);

    prevClose = getfield("close", "D")[1];

    prevVolume = getfield("volume", "D")[1];

 

    isHighVolume = (prevVolume / getfield("volume", "D")[1]) * 100 >= volumePercentThreshold;

end;

 

variable: currentTradeDate(CurrentDate), marketTime(CurrentTime);

 

variable: marketHour(marketTime / 100), marketMinute(marketTime - (marketHour * 100));

variable: currentMarketTime(NumToStr(marketHour, 2) + ":" + NumToStr(marketMinute, 2));

 

isJumpOpen = ((open / getfield("close", "D")[1]) - 1) * 100 >= jumpOpenPercent;

 

if marketTime >= 090000 and marketTime <= 100000 and isHighVolume and isJumpOpen then begin

    if ((close / open) - 1) * 100 <= (-priceDropPercent) then begin 

        isShortPosition = true;

        shortEntryPrice = close;

        shortEntryDate = currentTradeDate;

        // 記錄進場動作

        print("Short at ", close, " on ", shortEntryDate);

    end;

end;

if isShortPosition then begin

    isCoverSignal = ((close / shortEntryPrice) - 1) * 100 >= priceRallyPercent;

    

    if isCoverSignal then begin

        shortExitPrice = close;

        isShortPosition = false; 

        currentCapital = currentCapital + (shortEntryPrice - shortExitPrice) * 1000; 

 

        print("Cover at ", close, " on ", currentTradeDate, ". Profit: ", shortEntryPrice - shortExitPrice);

        print("Current Capital: ", currentCapital);

    end;

end;

 

if isShortPosition and marketTime >= forcedCoverTime then begin

    shortExitPrice = close;

    isShortPosition = false; 

    currentCapital = currentCapital + (shortEntryPrice - shortExitPrice) * 1000;

 

    print("Force Cover at ", close, " on ", currentTradeDate, ". Profit: ", shortEntryPrice - shortExitPrice);

    print("Current Capital: ", currentCapital);

end;

print("Date: ", currentTradeDate, " - Current Capital: ", currentCapital);


請問以上腳本在編譯時是成功的回測卻無數據,請問是哪個地方有問題導致回測不到數據。

排序方式: 標準 | 最新
虎科大許教授 發文於   2024/06/24

沒有ret=1或setposition等執行交易的指令。

Eric369 發文於   2024/06/25

謝謝教授,我已得到解答。謝謝您

發表回覆
Close