Xs腳本求助

  •   267 
  • 最後發表   qwer0203  2024 十一月 25
qwer0203 發文於   2024/11/18

想寫一個策略與量積木一樣的邏輯

盤中符合全部條件

執行時段為9點30分到12點整

最新價<當日均價線0%以上

成交量>= 2000張

長上影線,上影線幅度超過2%

連續3分鐘大戶持續賣超

目前腳本寫成

{@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 

    ret = 1;

 

回測不來與量化積木不太一樣

同一檔標的會重複進場

 

附加文件

XS小編 發文於   2024/11/25

Hello qwer0203,

 

可參考小編在 腳本問題 中的回覆。

另外回測時盤中條件是1分鐘頻率,盤後條件是日頻率,皆為非逐筆洗價。

同一日會重複進場是回測的設定 (最大同時進場次數)。

 

if ... then condition = True;

這種寫法會讓condition 變成True後就維持在True。

應該是:

if ... then condition = True else condition = False;

condition = ...;

 

建議您先觀看網站上的教學區教學影片,裡面有XS語法的基礎和應用可以閱覽。

在了解回測是怎麼運作後比較容易設定。

發表回覆
Close