目前語法如下,但想增加附加條件
1.5MA穿20MA時進場但價格必須高於200MA(交易中心執行頻率我是選擇5分鐘)
2.請問目前下面的設定假如當價格超過成本價1000點,是用1000點回檔150%才會出場嗎?謝謝
{
多單移動停損(點)
設定停損點, 跟停利點(如果不設定停利的話請把profit_point設定成0)
價格碰觸到停損/停利點時出場
如果價格上漲時, 停損點會跟著上漲
}
input: profit_point(300, "停利(點)");
input: profit_drawback_percent(150, "停利回跌(%)");
input: loss_point(80, "停損(點)");
var: long_condition(false); { 進場買進作多 }
{
範例:
均線穿越時買進1張
以成交價為基礎, 設定固定停利以及移動停損
}
if loss_point = 0 then raiseruntimeerror("請設定停損(點)");
long_condition = Average(Close, 5) cross over Average(Close, 20);
if Position = 0 and long_condition then begin
SetPosition(1); { 買進1張 }
end;
if Position = 1 and Filled = 1 then begin
{ 依照成本價格設定停損/停利 }
var: intrabarpersist stoploss_point(0);
{ 計算停損價格 }
if stoploss_point = 0 then begin
stoploss_point = FilledAvgPrice - loss_point;
end;
{ 如果價格上漲的話, 則往上挪動停損價格. 停損價格只會越來越高 }
if Close > FilledAvgPrice then begin
if Close - loss_point > stoploss_point then begin
stoploss_point = Close - loss_point;
end;
end;
if profit_point > 0 and Close >= FilledAvgPrice + profit_point then begin
{ 停利 }
SetPosition(0);
stoploss_point = 0;
end else if Close <= stoploss_point then begin
{ 停損 }
SetPosition(0);
stoploss_point = 0;
end;
end;
2 評論