input: profit_percent(3, "停利(%)");
input: profit_drawback_percent(1.5, "停利回跌(%)");
input: loss_percent(1, "停損(%)");
中間略過...
if condition1 and condition2 and condition3 and condition4
then setposition(-1, market);
if profit_percent = 0 then raiseruntimeerror("請設定停利(%)");
if profit_drawback_percent = 0 then raiseruntimeerror("請設定停利回跌(%)");
if profit_drawback_percent > profit_percent then raiseruntimeerror("停利(點)需大於停利回跌(%)");
if Position = -1 and Filled = -1 then begin
var: intrabarpersist max_profit_percent(0);{ 啟動停利後最大獲利% }
if loss_percent < 0 and Close >= FilledAvgPrice * (1 + (loss_percent / 100)) then begin
{ 停損 }
SetPosition(0);
max_profit_percent = 0;
end else begin
{ 判斷是否要啟動停利 }
if max_profit_percent = 0 and Close <= FilledAvgPrice - profit_percent then begin
max_profit_percent = Close;
end;
if max_profit_percent <> 0 then begin
if Close >= max_profit_percent + profit_drawback_percent then begin
{ 停利 }
SetPosition(0);
max_profit_percent = 0;
end else if Close < max_profit_percent then begin
{ 移動最大獲利點 }
max_profit_percent = Close;
if (position < 0 and close >= getfield("漲停價", "D") * 0.99) or
(position < 0 and close <= getfield("跌停價", "D") *1.01) or (position < 0 and currenttime >= 132000) then setposition(0, market);
end;
end;
end;
end;
不知哪裡沒寫好?
3 評論