MACD選股結果不符

  •   241 
  • 最後發表   兔兔  2022 四月 14
兔兔 發文於   2022/04/08

您好,試了很多次還是不符預期,請幫忙指點,謝謝

我要抓所有DIF小於0的,再新增3個欄位

(1.昨天DIF為正數,今天DIF為負者;

   2.今日OSC是正數且比昨天短;

   3.今日K棒有碰到布林下軌)

測試結果:一直會有抓到DIF是正數的;且第二個欄位顯示不出來(有一欄名為”欄位“的,沒有任何值);還有PRINT也在執行看不到東西

// MACD指標

input: FastLength(12), SlowLength(26), MACDLength(9);

variable: difValue(0), macdValue(0), oscValue(0);

SetTotalBar((maxlist(FastLength,SlowLength,6) + MACDLength) * 4);

MACD(weightedclose(), 12, 26, 9, difValue, macdValue, oscValue); //CALL XQ寫好的MACD函數

 

CONdition5= close > average(close,20);                //close收盤價大於20日均線

CONdition14= close < average(close,20);                //close收盤價小於20日均線

condition6=difValue >=0 and macdValue>=0;//MACD雙線上0軸~趨勢偏多

condition7=difValue < 0 and macdValue< 0;//MACD雙線下0軸~趨勢偏空

condition8 = oscValue[0] >= 0 ;//MACD紅柱~強度偏強

condition9 = oscValue[0] < 0 ; //MACD綠柱~強度偏弱

CONdition10= difValue[0] cross Over macdValue;        //DIF線(快)金叉MACD(慢)瞬間~轉紅柱瞬間

CONdition11= difValue[0] cross under macdValue;   //DIF線(快)死叉MACD(慢)瞬間~轉綠柱瞬間

CONdition12= oscValue[0] > oscValue[1];   //當日紅柱比昨日紅柱長或當日綠柱比昨天綠柱短

CONdition15= oscValue[0] < oscValue[1];   //當日紅柱比昨日紅柱短或當日綠柱比昨天綠柱長

condition16= difValue[0] < 0 ;

 

// 布林通道超賣訊號

Input: LengthB(20), LowerBand(2);

SetInputName(1, "期數");

SetInputName(2, "通道下緣");

settotalbar(3);

condition17 = GetField("Low", "D") <= bollingerband(Close, LengthB, -1 * LowerBand) ;

condition18 = bollingerband(Close, LengthB, -1 * LowerBand) <= GetField("high", "D");

 

if difValue[0] < 0  then  ret=1; 

//新增3個欄位

if difValue[0] < 0 and difValue[1] > 0  then outputfield(1,difValue[0],2, "剛轉空"); 

if (condition16 and  condition8 and CONdition15) then outputfield(3,oscValue[0],2, "空縮");  

if (condition16 and  CONdition17 and CONdition18) then outputfield(4,bollingerband(Close, LengthB, -1 * LowerBand),2, "下軌");  

 

 Print("Date=", Date, "Close=", Close, "Value1", difValue[0], "osd",oscValue);

 

排序方式: 標準 | 最新
KYT 發文於   2022/04/09

setbarfreq("D");

settotalbar(70);

variable:difValue(0), macdValue(0), oscValue(0);

macd(weightedclose,12,26,9,difvalue,macdValue,oscValue);

condition1=difValue[0] < 0 and difValue[1] > 0;

condition2=difValue[0] < 0 and oscValue[0] >= 0 and oscValue[0] < oscValue[1];

variable:bollValue(0);

bollValue=bollingerband(c,20,-2);

condition3=c crosses below bollValue;

if (condition1 or condition2) and condition3 then ret=1;

outputfield(1,difValue[0], "剛轉空"); 

outputfield(3,oscValue[0], "空縮"); 

 outputfield(4,bollingerband(bollValue-Close, "下軌");

XQ小幫手 發文於   2022/04/14

Hello 兔兔,

 

outputfield如果包在 if 裡面的話就會出現這種狀況。

建議您如果要讓輸出的數值有所不同的話,可以考慮像是:

if (condition16 and  condition8 and CONdition15) then outputfield(3,oscValue[0],2, "空縮") else outputfield(3, 0, "空縮");  

這種方式,確保outputfield會輸出數值。

小幫手這邊看篩選出來的商品都是dif小於0的商品,不知道您是哪一日什麼商品出現了dif大於0的狀況,麻煩告知讓小幫手檢驗。

至於print的部分,您需要把右上角的print功能打開才行。(參考附圖)

 

感謝 KYT 的熱心回覆。

附加文件

發表回覆
Close