試搓資料

  •   581 
  • 最後發表   hello10282000  2024 十一月 19
hello10282000 發文於   2024/11/04

大家好

我想問一下,當前一天晚上先選好標的,然後XS是否可以抓到08:59:45秒的盤前試搓資料,然後知到前一天選好的股票標的震幅大於3%後於開盤前掛漲停價自動下單。

排序方式: 標準 | 最新
虎科大許教授 發文於   2024/11/04

試撮時可以透過q_SimulatedTradePrice抓到試撮成交價,可根據此價格計算振幅。

hello10282000 發文於   2024/11/05

謝謝虎科大許教授,我再來研究研究,感謝。

hello10282000 發文於   2024/11/05

虎科大許教授 日安

想跟您請教一些問題,目前XS策略雷達中的自動洗價是否可做出我想要的自動交易程式,其邏輯說明如下:

1.前一天自行選出標的

2.使用q_SimulatedTradePrice抓到08:59:45試撮成交價,大於3%以上

3.程式自動掛漲停價買入股票

4.移動停利出場或是固定時間或固定tick出場

虎科大許教授 發文於   2024/11/05

可以的。自動交易中心記得除了設定逐筆洗價,也要勾選自動洗價。

  • 按讚來自於
  • hello10282000
hello10282000 發文於   2024/11/07

感謝虎科大許教授!

我將邏輯寫好成程式碼,如下

//設定變數

value1 = getField("漲停價","D")[1];

Value2 = GetField("外資買張","D")[1];

Value3 = GetField("成交量","D")[1];

value4 = value1*1.03;

//以金額計算交易數量

value5 = 2000000;

Value6 = value4/(value1*1000*1.1);

value7 = Floor(Value5);

 

//移動停損

{多單移動停利(點)

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

價格下跌到停損時出場

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

}

 

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

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

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

 

{ 範例:

均線穿越時買進1張

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

}

 

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

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

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

 

//買進條件

condition1 = getField("CLOSE","D")[1] = value1;

condition2 = value2 > 1;

condition3 = value3 > 15000;

condition4 = getField("CLOSE","D")[1] = value1*1.03;

   

//移動停利

if Position = 0

   and condition1 

   and condition2 

   and condition3

   and currentTimeMS > 085930.500

   and q_MarketState = 4 

   and condition4 

   then begin SetPosition(value7,getField("漲停價","D")); {漲停價買進,200萬/漲停價格 }

end;

 

if Position = 1 and Filled = 1 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;

 

 

請問這樣是否可以依據我的交易邏輯去執行呢??

hello10282000 發文於   2024/11/10

請問上述程式,是否可以達成我之前寫的交易邏輯,感謝

hello10282000 發文於   2024/11/10

請問上述程式,是否可以達成我之前寫的交易邏輯,感謝

虎科大許教授 發文於   2024/11/10

condition1 = getField("CLOSE","D")[1] = value1;

condition4 = getField("CLOSE","D")[1] = value1*1.03;

以上這兩個condition相抵觸。

我把condition4改成 condition4 = getField("Close","D") >= value1*1.03; //目前漲超過3%以上

買進張數value7計算有誤。應該改成:value7 = Floor(value5/(c*1000)); //200萬可買進的張數

//移動停損
{多單移動停利(點)
設定停損點(如果不設定的話, 請把loss_point設定成0), 以及停利點, 跟回跌點數
價格下跌到停損時出場
價格上漲到停利點後啟動移動停利, 如果價格繼續上漲, 則繼續持有, 如果價格回檔超過回跌點數時, 則停利出場
}
input: profit_point(8, "停利(點)");
input: profit_drawback_point(5, "停利回跌(點)");
input: loss_point(10, "停損(點)");
{ 範例:
均線穿越時買進1張
以成交價為基礎, 設定固定停損以及移動停利
}
var: intrabarpersist max_profit_point(0); { 啟動停利後最大獲利點 }

//設定變數
value1 = getField("漲停價","D")[1];
Value2 = GetField("外資買張","D")[1];
Value3 = GetField("成交量","D")[1];
value4 = value1*1.03;
//以金額計算交易數量
value5 = 2000000;
Value6 = value4/(value1*1000*1.1);
value7 = Floor(value5/(c*1000));
if profit_point = 0 then raiseruntimeerror("請設定停利(點)");
if profit_drawback_point = 0 then raiseruntimeerror("請設定停利回跌(點)");
if profit_drawback_point > profit_point then raiseruntimeerror("停利(點)需大於停利回跌(點)");
//買進條件
condition1 = getField("CLOSE","D")[1] = value1;
condition2 = value2 > 1;
condition3 = value3 > 15000;
condition4 = getField("CLOSE","D") = value1*1.03;
//移動停利
if Position = 0
    and condition1 
    and condition2 
    and condition3
    and currentTimeMS > 085930.500
    and q_MarketState = 4 
    and condition4 then 
    begin 
        SetPosition(value7,getField("漲停價","D")); {漲停價買進,200萬/漲停價格 }
    end;
if Position > 0 and Filled > 0 then 
    begin
        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;

hello10282000 發文於   2024/11/10

謝謝虎科大許教授,感謝您寶貴的回覆。

XS小編 發文於   2024/11/19

Hello hello10282000,

 

小編補充,網站上的教學區教學影片,裡面有XS語法的基礎和應用可以閱覽。

您可以在腳本中加上print印出相關數值,會比較容易確認理解策略是如何運作的,以及哪裡有問題。

 

感謝 虎科大許教授 的熱心回覆。

發表回覆
Close