多個進出場點判斷方法

  •   440 
  • 最後發表   Alex嘉  2024 三月 13
Alex嘉 發文於   2024/03/04

想請教一下
我想要寫多個條件去偵測進場點和出場點是怎麼寫呢?

比如 我要設定進場是
1. close 大於 MA100 就進場 空

2.macd>0 就進場 多

3.close到布林上通道就進場 多
4.close 小於 MA20 就做空

出場是

1. close >200MA 出場

2.close cross below bb 出場

3.close <200MA and close>150MA 停利出場

4.close <100MA and close >130mA 停利出場

 

想要讓程式 判斷 做多,由最上面賺最多的判斷下來,讓波段長一點,但怎麼都寫都不會出場,要不然就是出場會變成都是賺最少的呢?

 

if close cross over bbup  then setposition(1,label:="多");
if MACDss>0  then setposition(1,label:="多");
if close > M100  then setposition(-1,label:="空");
if clsoe < m20 then setposition(-1,label:="空");


if position=1 and close>MA210   then setposition(0);
if position=1 and close cross below bbmin then setposition(0);
if position=1 and close<M200 and clsoe>150M then setposition(0);
if position=1 and close<M100 and close>130M then setposition(0);

 

我用過 上面這樣的IF,也用過IF...else...end, 
但好像沒辦法寫出我想要的,我有看過 IF / THEN / ELS 的說明

但好像還是無法,想請問 如果想要多用的判斷式來進場和出場怎寫呢?

比如說: 有6條均線,突破最上面的停利出場,一路判斷下來到停損。

 

  • 按讚來自於
  • johnlintw
排序方式: 標準 | 最新
XS小編 發文於   2024/03/07

 Hello Alex嘉,

 

小編建議您先閱覽網站上的教學區教學影片,裡面有XS語法的基礎和應用可以閱覽。

 

當腳本中同時有多個 setposition 觸發時,只會執行第一個運算到的。

出場的部分的腳本條件都為position=1,但上面進場的部分有空方進場,也就是空方進場時腳本就不會平倉,除非觸發多方進場。

 

假設您要依造順序,由1最先執行排序到4,且要平倉後才能夠再進場的話,可以這樣寫:

condition1 = close > M100;

condition2 = MACDss>0;

condition3 = close cross over bbup;

condition4 = clsoe < m20;

 

condition5 = close>MA210;

condition6 = close cross below bbmin;

condition7 = close<M200 and clsoe>150M;

condition8 = close<M100 and close>130M;

 

if position = 0 and filled = 0 then begin

    if condition1 then setposition(-1)     //先判斷condition1 (空方)

    else if condition2 or condition3 then setposition(1)    //再判斷condition2 和 condition3 (多方)

    else if condition4 then setposition(-1);    //最後才判斷condition4 (空方)

    end;

 

if position <> 0 and filled <> 0 and (condition5 or condition6 or condition7 or condition8) then setposition(0);

 

請注意由於出場部分都是平倉,所以只要觸發任一個就會平倉。

若不希望如此而是要搭配的話 (ex. condition1 進場的話則只用 condition5 出場),那麼在撰寫時就需要另外用變數來記錄控制。

Alex嘉 發文於   2024/03/10

謝謝 小編,清楚了。

另外請問一下  指標撰寫,寫入以下的 卻不會進場且沒有標示出來呢?

v200=average(c,200);

Outp=30;

if  MKP = 0 and c > v200                   

then  begin   

 

MKP = 1;

        BC=c;

end;

if MKP=1 and C < Outp 

 

then MKP=0; 

 

if MKP[1]=0 and MKP=1 then  plot12 (C, "進場多"); //一開始沒部位 但現在有部位就紀錄

if MKP=1 then 

begin

plot14(BC , "買入價格:");

 

end;

if MKP[1]=1 and MKP=0 then 

 

begin

                plot14(BC , "買入價格:");

plot16(C , "出場價:");

plot18((C - BC) , "損益額");

 

 

end;

 

XS小編 發文於   2024/03/13

Hello Alex嘉,

 

小編建議您可以將相關數值先畫出,比較容易找出問題原因。

另外請注意您的出場條件是 MKP=1 and C < Outp,而 Outp 是固定值30,也就是說,只要上面進場條件一符合但價格在30以下的話,一符合就馬上會被改回來。

若還是有問題的話,麻煩附上完整的腳本並告知使用的商品和頻率讓小編確認。

發表回覆
Close