ThinkScript of MACD

分析一下TD官方的MACD代码

颜色的预定义值查看这里:
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look—Feel/GetColor

#
# TD Ameritrade IP Company, Inc. (c) 2007-2021
#

# Study作用于lower区域
declare lower;

# 快线周期
input fastLength = 12;
# 慢线周期
input slowLength = 26;
# 信号周期
input MACDLength = 9;

# 移动平均类型 - 指数移动平均
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

# 快慢线移动平均值差 = 12天的指数移动平均 - 26天的指数移动平均
plot Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);

# 快慢线移动平均值差的9天指数平均值
plot Avg = MovingAverage(averageType, Value, MACDLength);

# 差离值 = 快慢线移动平均值差 - 快慢线移动平均值差的9天指数平均值
plot Diff = Value - Avg;

# 零轴
plot ZeroLine = 0;

# 向上的信号 = 差离值Diff向上穿过零轴
plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;

# 向下的信号 = 差离值Diff向下穿过零轴
plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;

# 开关(先忽略)
UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

# 快慢线移动平均值差设置颜色值1
Value.SetDefaultColor(GetColor(1));

# 快慢线移动平均值差9日指数移动平均先设置颜色值8
Avg.SetDefaultColor(GetColor(8));

# 差离值设置默认颜色值5
Diff.SetDefaultColor(GetColor(5));
#
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#
Diff.SetLineWeight(3);

# 定义颜色别名
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);

# 设定颜色
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));

# 零轴先设置默认颜色值0
ZeroLine.SetDefaultColor(GetColor(0));

UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值