策略
MAGIC-MACD
ChaoZhang · PineScript · 趋势跟踪 · 2022-05-08 17:16:51
无说明:源文件没有中文正文。
参数
| 参数 | 默认值 | 说明 |
|---|---|---|
| v_input_bool_1 | true | Enable Signal EMA=ON/MACD=OFF |
| v_input_1 | 5 | Fast Length |
| v_input_2 | 50 | Slow Length |
| v_input_3_ohlc4 | 0 | Source: ohlc4 |
| v_input_int_1 | 30 | Signal Smoothing |
| v_input_string_1 | 0 | Oscillator MA Type: EMA |
| v_input_string_2 | 0 | Signal Line MA Type: EMA |
| v_input_int_2 | 50 | Histogram Filter EMA Length |
| v_input_int_3 | 5 | EMA1 Length |
| v_input_10 | #00bc77 | EMA-1 |
| v_input_int_4 | 20 | EMA2 Length |
| v_input_11 | #00bc77 | EMA-2 |
| v_input_4 | #2962FF | (?Color Settings)MACD Line |
| v_input_5 | #FF6D00 | Signal Line |
| v_input_6 | #26A69A | (?Histogram)Above Grow |
| v_input_7 | #B2DFDB | Fall |
| v_input_8 | #FFCDD2 | Below Grow |
| v_input_9 | #ff0062 | Fall |
源码(63 行)
/*backtest
start: 2022-04-07 00:00:00
end: 2022-05-06 23:59:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
indicator(title="MAGIC MACD", shorttitle="MAGIC MACD", timeframe="", timeframe_gaps=true)
//By HARI KRISHNA
//How to use?
//1.Signal RED Arrow on green Histogram for down
//2.Signal GREEN Arrow on Red Histogram for Up
//
//3.Confirmation by Crossover
//4.Place when Histogram is not Gray
//
//5.RED on RED Histogram IGNORE
//6.GREEN on GREEN Histogram IGNORE
//Buy SELL SIGNALS on EMA CROSSOVER
// Getting inputs
enableema=input.bool(true,title='Enable Signal EMA=ON/MACD=OFF', inline="MACD")
fast_length = input(title="Fast Length", defval=5)
slow_length = input(title="Slow Length", defval=50)
src = input(title="Source", defval=ohlc4)
signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 30)
sma_source = input.string(title="Oscillator MA Type", defval="EMA", options=["SMA", "EMA"])
sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"])
// Plot colors
col_macd = input(#2962FF, "MACD Line ", group="Color Settings", inline="MACD")
col_signal = input(#FF6D00, "Signal Line ", group="Color Settings", inline="Signal")
col_grow_above = input(#26A69A, "Above Grow", group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
col_fall_below = input(#ff0062, "Fall", group="Histogram", inline="Below")
// Calculating
fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) :ta.ema(src, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) :ta.ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) :ta.ema(macd, signal_length)
hist = macd - signal
ema50=ta.ema(close,input.int(title="Histogram Filter EMA Length", defval=50,maxval=200,minval=1))
colourhist=hist>=0 and open>ema50? (hist[1] < hist ? col_grow_above : col_fall_above) :hist<=0 and open<ema50? (hist[1] < hist ? col_grow_below : col_fall_below) :#666666
plot(hist, title="Histogram", style=plot.style_columns, color=colourhist)
plot(enableema==false?macd:na, title="MACD", color=col_macd)
plot(enableema==false?signal:na, title="Signal", color=col_signal)
[macd2,signal2,hist2]=ta.macd(close,12,26,9)
ma1=ta.ema(close,input.int(title="EMA1 Length", defval=5,maxval=50,minval=1))-ta.ema(close,100)
plot(enableema==true?ma1:na, title="EMA1 -Color", color=input(#00bc77,title='EMA-1'),linewidth=2) //ema 5
ma2=ta.ema(close,input.int(title="EMA2 Length", defval=20,maxval=50,minval=1))-ta.ema(close,100)
plot(enableema==true?ma2:na, title="EMA2 -Color", color=input(#00bc77,title='EMA-2'),linewidth=2)//ema20
plotshape(ta.crossover(macd2,signal2)? 0 : na, title="Buy Signal", location=location.absolute, style=shape.triangleup, size=size.small, color=color.new(#00bc77,0))
plotshape(ta.crossunder(macd2,signal2)? 0: na, title="Sell Signal", location=location.absolute, style=shape.triangledown, size=size.small, color=color.new(#ff0d5c,0))
if ta.crossover(macd2,signal2)
strategy.entry("Enter Long", strategy.long)
else if ta.crossunder(macd2,signal2)
strategy.entry("Enter Short", strategy.short)