我是想要寫出當自己手動進場後 腳本可以自己幫我停損
停損5趴當價格漲超過10趴後 則停損跟著一起往上移動
直到被停損掉 請問小幫手這樣哪邊有問題嗎
input: stop_per(5, "停損百分比"), trailing_per(10, "移動起始點");
var: stop_point(0), moving_point(0), controller(0);
if filled > 0 and position > 0 then begin
if controller = 0 then begin
stop_point = filledAvgPrice * (1 - (0.01 * stop_per)); //計算停損點
moving_point = filledAvgPrice * (1 + (0.01 * trailing_per)); //計算起始移動點
controller = 1;
end;
if close >= moving_point and (close * (1 - (0.01 * stop_per))) > stop_point then stop_point = (close * (1 - (0.01 * stop_per)))
// 如果價格大於起始移動點且新停損點大於舊停損點的話,更新停損點數值
else if close <= stop_point then begin
// 收盤價小於停損點就出場
setposition(0, market);
controller = 0;
print("out");
end;
print(date, time, close, filledAvgPrice, stop_point, moving_point);
end;
1 評論