https://www.bituzi.com/2015/04/trading-fundamantals34.html
這裡還是從前篇 HullMoving Average(HMA) 出發, 微分是無限小的變量,我們無法做到無限小, 只能在此均線上取兩點(6 根 K 棒)的差值(即導數)來近似!
//----------------------------------
inputs: Hlength(x), dyz(6);
Input: avmlen(y), asima(2), du(z1),dl(z2);
var: M1_M2(0), avM1_M2(0);
vars: delta1(0), MA(0),HMA(0);
vars: mp(0), IsBalanceDay(False);
//----------------------------------------
MA=2*WAverage(close,IntPortion(Hlength*0.5))-WAverage(close,Hlength);
HMA=WAverage(MA,IntPortion(SquareRoot(Hlength)));
delta1 = HMA - HMA[dyz];
//----------------------------------------
M1_M2 = AverageFC(delta1, asima);
avM1_M2 = AverageFC(M1_M2, avmlen);
//-----------------------------------------
mp = MarketPosition;
if DAYofMonth(Date) > 14 and DAYofMonth(Date) < 22 and DAYofWeek(Date)= 3 then isBalanceDay = True else isBalanceDay =False;
//---------------------------------------
if mp = 0 then begin
if M1_M2 cross over avM1_M2+du then buy next bar at market;
end;
if mp > 0 then begin
if M1_M2 cross under avM1_M2-dl then sellshort next bar at market;
end;
if mp < 0 then begin
if M1_M2 cross over avM1_M2+du then buy next bar at market;
end;
if IsBalanceDay then setExitonClose;
//--------------------------------------------------
delta1 即為 HullMoving Average(HMA) 的導數, 當導數為零時, 代表均線反轉, 而導數極大(小)值, 代表均線的反曲點, 均線增速為零, 之後均線上漲速度變緩!
為使導數較為平滑, 可求其某小區間的均值, 即 M1_M2 = AverageFC(delta1, asima); 而 avM1_M2 = AverageFC(M1_M2, avmlen) 為某一區間的導數簡單平均值(線)!
此指標的交易策略, 可以在導數M1_M2 穿越 avM1_M2 之上時買進, 在 M1_M2 穿越 avM1_M2 之下時賣出, 加減一小差值 du, dl 當緩衝, 以減少買賣雜訊.
4分鐘 K 線, 跑日夜盤的波段策略, 以 2017.05 至2020.06.30 之資料為樣本內做優化, 一口小台, 不設停損, 每月結算, 起始資金10萬, 單邊費用設120元, 2020. 07.01 後是樣本外績效,