MACD Histogram Fast Signal

Taro_S · study · 87 行 · 点赞 5 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
indicator("MACD Histogram Fast Signal", shorttitle="MACD Hist Fast", overlay=false)
 
//====================================================
// Parameters
//====================================================
fastLength = input.int(12, "MACD Fast Length", minval=1)
slowLength = input.int(26, "MACD Slow Length", minval=1)
signalSmoothing = input.int(9, "MACD Signal Smoothing", minval=1)
maLength = input.int(5, "Histogram EMA Length", minval=1)
 
//====================================================
// MACD
//====================================================
[macdLine, signalLine, _] = ta.macd(
     close,
     fastLength,
     slowLength,
     signalSmoothing)
 
macdHist = macdLine - signalLine
 
//====================================================
// EMA of MACD Histogram
//====================================================
macdHistEMA = ta.ema(macdHist, maLength)
 
//====================================================
// Histogram Conditions
//====================================================
greenCondition = macdHist > macdHistEMA and macdHist > macdHist[1]
redCondition   = macdHist < macdHistEMA and macdHist < macdHist[1]
 
//====================================================
// Histogram Color
// 緑条件 → 緑
// 赤条件 → 赤
// それ以外 → 直前の色を維持
//====================================================
var color histColor = color.green
 
if greenCondition
    histColor := color.green
else if redCondition
    histColor := color.red
 
//====================================================
// MACD Histogram
//====================================================
plot(
     macdHist,
     title="MACD Histogram",
     color=histColor,
     linewidth=2,
     style=plot.style_columns)
 
//====================================================
// Histogram EMA
//====================================================
plot(
     macdHistEMA,
     title="EMA of MACD Histogram",
     color=color.orange,
     linewidth=1)
 
//====================================================
// MACD Line
//====================================================
plot(
     macdLine,
     title="MACD",
     color=color.blue,
     linewidth=1)
 
//====================================================
// Signal Line
//====================================================
plot(
     signalLine,
     title="Signal",
     color=color.red,
     linewidth=1)
 
//====================================================
// Zero Line
//====================================================
hline(0, "0 Line", color=color.gray)

← 返回列表