請問如何改成一次下單兩口或者三口

  •   128 
  • 最後發表   swer  2022 一月 12
swer 發文於   2022/01/07

 

{

多單移動停損(點)

 

設定停損點, 跟停利點(如果不設定停利的話請把profit_point設定成0)

價格碰觸到停損/停利點時出場

如果價格上漲時, 停損點會跟著上漲

}

 

input: profit_point(0, "停利(點)");

input: loss_point(100, "停損(點)");

 

var: long_condition(false); { 進場買進作多 }

 

範例:

 

均線穿越時買進1張

以成交價為基礎, 設定固定停利以及移動停損

}

 

if loss_point = 0 then raiseruntimeerror("請設定停損(點)");

 

long_condition = Average(Close,10) 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;

 

 

 

排序方式: 標準 | 最新
swer 發文於   2022/01/07

SetPosition(1)  改成2 或者3 這樣嗎?

swer 發文於   2022/01/10

這是移動損 下面也得改嗎? 改的話 改哪裡 ?? 新手抱歉

XQ小幫手 發文於   2022/01/12

 Hello swer,

 

小幫手建議您可以先了解 position, filled, setposition 此3個函數。

 

SetPosition(2);

這樣代表的是把部位(position)設為2,若您原本的庫存(filled)為0的話,就會下買進2張的委託單。

 

if Position = 1 and Filled = 1 then begin

這是代表當部位和庫存為1的話,就繼續執行 begin ... end 裡的腳本。

所以若您改為買2口的話,這段就應該改為

if Position = 2 and Filled = 2 then begin

或是只要是有多方部位庫存的話:

if Position > 0 and Filled > 0 then begin

 

感謝 任任任 的熱心回覆。

發表回覆
Close