雷達的觸發

  •   120 
  • 最後發表   風期會  2023 五月 25
風期會 發文於   2023/05/24

小幫手請教,我以下腳本做回測,不清楚哪邊撰寫有誤,回測都沒有數據,在麻煩解惑,感謝。

腳本如下:

setbackBar(5000);
settotalBar(5000);

//=====================運算區=====================
//--------------------60DIF--------------------
input:  FastLength(12, "DIF短天數"), SlowLength(26, "DIF長天數"), MACDLength(9, "MACD天數"),
        FreqType("60", "跨頻率週期", inputkind:=dict(["1分鐘","1"],["5分鐘","5"],["10分鐘","10"],["15分鐘","15"],["30分鐘","30"],["60分鐘","60"],["日","D"],["還原日","AD"]));

xfMin_macd(FreqType,xfMin_weightedclose(FreqType),FastLength,SlowLength,MACDLength,value1,value2,value3);

// 前面區段資料變動較大, 先不繪出
//
if CurrentBar <= SlowLength then
begin
    Value1 = 0;
    Value2 = 0;
    Value3 = 0;
end;

//--------------------60KD--------------------
input:  Length(9, "天數"), RSVt(3, "RSVt權數"), Kt(3, "Kt權數"),
        FreqType1("60", "跨頻率週期", inputkind:=dict(["1分鐘","1"],["5分鐘","5"],["10分鐘","10"],["15分鐘","15"],["30分鐘","30"],["60分鐘","60"],["日","D"],["還原日","AD"]));
var: rsv(0), kk(0), dd(0);

xfMin_stochastic(FreqType1, Length, RSVt, Kt, rsv, kk, dd);


//--------------------15DIF--------------------
MACD(WeightedClose,12,26,9,value11,value12,value13);

//進場條件

condition21 = value1>0 and kk > dd and value13 cross over 0;  //做多
condition22 = value1<0 and kk < dd and value13 cross under 0;  //做空

//--------------------進出邏輯--------------------
input: Bull_Bear(1,"1做多,2做空");
input: _BuyOrSell(1,"1進場,2平倉"),slost(92,"點數");

var:intrabarpersist bcost(0);
var:intrabarpersist scost(0);

//進場做多
if Bull_Bear=1 then 
begin
if condition21 and bcost = 0 then 
begin 
    bcost = close;
    if _BuyOrSell=1 then Ret=1;
end;
end;

//做多平倉
if close < bcost-slost and bcost <> 0 then 
begin
    bcost = 0;
    if _BuyOrSell=2 then ret=1;

    if dayofweek(date) = 3 and weekofmonth(date) = 3 and time=130000 then 
      begin
        bcost = 0;
        if _BuyOrSell=2 then Ret=1;   
      end;
end;

//進場做空
if Bull_Bear=2 then 
begin
if condition22 and scost = 0 then 
begin 
    scost = close;
    if _BuyOrSell=1 then Ret=1;
end;
end;

//做空平倉
if close > scost+slost and scost <> 0 then 
begin
    scost = 0;
    if _BuyOrSell=2 then ret=1;

    if dayofweek(date) = 3 and weekofmonth(date) = 3 and time=130000 then 
      begin
        scost = 0;
        if _BuyOrSell=2 then Ret=1;   
      end;
end;


print(file("f:\Users\USER\Desktop\平台型態\台期程式交易\"),text("日期",dateToString(date), "時間",timeToString(time),
"。空方成本:",NumToStr(scost,0),"。多方成本:",NumToStr(bcost,0),"。60DIF:",NumToStr(value1,0),"。柱體值:",NumToStr(value13,0)));

排序方式: 標準 | 最新
XQ小幫手 發文於   2023/05/25

Hello 風期會,

 

小幫手建議您可以將相關數值印出就能夠知道問題原因。

舉例來說,就以 Bull_Bear = 1, _BuyOrSell = 1 作範例,在資料預讀筆數時若條件為True的話,bcost就會被改動,那麼進到回測區間時就算condition21 符合,bcost <> 0 的狀況下ret =1;就不會觸發。

而設定為作多平倉的話則是 bcost 從頭到尾都會是0。

另外需注意 xfMin 跨頻率函數僅支援台股。

 

  • 按讚來自於
  • greg750
風期會 發文於   2023/05/25

感謝小幫手,明白了。

發表回覆
Close