小幫手請教,我以下腳本做回測,不清楚哪邊撰寫有誤,回測都沒有數據,在麻煩解惑,感謝。
腳本如下:
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)));
2 評論