請問這個腳本直接在策略雷達執行,偵測到出場條件會自動出場嗎?
為什麼感覺他都只有進場..
Inputs: len20(20), len60(60), len240(240);
Vars:
ma20(0), ma60(0), ma240(0),
s20(0), t1(0), t2(0), fit20(0),
s60(0), t3(0), t4(0), fit60(0),
s240(0), t5(0), t6(0), fit240(0),
IntraBarPersist mPos(0);
SetTotalBar(300);
{ === 計算均線與斜率 === }
ma20 = Average(Close, len20);
ma60 = Average(Close, len60);
ma240 = Average(Close, len240);
LinearReg(Close, len20, 0, s20, t1, t2, fit20);
LinearReg(Close, len60, 0, s60, t3, t4, fit60);
LinearReg(Close, len240, 0, s240, t5, t6, fit240);
{ ==========================================
邏輯 A:進場 (空手時才偵測)
========================================== }
if mPos = 0 then begin
if (Close > ma20) and (Close > ma60) and (Close > ma240)
and (s20 > s20[1] and s20[1] > s20[2])
and (s60 > s60[1] and s60[1] > s60[2])
and (s240 > s240[1] and s240[1] > s240[2])
then begin
mPos = 1; { 標記為持倉中 }
ret = 1;
RetMsg = "【多單進場】";
end;
end
{ ==========================================
邏輯 B:出場 (持倉時才偵測)
條件:連續兩根收盤價 < MA60
========================================== }
else if mPos = 1 then begin
if (Close < ma60) and (Close[1] < ma60[1]) then begin
mPos = 0; { 標記為已出場 }
ret = 1;
RetMsg = "【多單出場】";
end;

11 評論