Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study(title="", shorttitle="",overlay=true)
- len = input(14, minval=1, title="DI Length")
- lensig = input(14, title="ADX Smoothing", minval=1, maxval=50)
- up = change(high)
- down = -change(low)
- plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
- minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
- trur = rma(tr, len)
- plus = fixnan(100 * rma(plusDM, len) / trur)
- minus = fixnan(100 * rma(minusDM, len) / trur)
- sum = plus + minus
- adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
- //plot(plus, color=color.blue, title="+DI")
- //plot(minus, color=color.orange, title="-DI")
- //plot(adx, color=color.red, title="ADX")
- ////////////////////////////////////////////////////////////////////////////
- fast_length = input(title="Fast Length", type=input.integer, defval=12)
- slow_length = input(title="Slow Length", type=input.integer, defval=26)
- src1 = input(title="Source", type=input.source, defval=close)
- signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
- sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=false)
- sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false)
- // Plot colors
- //col_grow_above = #26A69A
- //col_grow_below = #FFCDD2
- //col_fall_above = #B2DFDB
- //col_fall_below = #EF5350
- //col_macd = #0094ff
- //col_signal = #ff6a00
- // Calculating
- fast_ma = sma_source ? sma(src1, fast_length) : ema(src1, fast_length)
- slow_ma = sma_source ? sma(src1, slow_length) : ema(src1, slow_length)
- macd = fast_ma - slow_ma
- signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
- hist = macd - signal
- //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) ), transp=0 )
- //plot(macd, title="MACD", color=col_macd, transp=0)
- //plot(signal, title="Signal", color=col_signal, transp=0)
- ////////////////////////////////////////////////////////////////////////////
- // cond1 = (crossover(plus,minus))
- // cond2 = (crossover(macd,signal))
- // cond3 = (crossunder(plus,minus))
- // cond4 = (crossunder(macd,signal))
- cond1 = plus > minus
- cond2 = macd > signal
- cond3 = plus < minus
- cond4 = macd < signal
- var inLong = false
- enterLong = cond1 and cond2 and not inLong
- enterShort = cond3 and cond4 and inLong
- if enterLong
- inLong := true
- else
- if enterShort
- inLong := false
- //conditionbuy = cond1 and cond2 or cond1 and not cond2
- //conditionsell = cond3 and cond4 or cond3 and not cond4
- //plotshape(conditionbuy, text="BUY", style=shape.labelup,color=color.green, textcolor=color.white, location=location.belowbar, transp=0)
- //plotshape(conditionsell, text="SELL", style=shape.labeldown,color=color.red, textcolor=color.white, location=location.abovebar, transp=0)
- plotshape(cond1, "cond1", shape.circle, location.top, color.silver, text = "1", size = size.small)
- plotshape(cond2, "cond2", shape.diamond, location.top, color.orange, text = "2", size = size.tiny)
- plotshape(cond3, "cond3", shape.circle, location.bottom, color.fuchsia, text = "3", size = size.small)
- plotshape(cond4, "cond4", shape.diamond, location.bottom, color.aqua, text = "4", size = size.tiny)
- plotshape(enterLong, "enterLong", shape.triangleup, location.belowbar, color.green, 0, text = "enterLong", size = size.tiny)
- plotshape(enterShort, "enterShort", shape.triangledown, location.abovebar, color.maroon, 0, text = "enterShort", size = size.tiny)
- // Place these markers one bar late so they don't overprint the "plotshape()" triangles.
- //plotchar(cond5[1], "cond5", "⮝", location.belowbar, color.lime, 0, size = size.tiny)
- //plotchar(cond6[1], "cond6", "⮟", location.abovebar, color.red, 0, size = size.tiny)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement