练习编写第一个指标
//@version=5 ------这是一个包含编译器指令的注释,告诉编译器脚本将使用 Pine Script™ 版本 5
indicator("MACD #1") ------图表上的脚本名称定义为“MACD”
fast = 12
slow = 26
fastMA = ta.ema(close, fast) -----以收盘价计算EMA(指数移动平均),计算时间跨度为fast(26)
slowMA = ta.ema(close, slow)
macd = fastMA - slowMA
signal = ta.ema(macd, 9) ------以长度为9的ema算法平滑macd指标
plot(macd, color = color.blue) ---------画线,为macd指标,使用蓝线输出变量
plot(signal, color = color.orange)
改进代码为
//@version=5
indicator("MACD #2")
fastInput = input(12, "Fast lengthhhh") ----参数为: value, key
slowInput = input(26, "Slow lengthhhh")
[macdLine, signalLine, histLine] = ta.macd(close, fastInput, slowInput, 9)
plot(macdLine, color = color.blue)
plot(signalLine, c