input:stop_profit(3,"停利點");
input:stop_loss(8,"停損點");
var:pl(0); //損益
settotalBar(1);
if Filled>0 and position>0 then begin //做多部位
pl = (Close - FilledAvgPrice); //做多計算損益(%)
if pl>= stop_profit then setposition(0,market,label:="停利出場")
else if ((-1*pl)>=stop_loss) then setposition(0,market,label:="停損出場");
end
else if Filled<0 and position<0 then begin //做空部位
pl = (FilledAvgPrice - Close); //做空計算損益(%)
if pl>= stop_profit then setposition(0,market,label:="停利出場")
else if ((-1*pl)>=stop_loss) then setposition(0,market,label:="停損出場");
end;
4 評論