各位先進、小幫手好:
想寫一個台指是突破某個價位使用智慧單送出建立部位,然後在建立部位前利用自動交易幫忙把關,一旦部位成立就會幫忙守停損以及停利,舉例來說:如果我預設智慧單在突破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;
2 評論