台指停損出場的寫法

  •   558 
  • 最後發表   SHIH0408  2022 九月 16
SHIH0408 發文於   2022/09/09

各位先進、小幫手好:

想寫一個台指是突破某個價位使用智慧單送出建立部位,然後在建立部位前利用自動交易幫忙把關,一旦部位成立就會幫忙守停損以及停利,舉例來說:如果我預設智慧單在突破15000點時買進,然後程式就馬上幫忙交易庫存內的這個部位(先假設漲10點獲利出場,跌10點停損出場這樣,以下腳本是否可行(逐筆洗價)。

{ 多單停損(點)}

 

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

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

 

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

{ 依照成本價格設定停損/停利 }

 

if profit_point > 0 and Close >= FilledAvgPrice + profit_point then begin

{ 停利 }

SetPosition(0);

end else if loss_point > 0 and Close <= FilledAvgPrice - loss_point then begin

{ 停損 }

SetPosition(0);

end;

end;

 

{ 空單停損(點)}

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

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

 

 

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

{ 依照成本價格設定停損/停利: 請注意當作空時, 判斷是否獲利的方向要改變 }

 

if profit_pointR > 0 and Close <= FilledAvgPrice - profit_pointR then begin

{ 停利 }

SetPosition(0);

end else if loss_pointR > 0 and Close >= FilledAvgPrice + loss_pointR then begin

{ 停損 }

SetPosition(0);

end;

end;

 

排序方式: 標準 | 最新
musashi 發文於   2022/09/09

你的出場看起來沒問題,進場其實也可以寫進去,以下進場給你參考

{進場}
input: price_over(15000, "突破價");
input: price_under(14000, "跌破價");

if Position =0 and Filled = 0
then begin
    if close[1]<=price_over and close>price_over //由下往上穿越15000
    then begin
        SetPosition(1);//多單
    end else 
    if  close[1]>=price_under and close<price_under//由上往下穿越15000
    then begin
        SetPosition(-1);//空單
    end;
end;

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

Hello SHIH0408,

 

小幫手補充,XS編輯器裡的內建交易腳本有各種不同的下單出場方式,您可以參考看看。

感謝 musashi 的熱心回覆。

發表回覆
Close