出場腳本

  •   274 
  • 最後發表   shuyen  2021 九月 01
shuyen 發文於   2021/08/28

請問如果我想寫一個出場腳本是

做多 股價往上漲以後 從高點下殺1.5% 就出場

做空 股價下跌以後,從低點反彈1.5%就出場

腳本要如何撰寫

XQ小幫手 發文於   2021/09/01

Hello shuyen,

 

您可以使用 getfield("High", "D") 跟 getfield("Low", "D") 來取得當日的最高最低價,並以此來作判斷。

舉例來說,假設是用在交易腳本的話:

if position > 0 and close <= (getfield("High", "D") * 0.985) then setposition(0, market);

//如果現在部位大於0且收盤價低於當日最高價跌1.5%的話就出場

if position < 0 and close >= (getfield("Low", "D") * 1.015) then setposition(0, market);

//如果現在部位小於0且收盤價高於當日最低價漲1.5%的話就出場

 

如果您要的不是以當日最高價或最低價來作判斷,而是使用進場後的最高價與最低價。

那麼您可以在進場的時候用變數紀錄當下的時間與日期,然後使用 GetBarOffset 搭配 HighestLowest 函數來取得這段時間內的最高價與最低價。

像是:

if position = 0 and {進場條件} then begin

    setposition(1, market);

    value1 = date;

    value2 = time;

    end;

if position > 0 and close <= (highest(high, getbaroffset(value1, value2)) * 0.985) then setposition(0, market);

發表回覆
Close