|
回復 9# oneman001
在此先貼上我自己用的MACD程式碼產生的輸出圖。
中間是原本AmiBroker的MACD,下面是我MACD程式產生的圖形。DIF 及 MACD 線基本上一樣;DEF用PlotOHLC畫,所以會和Candlestick一樣粗;同時,除了顏色用正負區別外,同時也和前一個值比,往上與往下顏色會有些不同,所以光用看的,就可以知道DEF的方向。
程式碼如下:
// ========== MACD Parameter ==========
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
// ========== MACD Calculation ==========
MACDPrice = (C + H + L + C)/4;
dif = EMA(MACDPrice, r1) - EMA(MACDPrice, r2);
dea = EMA(dif, r3);
def = dif - dea;
// dif = MACD(r1, r2);
// dea = Signal(r1,r2,r3);
// def = dif -dea;
// ========== DIF/MACD Plots ==========
Plot( dif, StrFormat("DIF(%g,%g)", r1, r2), ParamColor("DIF color", colorRed ), ParamStyle("DIF style") );
Plot( dea, "MACD" + _PARAM_VALUES(), ParamColor("MACD color", colorBlue ), ParamStyle("MACD style") );
// ========== DEF "Thick" Histogram ==========
// Set DEF color
Color=IIf(def > 0, IIf(def > Ref(def,-1), ColorRGB(128,255,128), colorGreen),IIf(def > Ref(def,-1), ColorRGB(255,160,160), colorRed));
// Set DEF title and its value (no plot is drawn)
Plot(def, _SECTION_NAME() +_PARAM_VALUES() , colorGreen, styleHidden | styleHistogram | styleThick );
// Plot DEF "thick" histogram using OHLC
SetBarFillColor(Color);
zero = IIf(IsEmpty(Ref(def, -1)), Null, 0);
PlotOHLC(def, def, zero, zero, "Thick Histogram", Color, styleCandle | styleNoTitle | ParamStyle("Histogram style", styleOwnScale, styleOwnScale ) );
GraphXSpace = 20; |
評分
-
查看全部評分
|