電子信箱 service [at] bituzi.com
幣圖誌首頁 facebook粉絲團 google plus google plus


開發商品的交易系統 - 基礎篇 [50] 資金流量指標

資料參考自MBA智庫

資金流量指標,英文全名Money Flow Index,縮寫為MFI,根據成交量來計測市場供需關係和買賣力道,屬於量能反趨向指標。1989年3月由威爾斯·威爾德(Wells Wilder)首次發表MFI指標的用法。MFI指標實際是將相對強弱指標RSI加以修改後,演變而來。RSI以成交價為計算基礎;MFI指標則結合價和量,將其列入綜合考慮的範圍。可以說,MFI指標是成交量的RSI指標;指標的公式只是硬梆梆的計算程式,重要的是他計算式裡的內涵。



在2015年近月STOCKS&COMMODITIES雜誌中 “The Money Flow Oscillator” 文章的作者 Vitali Apirine 再度發表了一個新指標,透過從現有計算方式的改變,重新評估商品價格在市場中的買賣壓力。

資金流量指標的應用法則:
  1. MFI>80時,代表資金短期過熱訊號。但是,必須等待MFI指標再度向下跌破80時,才能確認資金轉向。
  2. MFI<20時,代表資金短期冷卻訊號。但是,必須等待MFI指標再度向上突破20時,才能確認資金轉向。
  3. MFI在80左右的水平,出現一頂比一頂低,和股價“背離”的現象時,可視為中期反轉下跌的訊號。
  4. MFI在20左右的水平,出現一底比一底高,和股價“背離”的現象時,可視為中期反轉上漲的訊號。
  5. MFI指標連續兩次向下交叉其平均線時,視為賣出訊號。(平均線一般設定為6天)
  6. MFI指標連續二次向上交叉其平均線時,視為買進訊號。(平均線一般設定為6天)

指標程式碼
inputs: Length(20) ;
vars:Dvs(0),MLTP(0),MyVol(0),Dvsv(0),MFV(0),MFO(0);

Dvs = ( High - Low[1] ) + ( High[1] - Low ) ;
if Dvs <> 0 then MLTP = Round(( ( High - Low[1] ) - ( High[1] - Low ) ) / Dvs,2) ;

MyVol = iff( DataCompression >= 2 , Volume, Ticks ) ;
Dvsv = iff ( MyVol <> 0, MyVol, 0 ) ;

MFV = ( MLTP * MyVol ) ;

if Summation( Dvsv, Length ) <> 0
then MFO = Summation( MFV, Length ) / Summation( Dvsv, Length ) ;

Plot1( MFO, "MFO" ) ;
Plot2( 0, "ZL" ) ;

{系統參數與變數} 
input:EntryType(2),ExitType(5);
inputs:NBarL(6),NBarS(9),TradeProfit(0.045),TradeStopLoss(0.03),ATRs_L(16),ATRs_S(21);
vars:IsBalanceDay(False),MP(0),PF(0),PL(0);
inputs:LenA(25),LenB(11),ConfirmBarA(5),ConfirmBarB(3),RangeA(70),RangeB(-40),HighBar(7),LowBar(16) ;
vars:Dvs(0),MLTP(0),MyVol(0),Dvsv(0),MFV(0),MFOA(0),MFOB(0);
vars:UpCounterA(0),DnCounterA(0),UpCounterB(0),DnCounterB(0) ;

MP = MarketPosition ;
if DAYofMonth(Date) > 14 and DAYofMonth(Date) < 22 and DAYofWeek(Date)= 3 then isBalanceDay = True else isBalanceDay =False ;

PF = AvgPrice*TradeProfit ;
PL = AvgPrice*TradeStopLoss ;

{ 計算連續兩根K棒的高低點差距與強度 }
Dvs = ( High - Low[1] ) + ( High[1] - Low ) ; if Dvs <> 0 then MLTP = Round((( High - Low[1] )-( High[1] - Low ) ) / Dvs,2) ;

MyVol = iff( DataCompression >= 2 , Volume, Ticks ) ;
Dvsv = iff ( MyVol <> 0, MyVol, 0 ) ;

{ 計算資金流量 }
MFV = ( MLTP * MyVol ) ;

{分別計算多空使用不同週期的擺盪指標}
if Summation( Dvsv, LenA ) <> 0 then MFOA = Summation( MFV, LenA ) / Summation( Dvsv, LenA ) *100 else MFOA = 0 ;
if Summation( Dvsv, LenB ) <> 0 then MFOB = Summation( MFV, LenB ) / Summation( Dvsv, LenB ) *100 else MFOB = 0 ;

{ 計算多方擺盪指標在零軸上下的次數}
if MFOA > 0 then begin
UpCounterA = UpCounterA + 1 ;
DnCounterA = 0 ;
end else begin
UpCounterA = 0 ;
DnCounterA = DnCounterA + 1 ;
end ;

{ 計算空方擺盪指標在零軸上下的次數}
if MFOB > 0 then begin
UpCounterB = UpCounterB + 1 ;
DnCounterB = 0 ;
end else begin
UpCounterB = 0 ;
DnCounterB = DnCounterB + 1 ;
end ;

{ 穿越零軸次數作多空進出參考-多空相同週期}
if EntryType = 1 then Begin
if MP <> 1 and UpCounterA >= ConfirmBarA then Buy next bar at Market
else if MP <> -1 and DnCounterA >= ConfirmBarA then Sell next bar at Market ;
end;

{ 穿越零軸次數作多空進出參考- 多空不同週期}
if EntryType = 2 then Begin
if MP <> 1 and UpCounterA >= ConfirmBarA then Buy next bar at Highest(High,HighBar) stop ;
if MP <> -1 and UpCounterB >= ConfirmBarB then Sell next bar at Lowest(Low,LowBar) stop ;
end;

{ 穿越超買超賣線的次數作多空進出參考}
if EntryType = 3 then Begin
if MP <> 1 and Countif(MFOA > RangeA,ConfirmBarA) >= ConfirmBarA then Buy next bar at Highest(High,HighBar) stop ;

if MP <> -1 and Countif(MFOB < RangeB,ConfirmBarB) >= ConfirmBarB then Sell next bar at Lowest(Low,LowBar) stop ;
end;

if ExitType = 1 then SetStopLoss(PL * BigPointValue) ;

if ExitType = 2 then Begin
SetStopLoss(PL * BigPointValue) ;
setProfitTarget(PF * BigPointValue) ;
end;

if ExitType = 3 then Begin
if MP > 0 and BarsSinceEntry = NBarL then ExitLong next bar at Market;
if MP < 0 and BarsSinceEntry = NBarS then ExitShort next bar at Market;
end;

if ExitType = 4 then Begin SetStopLoss(PL * BigPointValue) ;
setProfitTarget(PF * BigPointValue) ; if MP > 0 and BarsSinceEntry = NBarL then {Sell } ExitLong next bar at Market ;
if MP < 0 and BarsSinceEntry = NBarS then {Buy} ExitShort next bar at Market ;
end;

if IsBalanceDay or date = 1150224 then setExitonClose ;

台指期 15 min K 多空留倉 交易週期 2005/3/31~ 2015/3/31 交易成本 1200

台指期 30 min K 多空留倉 交易週期 2005/3/31~ 2015/3/31 交易成本 1200

原文轉載自就是愛現,程式交易

0 意見: