分享AmiBroker的MACD紅綠柱狀線
剛才想要MACD紅綠柱狀線。上網找了寫法。
分享給大家。//MACD - Moving Average Convergence Divergence v1
//adapted from code by Tomasz Janeczko
//ideas by Graham Kavanagh and Terry Magic
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
m1 = MACD(r1, r2);
s1 = Signal(r1,r2,r3);
difference = m1-s1;
Plot( m1, StrFormat(_SECTION_NAME()+"(%g,%g)", r1, r2), ParamColor("MACD color", colorRed ), ParamStyle("MACD style") );
Plot( s1, "Signal" + _PARAM_VALUES(), ParamColor("Signal color", colorBlue ), ParamStyle("Signal style") );
Color=IIf(difference > 0,colorGreen,colorRed);
Plot(difference, "MACD Histogram", Color, styleNoTitle | ParamStyle("Histogram style", styleHistogram | styleThick | styleNoLabel, maskHistogram ) ); 剛才有在別的主題上貼上自己修改的MACD碼。為了和更多人分享,在此也貼上自己用的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; 抱歉。
剛才沒有發現顏色標反了。
外國人真奇怪,
上漲用綠的,下跌用紅的。
修正在下面。
//MACD - Moving Average Convergence Divergence v1
//adapted from code by Tomasz Janeczko
//ideas by Graham Kavanagh and Terry Magic
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
m1 = MACD(r1, r2);
s1 = Signal(r1,r2,r3);
difference = m1-s1;
Plot( m1, StrFormat(_SECTION_NAME()+"(%g,%g)", r1, r2), ParamColor("MACD color", colorRed ), ParamStyle("MACD style") );
Plot( s1, "Signal" + _PARAM_VALUES(), ParamColor("Signal color", colorBlue ), ParamStyle("Signal style") );
Color=IIf(difference > 0,colorRed,colorGreen);
Plot(difference, "MACD Histogram", Color, styleNoTitle | ParamStyle("Histogram style", styleHistogram | styleThick | styleNoLabel, maskHistogram ) );
本帖最後由 Sirius 於 11-10-18 07:59 PM 編輯
若需要柱體值的,最後一行補上以下這行即可Plot( difference , "BAR", Color, styleNoLine);"BAR"那個柱體英文名稱,請自行改成自己想要的名稱
以上是幫oneman001大做的 回復 3# Sirius
謝謝您
您人真好 謝謝分享............ 謝謝您
您人真好。。。。。。。。。。。。 真好!謝謝您分享。 太棒了,很多希望是內建的,不用再搞東搞西 謝謝大大.......剛來報到 感謝版主的分享,謝謝{:4_113:}
頁:
[1]