MACD線: 計算12天平均和26天平均的差
Signal (信號線): 計算MACD 9天均值
Histogram (柱): 計算MACD與Signal的差值
MACD指標的一般研判標準
MACD指標的一般研判標準主要是圍繞快速和慢速兩條均線及紅、綠柱線狀況和它們的形態展開。一般分析方法主要包括DIF指標和MACD值及它們所處的位置、DIF和MACD的交叉情況、紅柱狀的收縮情況和MACD圖形的形態這四個大的方面分析。一、DIF和MACD的值及線的位置
1、當DIF和MACD均大於0(即在圖形上表示為它們處於零線以上)並向上移動時,一般表示為股市處於多頭行情中,可以買入或持股;
2、當DIF和MACD均小於0(即在圖形上表示為它們處於零線以下)並向下移動時,一般表示為股市處於空頭行情中,可以賣出股票或觀望。
3、當DIF和MACD均大於0(即在圖形上表示為它們處於零線以上)但都向下移動時,一般表示為股票行情處於退潮階段,股票將下跌,可以賣出股票和觀望;
4、當DIF和MACD均小於0時(即在圖形上表示為它們處於零線以下)但向上移動時,一般表示為行情即將啟動,股票將上漲,可以買進股票或持股待漲。
本篇介紹一個利用MACD線在趨勢中拉回的交易系統(FPS - First PullBack System),它主要是以訊號線來定義趨勢,而以MACD線在拉回或反彈過程中與訊號線交叉來決定是否進場
{策略的參數與變數}
input:EntryType(3),ExitType(5);
inputs:NBarL(30),NBarS(27),TradeProfit(0.03),TradeStopLoss(0.04),
ATRs_L(14.9),ATRs_S(6.8);
vars: IsBalanceDay(False),MP(0),PF(0),PL(0);
inputs: FastMA(4),SlowMA(10), AvgMA(16),ATRLen(8),EATRPcnt(2.7), XATRPcnt(5.3), HighBar(5), LowBar(3);
Vars: MACDLine(0),SignalLine(0),ZeroLine(0),ATR(0),UpTrend(False),
DnTrend(False),BuySetup(False),SellSetup(False),CTrendLow(0), CTrendHigh(0), SignalFlag(False);
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 ;
{Calculation variables}
MACDLine = MACD(Close, FastMA, SlowMA);
SignalLine = XAverage(MACD(Close, FastMA, SlowMA), AvgMA);
ATR = AvgTrueRange(ATRLen);
{定義趨勢方向 - 信號線突破零軸為上漲}
IF SignalLine Crosses Above ZeroLine Then Begin
UpTrend = True;
DnTrend = False;
SellSetup = False;
SignalFlag = False;
End;
{定義趨勢方向 - 信號線跌破零軸為下跌}
IF SignalLine Crosses Below ZeroLine Then Begin
DnTrend = True;
UpTrend = False;
BuySetup = False;
SignalFlag = False;
End;
{買方環境建立 - 當趨勢向上時觀察第一次 MACD 線拉回交叉信號線的時間點}
IF UpTrend Then Begin
IF MACDLine Crosses Below SignalLine AND SignalFlag = False Then BuySetup = True;
End;
{賣方環境建立 - 當趨勢向下時觀察第一次 MACD 線反彈交叉信號線的時間點}
IF DnTrend Then Begin
IF MACDLine Crosses Above SignalLine AND SignalFlag = False Then SellSetup = True;
End;
{進場後重新設置變數值}
IF MarketPosition = 1 Then Begin
BuySetup = False;
SignalFlag = True;
End;
IF MarketPosition = -1 Then Begin
SellSetup = False;
SignalFlag = True;
End;
{Entries}
IF MP <> 1 and BuySetup Then Buy Next Bar at Highest(High,HighBar) Stop;
IF MP <> -1 and SellSetup Then Sell Next Bar at
Lowest(Low,LowBar) Stop;
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 ExitType = 5 then Begin {*******************************************************************
Description : ATR Trailing Stop Long Exit
Provided By : Omega Research, Inc. (c) Copyright 1999 ********************************************************************}
{Inputs: ATRs_L(3);}
Variables: PosHigh(0), ATRVal_L(0);
ATRVal_L = AvgTrueRange(10) * ATRs_L;
If BarsSinceEntry = 0 Then PosHigh = High;
If MarketPosition = 1 Then Begin
If High > PosHigh Then PosHigh = High;
ExitLong ("ATR") Next Bar at PosHigh - ATRVal_L Stop;
End else ExitLong ("ATR eb") Next bar at High - ATRVal_L Stop;
{*******************************************************************
Description : ATR Trailing Stop Short Exit
Provided By : Omega Research, Inc. (c) Copyright 1999
********************************************************************}
{Inputs: ATRs_S(3);}
Variables: PosLow(0), ATRVal_S(0);
ATRVal_S = AvgTrueRange(10) * ATRs_S;
If BarsSinceEntry = 0 Then PosLow = Low;
If MarketPosition = -1 Then Begin
If Low < PosLow Then PosLow = Low;
ExitShort ("ATR_1") Next Bar at PosLow + ATRVal_S Stop;
End else ExitShort ("ATR_1 eb") Next bar at Low + ATRVal_S Stop;
end;
if IsBalanceDay or date = 1150224 then setExitonClose ;
台指期 30 min K 留倉 交易期間 2004/12/31 ~ 2014/12/31 交易成本 1200
從本質上來觀察,此交易策略也類似股票價格在月/季線上方行進時,當價格作次級修正使得5日線折返回中期均線獲得支撐後,再延續上升軌跡前進的道理相同。在文內的指標圖也能看到每一次的 MACD 與信號線的交叉 都是可以運用參考的進場點
0 意見:
張貼留言