在此先貼上我自己用的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; 回復 16# wilburwclee
非常謝謝您 {:4_160:}祝福 {:4_209:} 回復 16# wilburwclee
MACD的語法很多,這組是我見過最注重細節的寫法。 Sirius 發表於 11-10-18 20:26 static/image/common/back.gif
已經變粗了,又想要變長
以前怎沒想過這問題?
看到這個我忍不住笑了 XD
頁:
1
[2]