指定時間段內的最高價及最低價

  •   1.1K 
  • 最後發表   奇怪的人  2021 九月 29
奇怪的人 發文於   2021/09/23

 

如圖所示

5分K線圖

我想要指定再每天開盤的前4跟K線(0845~0905)

這4跟K棒的實線的最高級最低價(影線不要,只取開/收盤價)

有辦法這樣做篩選嗎?

 

排序方式: 標準 | 最新
XQ小幫手 發文於   2021/09/24

Hello 奇怪的人,

 

您可以使用往前第五根跟第四根的日期判斷是否有換日,接著再判斷這段時間內開盤收盤的最高最低價。

不過您舉的例子台指期的話為了避免換日判斷錯誤(包含夜盤的商品是在13:45換日),可以直接指定時間。

附上指標腳本供您參考。

附加文件

奇怪的人 發文於   2021/09/25

那我套用上面概念

我寫出以下

//if getfielddate("Date")[3] <> getfielddate("Date")[4] then begin
if time = 090000 then begin
    if highest(open, 4) > highest(close, 4) then value1 = highest(open, 4) else value1 = highest(close, 4);
    if lowest(open, 4) < lowest(close, 4) then value2 = lowest(open, 4) else value2 = lowest(close, 4);
    end;

value3 = (open[1]+close[1])*(open[1]*0.5+close[1]*0.5)/(open[1]+close[1]);

var:plratio(0),InCondition1(False),InCondition2(False);
var: price_change(0);

if barfreq <> "MIN" and barinterval <> 5 then raiseruntimeerror("請使用5分鐘頻率");
//進場
InCondition1 = position = 0 and value3 > value1 and close > value1 ;
if position = 0 and filled = 0 and InCondition1 then setposition(1);
InCondition2 = position = 0 and value3 < value2 and close < value2 ;
if position = 0 and filled = 0 and InCondition2 then setposition(-1);

//中午1點35分強制平倉
if filled <> 0 and currenttime >= 133500 then setposition(0, market);

//出場
if position > 0 and  close > addspread(filledavgprice, 50) then setposition(0,addspread(filledavgprice, 50));
if position < 0 and  close < addspread(filledavgprice, -50) then setposition(0,addspread(filledavgprice, -50));

 

邏輯為:

每天早上開盤的前4根5分K實線的最高及最低價為基準

Value3大於高價基準線買進一口做多

Value3小於低價基準線賣出一口做空

獲利50點出場

中午1點35分強制平倉

以上邏輯

這樣寫有問題嗎?

 

另外

有辦法再增加以下條件嗎?

只操作期貨日盤(084500~134500)

並且每天最多只操作多空各一次

 

 

謝謝~

 

 

-


補充

我又加上了移動停利出場

如以下

input: profit_point(200, "停利(點)");
input: profit_drawback_point(25, "停利回跌(點)");
input: loss_point(25, "停損(點)");
Input: AAAAA(1, "購買張數");

//if getfielddate("Date")[3] <> getfielddate("Date")[4] then begin
if time = 090000 then begin
    if highest(open, 4) > highest(close, 4) then value1 = highest(open, 4) else value1 = highest(close, 4);
    if lowest(open, 4) < lowest(close, 4) then value2 = lowest(open, 4) else value2 = lowest(close, 4);
    end;

value3 = (open+close)/2;

var:plratio(0),InCondition1(False),InCondition2(False);
var: price_change(0);

if barfreq <> "MIN" and barinterval <> 5 then raiseruntimeerror("請使用5分鐘頻率");
//進場
if time > 090505 then begin
    InCondition1 = position = 0 and value3 > value1 and close > value1 ;
    if position = 0 and filled = 0 and InCondition1 then setposition(AAAAA);
    InCondition2 = position = 0 and value3 < value2 and close < value2 ;
    if position = 0 and filled = 0 and InCondition2 then setposition(-1*AAAAA);
    end;

//中午1點35分強制平倉
if filled <> 0 and currenttime >= 133500 then setposition(0, market);

//出場
if profit_point = 0 then raiseruntimeerror("請設定停利(點)");
if profit_drawback_point = 0 then raiseruntimeerror("請設定停利回跌(點)");
if profit_drawback_point > profit_point then raiseruntimeerror("停利(點)需大於停利回跌(點)");

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 else 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;

這樣移動停利停損的寫法有問題嗎?

想麻煩小幫手幫我健檢一下

 

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

Hello 奇怪的人,

 

要限制五分鐘的話應該是要用 if barfreq <> "MIN" or barinterval <> 5 then raiseruntimeerror("請使用5分鐘頻率");

另外您的 InCondition 裡面已經有position的判斷了,下面進場時就不用另外加 position 的判斷。

如果您想限定時間的話可以使用在進場時就做限定。

舉例來說:

if time > 090500 and time < 133000 then begin

    InCondition1 = position = 0 and value3 > value1 and close > value1 ;

    if position = 0 and filled = 0 and InCondition1 then setposition(AAAAA);

    InCondition2 = position = 0 and value3 < value2 and close < value2 ;

    if position = 0 and filled = 0 and InCondition2 then setposition(-1*AAAAA);

    end;

這樣就可以確保只在 09:10 ~ 13:30 之間交易。

需注意XQ的time是 Bar 開始的時間。

 

第二部分小幫手看腳本和用print輸出數值看起來是沒有問題。

建議您可以使用 print 函數將相關數據輸出檢驗即可。

發表回覆
Close