COCO研究院

 找回密碼
 註冊
搜索
12
返回列表 發新帖
樓主: playpp

[範例程式碼] AB中,均線扣抵值的寫法 part 1

[複製鏈接]
發表於 12-1-13 01:09 | 顯示全部樓層
回復 9# oneman001

在此先貼上我自己用的MACD程式碼產生的輸出圖。
MACD.png

中間是原本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;

評分

參與人數 2金錢 +4 收起 理由
lu0811 + 2 :)
oneman001 + 2 很感謝您的幫忙 祝福

查看全部評分

發表於 12-1-13 10:46 | 顯示全部樓層
回復 16# wilburwclee


    非常謝謝您   祝福
發表於 12-1-13 14:32 | 顯示全部樓層
回復 16# wilburwclee

MACD的語法很多,這組是我見過最注重細節的寫法。
發表於 12-12-22 15:27 | 顯示全部樓層
Sirius 發表於 11-10-18 20:26
已經變粗了,又想要變長

以前怎沒想過這問題?

看到這個我忍不住笑了 XD
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-4-29 20:37

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 | AI繪圖AI超擬真美女AI beauty AI Stable DiffusionAI正妹AI Lookbook