跌破第一根5分K放空,如何記錄進場當根高點不要讓他一直變?

  •   585 
  • 最後發表   東.  2022 十月 04
東. 發文於   2022/09/20

 

 

if barInterval <> 5 and barfreq <> "Min" then raiseRunTimeError("請使用5分鐘頻率");
if getfielddate("Date") <> getfielddate("Date")[1] then 
begin  //如果是開盤第一根的話
value1 = low;   //value2紀錄第一根最低價
end;

if Position = 0 and filled = 0 then 
    begin
        if close[1] < value1 then 
            begin 
                setposition(-1);
                Value5=GetField("high")[1]; 
                print("",value5);
            end;
    end;

if Position = -1 and filled = -1 then begin 

    if Close > value5 then 
        begin           
            SetPosition(0);
        end;
    end;

if currenttime >= 130000 and filled <> 0 then setposition(0, market);

 

如標題,實際跑的時候Value5會隨著k棒變動,但是我不是有設條件 if Position = 0 and filled = 0才會執行了嗎

有沒有方法能夠紀錄進場當根高點 不要讓它變呢 謝謝

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

Hello 東.,

 

小幫手認為您是因為value5會記錄當次進場的數值,所以不同次進場時印出的數值就會不同。

而因為此腳本只有在進場的時候print,所以觀看印出數值時會覺得像是value5一直變化。

建議您print的時候可以同時將 date 和 time 印出一併檢查就可以看出是否是每根Bar都變 (小幫手回測測試就是上述狀況)。

 

東. 發文於   2022/09/27

小幫手你好,感謝你得回復,value5是解決了 但現在問題變成 價格到value5卻不會停損 

if barInterval <> 5 and barfreq <> "Min" then raiseRunTimeError("請使用5分鐘頻率");
if getfielddate("Date") <> getfielddate("Date")[1] then 
begin  //如果是開盤第一根的話
value1 = low;   //value2紀錄第一根最低價
end;
Var: intrabarpersist ct(0),ct2(0),ct3(0);
condition1 = close[1] < value1;
condition2 = Position = 0 ;
condition3 = filled = 0;
value2 = AddSpread(GetField("跌停價", "D"),2);
if currentTime > 090500 then ct3=1;

if ct3=1 and condition1 and condition2 and condition3 then 
    begin   
        ct=1;
        setposition(-1);        
    end;

if ct=1 and filled = -1 then 
    Begin 
        value5 = High[1]; 
        print("",value5);
        ct=0; 
        ct2=1;
    End;

if ct2=1 and Close > value5 then SetPosition(0);

if close <= value2 then setposition(0);

if currentTime > 132430 then setposition(0);

 

27行

 if ct2=1 and Close > value5 then SetPosition(0);

的部分我試了很久 回測了好幾檔 今天也實際下去跑 明明有符合條件卻都不執行,想問是不是哪裡沒注意到?

XQ小幫手 發文於   2022/10/04

Hello 東.,

 

小幫手這邊回測可以正常的進出場,建議您可以測試將 setposition 改為市價單,有可能是因為限價設定的關係導致沒有成交。

if currentTime > 090500 then ct3=1; 這種寫法會讓其在第一次過了09:05以後 ct3 就一直等於 1。

如果您是要 09:05 以後才進場,建議您可以改為 condition4 = currentTime > 090500; 或 if currentTime > 090500 then ct3=1 else ct3 = 0;

您也可以將相關數值print出來確認腳本是否有如您所想的運作。(ex. print(date, time, ct3, ct, ct2, Close > value5, filled);)

 

如果還是有問題的話,麻煩您提供 策略匯出檔勾選(包含) 交易腳本 並告知有問題的商品和發生的日期時間讓小幫手確認。

您可以直接將檔案上傳,也可以Mail至客服信箱 XQservice@XQ.com.tw 且務必附上 討論文章連結網址(小幫手才能盡早處理)。

感謝。

發表回覆
Close