策略雷達如何回測

  •   294 
  • 最後發表   qwer0203  2024 十一月 17
qwer0203 發文於   2024/11/16

腳本已經編譯完成想要回測

但是回測不出東西

 

不知道哪裡出錯

 

{@type:strategy}

// 腳本類型: 策略

// 腳本名稱: 綜合條件策略

// 顯示名稱: 綜合條件策略

// 執行頻率: 1分(非逐筆洗價)

 

// ========== 參數定義 ==========

Input: priceDeviation(0), volumeLimit(2000), shadowThreshold(2), bigOrderSide(-1);

 

// ========== 變數定義 ==========

Var: priceCondition(false), volumeCondition(false), shadowCondition(false), bigOrderCondition(false), overallCondition(false);

 

// ========== 條件一:最新價小於均價線 ==========

SetTotalBar(2);

Var: lastPrice(0), averagePrice(0);

lastPrice = GetField("收盤價");

averagePrice = GetField("均價");

if lastPrice < averagePrice * (1 - (priceDeviation / 100)) then priceCondition = true;

 

// ========== 條件二:成交量大於等於2000張 ==========

SetTotalBar(1);

if GetField("成交量", "D")[0] >= volumeLimit then volumeCondition = true;

 

// ========== 條件三:長上影線判斷 ==========

SetBackBar(10, "D");

Var: highPrice(0), bodyReference(0);

highPrice = GetField("最高價", "D");

bodyReference = maxList(GetField("開盤價", "D"), GetField("收盤價", "D"));

if (highPrice - bodyReference) > GetField("收盤價", "D")[1] * shadowThreshold * 0.01 and 

   (GetField("開盤價", "D") - GetField("收盤價", "D")) < (highPrice - bodyReference) then shadowCondition = true;

 

// ========== 條件四:大戶持續賣超 ==========

SetTotalBar(3);

Var: orderSellVolume(0), orderBuyVolume(0), netBigOrders(0);

orderSellVolume = GetField("賣出特大單量") + GetField("賣出大單量");

orderBuyVolume = GetField("買進特大單量") + GetField("買進大單量");

netBigOrders = bigOrderSide * (orderBuyVolume - orderSellVolume);

if netBigOrders > 0 then bigOrderCondition = true;

 

// ========== 綜合條件判斷 ==========

overallCondition = priceCondition and volumeCondition and shadowCondition and bigOrderCondition;

 

if overallCondition then begin

    // 策略執行

    Print("策略觸發:所有條件同時成立!");

end;

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

(1)一個腳本裡面若有好幾個SetTotalBar,系統會選擇數值最大的那個為預設讀取資料筆數。

(2)我用台積電測試,20241016 124300就出現所有條件同時成立的情況。若你用貼上來的程式回測,由於沒有進出場,不會有回測結果。

qwer0203 發文於   2024/11/17

請問一下這個要如何更改因為我希望4個條件都成立下警示,當股價跌破當日均價且k線有上引線2%以上,成交量大於2000張

虎科大許教授 發文於   2024/11/17

警示腳本:if overallCondition then ret=1;

交易腳本:if overallCondition then setposition(1);

發表回覆
Close