使用選股腳本,挑選出MACD全部的數值都在0軸以上的語法。

  •   832 
  • 最後發表   XQ小幫手  2017 二月 21
XQ小幫手 發文於   2016/12/20

使用選股腳本,挑選出MACD全部的數值都在0軸以上的語法,

範例程式碼選股腳本如下:

input: FastLength(12), SlowLength(26), MACDLength(9);
variable: difValue(0), macdValue(0), oscValue(0);

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

SetInputName(1, "DIF短期期數");
SetInputName(2, "DIF長期期數");
SetInputName(3, "MACD期數");

MACD(weightedclose(), FastLength, SlowLength, MACDLength, difValue, macdValue, oscValue);

Ret = oscValue > 0 and difValue > 0 and macdValue> 0;

 

有任何問題歡迎詢問小幫手,謝謝。

 

Jack 發文於   2017/02/21

藍靖兄 你好:

 

使用選股腳本撰寫 MACD 0軸以上持續60天以上or 60天以下的語法,如下

 

大致邏輯:

1. 基本上與XQ小幫手撰寫的範例腳本一樣

2. 加入 TrueAll 函數挑選出 MACD 0軸以上持續60天以上or 60天以下 的個股

3. 在報表上標註 那些個股0軸以上、那些個股0軸以下 

 

程式碼範例如下:

input: FastLength(12), SlowLength(26), MACDLength(9), Length_(60,"持續N天");
variable: difValue(0), macdValue(0), oscValue(0);

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

SetInputName(1, "DIF短期期數");
SetInputName(2, "DIF長期期數");
SetInputName(3, "MACD期數");

MACD(weightedclose(), FastLength, SlowLength, MACDLength, difValue, macdValue, oscValue);

if TrueAll(macdValue>=0,Length_) and close[Length_] > 0 then begin 
    ret = 1;
    outputfield1(text("符合"),"MACD 0軸以上持續60天");
end;

if TrueAll(macdValue<=0,Length_) and close[Length_] > 0 then begin
    ret = 1;
    outputfield2(text("符合"),"MACD 0軸以下持續60天");
end;

 

以上供參,有問題再詢問。

 

發表回覆
Close