請問小幫手,我的程式邏輯是不是錯了?
Q1:回測頻率設為1分K,程式裡設了 if time=085000 才去取 08:45 的5分K資料,但是 log 印出來卻好像執行了四次(請參見附圖)
// 設定及宣告
if barfreq<>"Min" or barinterval<>1 then RaiseRunTimeError("頻率限用一分K");
var: kbar_high(0),kbar_low(0),kbar_open(0),kbar_close(0),kbar_des("");//紀錄紅黑的高低點
if time=085000 then begin //取出今天開盤第一根 5分K (設50分取45分)
kbar_high =GetField("High","5")[1];
kbar_low = GetField("Low","5")[1];
kbar_open= GetField("Open","5")[1];
kbar_close=GetField("Close","5")[1];
if (kbar_open>getfield("Close","5")[2]) and (kbar_close>kbar_open) then
kbar_des="開高收紅"
else if (kbar_open>getfield("Close","5")[2]) and (kbar_open>kbar_close) then
kbar_des="開高收黑"
else if (kbar_open<getfield("Close","5")[2]) and (kbar_close>kbar_open) then
kbar_des="開低收紅"
else if (kbar_open<getfield("Close","5")[2]) and (kbar_open>kbar_close) then
kbar_des="開低收黑";
Print(file("C:\print\[Symbol]\"),formatMQY(Date),FormatTime("HH:mm",currentTime),"開盤五分K >> ",kbar_des);
end;
Q2:我想印出 SetPosition(1) 時的進場價位,這樣寫卻印出來都是 0
if Position = 0 then begin
SetPosition(1);
Print(file("C:\print\[Symbol]\"),formatMQY(Date),FormatTime("HH:mm",currentTime),"買進 Position=",NumToStr(FilledAvgPrice,0));
end;
3 評論