自動選股

  •   227 
  • 最後發表   tradeNew  2022 三月 30
tradeNew 發文於   2022/03/25

這是我的函數庫 目前使用他來判斷做自動交易買賣的均線,然後我想應用在選股

input:thePrice(numericseries); //"價格序列"

input:Length(Numeric);   //"計算期間"

input:multiP(numericsimple); //權重

 

variable:  Factor(0);

 

if length + 1 = 0 and multiP=2 then Factor = 1 else if multiP=2 then Factor = 2 / (Length + 1);

if length + 1 = 0 and multiP=1 then Factor = 1 else if multiP=1 then Factor = 1 / Length;

 

if CurrentBar = 1 then

EMA_m = thePrice

else if CurrentBar <= Length then

    EMA_m = (thePrice + (EMA_m[1]*(CurrentBar-1)))/CurrentBar

else

EMA_m = EMA_m[1] + Factor * (thePrice - EMA_m[1]);

 

 

這個是選股條件,為什麼都跑不出來呢? 執行後都無法跑出? 謝謝幫手!

 

if close >= EmaWeight("D",close, 23, 1) then ret = 1;

XQ小幫手 發文於   2022/03/30

Hello tradeNew,

 

您上面附的函數腳本,函數名稱應該叫做 EMA_m ,但您在選股條件裡卻是呼叫 EmaWeight。

另外,EMA這個技術指標運算時會需要大量的前期值,所以您需要在選股腳本或選股策略設定足夠的資料讀取筆數讓其運算才能得出正確的數值。

就您的例子,應該要 settotalbar(23 * 6) 筆資料來計算。

發表回覆
Close