關於逐筆交易

  •   225 
  • 最後發表   swer  2022 六月 16
swer 發文於   2022/06/07

{

多單移動停利(點)

 

設定停損點(如果不設定的話, 請把loss_point設定成0), 以及停利點, 跟回跌點數

價格下跌到停損時出場

價格上漲到停利點後啟動移動停利, 如果價格繼續上漲, 則繼續持有, 如果價格回檔超過回跌點數時, 則停利出場

}

 

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

input: profit_drawback_point(10, "停利回跌(點)");

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

 

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

 

範例:

 

均線穿越時買進1張

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

}

 

if profit_point = 0 then raiseruntimeerror("請設定停利(點)");

if profit_drawback_point = 0 then raiseruntimeerror("請設定停利回跌(點)");

if profit_drawback_point > profit_point then raiseruntimeerror("停利(點)需大於停利回跌(點)");

 

long_condition = Average(Close, 5) cross over Average(Close, 10);

 

if Position = 0 and long_condition then begin

SetPosition(1);{ 買進1張 }

end;

 

if Position > 0 and Filled > 0 then begin

var: intrabarpersist max_profit_point(0);{ 啟動停利後最大獲利點 }

 

if loss_point > 0 and Close <= FilledAvgPrice - loss_point then begin

{ 停損 }

SetPosition(0);

max_profit_point = 0;

 

end else begin

 

{ 判斷是否要啟動停利 }

if max_profit_point = 0 and Close >= FilledAvgPrice + profit_point then begin

max_profit_point = Close;

end;

 

if max_profit_point <> 0 then begin

if Close <= max_profit_point - profit_drawback_point then begin

{ 停利 }

SetPosition(0);

max_profit_point = 0;

end else if Close > max_profit_point then begin

{ 移動最大獲利點 }

max_profit_point = Close;

end;

end;

end;

 

end;

請問要如何更改 才能間隔一分鐘之後再下單  不然使用逐筆交易 他一分鐘 可以進出三次

排序方式: 標準 | 最新
XQ小幫手 發文於   2022/06/10

Hello swer,

 

簡單的方法是您可以設一個 intrabarpersist 的變數,然後在出場的時後將該變數設為currentbar,以此作為進場的限制 (該變數相同的話不能進場)。

這樣的話就會變成同根Bar不會發生出場後又進場的狀況。

 

另外的一個方法就是使用 FilledRecordTime 搭配 FilledRecordCount 去取得最後出場的時間點,搭配 TimeAdd 計算1分鐘後可以再進場的時間點來當作進場條件之一。

swer 發文於   2022/06/12

那我應該哪裡?做怎樣的修改比較好?

 

swer 發文於   2022/06/12

不然還是新手不太會@@

 

XQ小幫手 發文於   2022/06/16

Hello swer,

 

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

input: profit_drawback_point(10, "停利回跌(點)");

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

 

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

var: intrabarpersist _currentbar(0);    //紀錄當下的K棒編號

 

if profit_point = 0 then raiseruntimeerror("請設定停利(點)");

if profit_drawback_point = 0 then raiseruntimeerror("請設定停利回跌(點)");

if profit_drawback_point > profit_point then raiseruntimeerror("停利(點)需大於停利回跌(點)");

 

long_condition = Average(Close, 5) cross over Average(Close, 10);

condition1 = currentbar <> _currentbar;    //紀錄的K棒編號不等於當下的K棒編號

 

if Position = 0 and long_condition and condition1 then begin

    SetPosition(1);{ 買進1張 }

    end;

 

if Position > 0 and Filled > 0 then begin

var: intrabarpersist max_profit_point(0);{ 啟動停利後最大獲利點 }

if loss_point > 0 and Close <= FilledAvgPrice - loss_point then begin

{ 停損 }

SetPosition(0);

_currentbar = currentbar;    //更新紀錄的K棒編號

max_profit_point = 0;

end else begin

{ 判斷是否要啟動停利 }

if max_profit_point = 0 and Close >= FilledAvgPrice + profit_point then begin

max_profit_point = Close;

end;

 

if max_profit_point <> 0 then begin

if Close <= max_profit_point - profit_drawback_point then begin

{ 停利 }

SetPosition(0);

_currentbar = currentbar;    //更新紀錄的K棒編號

max_profit_point = 0;

end else if Close > max_profit_point then begin

{ 移動最大獲利點 }

max_profit_point = Close;

end;

end;

end;

end;

 

這樣就會在出場後的下根Bar才會再度進場。

網站上有教學區,裡面有XS語法的基礎和應用。

發表回覆
Close