想請問如果想要(指標)裡面的修正移動平均線(如下)想要穿越布林指標的(中軌)(如下),並且寫成警示提醒,該怎麼寫, (指標)裡面的修正移動平均線如下

  •   164 
  • 最後發表   jam0209  2022 九月 27
jam0209 發文於   2022/09/13

想請問如果想要(指標)裡面的修正移動平均線(如下)想要穿越布林指標的(中軌)(如下),並且寫成警示提醒,該怎麼寫,

(指標)裡面的修正移動平均線如下

 

 

input:n(20,"計算期數");

variable: w(0);

 

if barfreq = "Tick" or barfreq = "Min" then

begin

value1=GetField("內盤量");//單位:元

value2=GetField("外盤量");//單位:元

end else begin

value1=GetField("內盤量","D");//單位:元

value2=GetField("外盤量","D");//單位:元

end;

 

//計算內外盤比

if value2<>0 then

value3=value1/value2*100

else

value3=100;

 

if close>close[1] then begin

if value3>130 then 

w=2.5

else if value3>120 then

w=2.2

else if value3>110 then

w=2.1

else if value3>100 then

w=1.9

else

w=1.8;

end else if value3<70 then 

w=2.5

else if value3<80 then 

w=2.2

else if value3<90 then 

w=2.1

else if value3<100 then 

w=1.9

else

w=1.8;

 

value4=(w/(n+1))*close+(n-1)/(n+1)*value4[1];

value5=average(close,n);

 

plot2(value5,"移動平均線");

 

 

 

 

布林指標的(中軌)(如下)

input:Length(40,"布林通道MA的天數"),

 

 UpperBand(3,"上通道標準差倍數"),

 

 LowerBand(3,"下通道標準差倍數"); 

 

 variable:mid(0),up(0),down(0);

 

 

 

 up = bollingerband(Close,Length,UpperBand) ; 

 

 mid = average(close,Length); 

 

 down = bollingerband(Close,Length,-1*LowerBand);

 

 

 

 plot1(up,"UB");

 

 plot2(mid,"BBandMA"); 

 

 plot3(down,"LB");

排序方式: 標準 | 最新
XQ小幫手 發文於   2022/09/20

Hello jam0209,

 

所以您的 value4 是修正移動平均線,然後要判斷如果其向上/向下突破布林中軌的話警示是嗎?

那麼您只要把計算value5的部分和計算中軌的部分合併起來,並加上條件即可。

舉例來說:

input:n(20,"計算期數");

variable: w(0);

 

if barfreq = "Tick" or barfreq = "Min" then begin

value1=GetField("內盤量");//單位:元

value2=GetField("外盤量");//單位:元

end else begin

value1=GetField("內盤量","D");//單位:元

value2=GetField("外盤量","D");//單位:元

end;

 

//計算內外盤比

if value2<>0 then

value3=value1/value2*100

else

value3=100;

 

if close>close[1] then begin

if value3>130 then 

w=2.5

else if value3>120 then

w=2.2

else if value3>110 then

w=2.1

else if value3>100 then

w=1.9

else

w=1.8;

end else if value3<70 then 

w=2.5

else if value3<80 then 

w=2.2

else if value3<90 then 

w=2.1

else if value3<100 then 

w=1.9

else

w=1.8;

 

value4=(w/(n+1))*close+(n-1)/(n+1)*value4[1];

 

input:Length(40,"布林通道MA的天數")

variable:mid(0);

 

mid = average(close,Length); 

 

condition1 = value4 cross over mid; //修正移動平均線向上穿越中軌

condition2 = value4 cross under mid;  //修正移動平均線向下穿越中軌

 

if condition1 or condition2 then ret = 1;  //兩者任一達成就警示

jam0209 發文於   2022/09/21

謝謝小編回復,想請問您得腳本之間再編一時出現(在 "variable" 之前可能少了",", ";"。),請問該如何改

 

Marcuz 發文於   2022/09/21

第83行 後面沒有加分號

你在編譯的時候下面錯誤訊息會提示你哪一行有問題

錯誤訊息寫85那妳可以將鄰近的程式碼看看是否少了分號

XQ小幫手 發文於   2022/09/27

Hello jam0209,

 

小幫手這一行漏了一個分號,只要加上就可以了。

input:Length(40,"布林通道MA的天數");

網站上有教學區,裡面有XS與法的基礎和應用可以閱覽。

 

感謝 Marcuz 的熱心回覆。

發表回覆
Close