求指導如何寫停利停損

  •   340 
  • 最後發表   miru_pa  2021 十一月 17
miru_pa 發文於   2021/11/16

//value2 = RSV, value3 = K, value4 = D

value1 = Stochastic(9,3,3,value2,value3,value4);

 

// K, D 都大於70且KD死叉

if value3 > 70 and value4 > 70 and value3 cross over value4 

 

then setposition(-1);

//停損停利

input: profit_point(10, "停利(點)");

input: loss_point(10, "停損(點)");

 

if Position = -1 and Filled = -1 then begin;

 

if profit_point < 15 then begin;

 

SetPosition(0);

end else if loss_point  > 18 and Close >= FilledAvgPrice + loss_point then begin;

 

SetPosition(0);

 

剛入門,寫一個台指期空單策略,想寫成:

停利:成本價-15就停利

停損:收盤價>成本價+18就市價停損

我按編譯會說最後一行有少東西

但如果只有這樣就編譯完成

//value2 = RSV, value3 = K, value4 = D

value1 = Stochastic(9,3,3,value2,value3,value4);

//停損停利

input: profit_point(10, "停利(點)");

input: loss_point(10, "停損(點)");

// K, D 都大於70且KD死叉

if value3 > 70 and value4 > 70 and value3 cross over value4 

 

then setposition(-1);

 

不知道哪裡出問題,求指導,非常感謝!!

XQ小幫手 發文於   2021/11/17

Hello miru_pa,

 

您下半部的腳本之所以會錯誤是因為您有了begin但沒有end,且begin後又加了分號所導致。

建議可以參考官網的教學區,裡面有XS語法的基礎與應用。

停利停損的部分應該這樣寫:

input: profit_point(10, "停利(點)");

input: loss_point(10, "停損(點)");

 

if Position = -1 and Filled = -1 then begin

    if close >= (filledavgprice + loss_point) then setposition(0);   //如果收盤價大於進場價格+停損點數就出場

    if close <= (filledavgprice - profit_point) then setposition(0);  //如果收盤價小於進場價格-停利點數就出場

    end;

討論區裡也有其他關於停損停利的文章。

發表回覆
Close