Qantum Robot V4 Nu & Pu
//@version=4study(title="{AlyaNet} RSI + MACD", shorttitle="{A.N} RSI+MACD Divergence")len = input(title="RSI Period", minval=1, defval=7)src = input(title="RSI Source", defval=close)lbR = input(title="Pivot Lookback Right", defval=5)lbL = input(title="Pivot Lookback Left", defval=3)
rangeUpper = input(title="Max of Lookback Range", defval=60)rangeLower = input(title="Min of Lookback Range", defval=5)plotBull = input(title="Plot Bullish", defval=true)plotHiddenBull = input(title="Plot Hidden Bullish", defval=true)plotBear = input(title="Plot Bearish", defval=true)plotHiddenBear = input(title="Plot Hidden Bearish", defval=false)
bearColor = color.purplebullColor = color.greenhiddenBullColor = color.new(color.green, 80)hiddenBearColor = color.new(color.red, 80)textColor = color.whitenoneColor = color.new(color.white, 100)
osc = rsi(src, len)
plot(osc, title="RSI", linewidth=2, color=#8D1699)hline(50, title="Middle Line", linestyle=hline.style_dotted)obLevel = hline(60, title="Overbought", linestyle=hline.style_dotted)osLevel = hline(40, title="Oversold", linestyle=hline.style_dotted)fill(obLevel, osLevel, title="Background", color=#9915FF, transp=90)
plFound = na(pivotlow(osc, lbL, lbR)) ? false : truephFound = na(pivothigh(osc, lbL, lbR)) ? false : true
_inRange(cond) =>bars = barssince(cond == true)rangeLower <= bars and bars <= rangeUpper
//------------------------------------------------------------------------------// Regular Bullish
// Osc: Higher LowoscHL = osc[lbR] > valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
// Price: Lower LowpriceLL = low[lbR] < valuewhen(plFound, low[lbR], 1)
bullCond = plotBull and priceLL and oscHL and plFound
plot(plFound ? osc[lbR] : na,offset=-lbR,title="Regular Bullish",linewidth=2,color=(bullCond ? bullColor : noneColor),transp=0)
plotshape(bullCond ? osc[lbR] : na,offset=-lbR,title="Regular Bullish Label",text=" Bull ",style=shape.labelup,location=location.absolute,color=bullColor,textcolor=textColor,transp=0)
//------------------------------------------------------------------------------// Hidden Bullish
// Osc: Lower LowoscLL = osc[lbR] < valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
// Price: Higher LowpriceHL = low[lbR] > valuewhen(plFound, low[lbR], 1)
hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound
plot(plFound ? osc[lbR] : na,offset=-lbR,title="H Bullish",linewidth=2,color=(hiddenBullCond ? hiddenBullColor : noneColor),transp=0)
plotshape(hiddenBullCond ? osc[lbR] : na,offset=-lbR,title="Hidden Bullish Label",text=" H Bull ",style=shape.labelup,location=location.absolute,color=bullColor,textcolor=textColor,transp=0)
longCondition=bullCond or hiddenBullCond
//------------------------------------------------------------------------------// Regular Bearish
// Osc: Lower HighoscLH = osc[lbR] < valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
// Price: Higher HighpriceHH = high[lbR] > valuewhen(phFound, high[lbR], 1)
bearCond = plotBear and priceHH and oscLH and phFound
plot(phFound ? osc[lbR] : na,offset=-lbR,title="Regular Bearish",linewidth=2,color=(bearCond ? bearColor : noneColor),transp=0)
plotshape(bearCond ? osc[lbR] : na,offset=-lbR,title="Regular Bearish Label",text=" Bear ",style=shape.labeldown,location=location.absolute,color=bearColor,textcolor=textColor,transp=0)
//------------------------------------------------------------------------------// Hidden Bearish
// Osc: Higher HighoscHH = osc[lbR] > valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
// Price: Lower HighpriceLH = high[lbR] < valuewhen(phFound, high[lbR], 1)
hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound
plot(phFound ? osc[lbR] : na,offset=-lbR,title="H Bearish",linewidth=2,color=(hiddenBearCond ? hiddenBearColor : noneColor),transp=0)
plotshape(hiddenBearCond ? osc[lbR] : na,offset=-lbR,title="H Bearish Label",text=" H Bear ",style=shape.labeldown,location=location.absolute,color=bearColor,textcolor=textColor,transp=0)
// Getting inputsfast_length = input(title="Fast Length", type=input.integer, defval=5)slow_length = input(title="Slow Length", type=input.integer, defval=8)srcd = input(title="Source", type=input.source, defval=close)signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 3)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 colorscol_grow_above = #26A69Acol_grow_below = #FFC1D5col_fall_above = #B2DFDBcol_fall_below = #EF5550col_macd = #0094ffcol_signal = #ff6a00
// Calculatingfast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)macd = fast_ma - slow_masignal = 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)
Was this answer helpful?
Also Read
Powered by WHMCompleteSolution