您好,試了很多次還是不符預期,請幫忙指點,謝謝
我要抓所有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);
2 評論