Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator(title="MACD金、死叉提示", shorttitle="MACD", timeframe="", timeframe_gaps=true)
- // Getting inputs
- //fast_length = input(title="Fast Length", defval=12) //默认输入 快线长度 12
- //slow_length = input(title="Slow Length", defval=26) //默认输入 慢线长度 26
- //src = input(title="Source", defval=close) //来源:收盘价
- signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9) //信号平滑:最小1、最大50、默认输入 9
- sma_source = input.string(title="Oscillator MA Type", defval="EMA", options=["SMA", "EMA"]) //振荡器类型、默认输入:EMA 选择输入:EMA、SMA
- sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"]) //信号线类型、默认输入:EMA 选择输入:EMA、SMA
- col_macd = input(#2962FF, "MACD Line ", group="Color Settings", inline="MACD") //选择MACD颜色
- col_signal = input(#FF6D00, "Signal Line ", group="Color Settings", inline="Signal") //选择信号颜色
- col_grow_above = input(#26A69A, "Above Grow", group="Histogram", inline="Above") //选择直方图0颜色 上面柱子深
- col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above") //选择直方图1颜色 上面柱子浅
- col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below") //选择直方图2颜色 下面柱子深
- col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below") //选择直方图3颜色 下面柱子浅
- macd = ta.ema(close,12) - ta.ema(close,26) //定义MACD值=快线 DIF
- signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length) //定义MACD值=慢线 DEM 通常是9日均线
- hist = macd - signal
- hline(0, "Zero Line", color=color.new(#787B86, 50)) //选择水平线的颜色
- plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below)))
- plot(macd, title="MACD", color=col_macd)
- plot(signal, title="Signal", color=col_signal)
- //金叉死叉
- jin = ta.crossover(macd,signal)
- si = ta.crossunder(macd,signal)
- //触发条件、和在屏幕上显示:“金”、“死”
- plotchar(jin?macd:na,char="金",location = location.absolute,color = color.blue,size = size.tiny)
- plotchar(si?macd:na,char="死",location = location.absolute,color = color.red,size = size.tiny)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement