157 lines
4.5 KiB
Plaintext
157 lines
4.5 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center Multpile Strategies Oscillator
|
|
// -------------------------------------------------
|
|
// saherelm implementation of above oscillator ...
|
|
//
|
|
// Maintainer:
|
|
// ------------
|
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
//
|
|
//////////////////////////////////////////////////////
|
|
|
|
//
|
|
//@version=5
|
|
indicator(title="SaherElm Multpile Strategies Oscillator", shorttitle = "XS_MPS_OSC", overlay = false)
|
|
|
|
//
|
|
// START Inputs ....
|
|
//
|
|
MPSScale = input.float(defval = 75.0, title = "General scale")
|
|
|
|
//
|
|
// Momentum ...
|
|
MPSShowMomentum = input.bool(defval = true, title = "Show Squeeze Momentum", group = "Squeeze Momentum")
|
|
MPSLengthM = input.int(defval = 17, title = "MOM Length", minval = 1, step = 1, group = "Squeeze Momentum")
|
|
MPSSrcM = input.source(defval = close, title = "MOM Source", group = "Squeeze Momentum")
|
|
MPSLength = input.int(defval = 17, title = "SQZ Length", minval = 1, step = 1, group = "Squeeze Momentum")
|
|
MPSSrc = input.source(defval = close, title="SQZ Source", group = "Squeeze Momentum")
|
|
|
|
//
|
|
// RSI ...
|
|
MPSShowRsi = input.bool(defval = true, title = "Show RSI", group = "RSI")
|
|
MPSShowRsiFondo = input.bool(defval = true, title = "Show RSI background", group = "RSI")
|
|
MPSRsiApart = input.int(defval = 0, title = "RSI Separation", group = "RSI")
|
|
MPSLen = input.int(defval = 14, minval = 1, title = "RSI Length", group = "RSI")
|
|
MPSUpperR = input.int(defval = 70, title = "RSI Upper Band", group = "RSI")
|
|
MPSMiddleR = input.int(defval = 50, title = "RSI Middle Band", group = "RSI")
|
|
MPSLowerR = input.int(defval = 30, title = "RSI Lower Band", group = "RSI")
|
|
|
|
//
|
|
// RSI DIVERGENCE ...
|
|
MPSShowRsiDivergence = input.bool(defval = false, title = "Show RSI DIVERGENCE", group = "RSI")
|
|
MPSFarRSI = input.int(defval = 70, title = "Adjust RSI DIVERGENCE", group = "RSI")
|
|
MPSLenFast = input.int(defval = 5, minval = 1, title = "Fast RSI Length", group = "RSI")
|
|
MPSLenSlow = input.int(defval = 14, minval = 1, title = "Slow RSI Length", group = "RSI")
|
|
//
|
|
// END Inputs ....
|
|
//
|
|
|
|
//
|
|
// START Functions ....
|
|
//
|
|
biggest(series) =>
|
|
max = 0.0
|
|
max := nz(max[1], series)
|
|
if series > max
|
|
max := series
|
|
max
|
|
//
|
|
// END Functions ....
|
|
//
|
|
|
|
//
|
|
// START Calculations ....
|
|
//
|
|
//
|
|
var bullishColor = color.lime
|
|
var bearishColor = color.red
|
|
|
|
//
|
|
// Momentum ...
|
|
MPSSz = ta.linreg(MPSSrcM - math.avg(math.avg(ta.highest(high, MPSLengthM), ta.lowest(low, MPSLengthM)), ta.sma(close, MPSLengthM)), MPSLengthM, 0)
|
|
MPSNi = biggest(MPSSz)
|
|
|
|
//
|
|
// Momentum Conditions ...
|
|
MPSSc1 = MPSSz >= 0
|
|
MPSSc2 = MPSSz < 0
|
|
MPSSc3 = MPSSz >= MPSSz[1]
|
|
MPSSc4 = MPSSz < MPSSz[1]
|
|
|
|
//
|
|
// Momentum Identifiers ...
|
|
isMPSMomentumBullish = (MPSSc1 and MPSSc3) or (MPSSc1 and MPSSc4)
|
|
isMPSMomentumBearish = (MPSSc2 and MPSSc4) or (MPSSc2 and MPSSc3)
|
|
|
|
//
|
|
MPSClr = isMPSMomentumBullish ? bullishColor : isMPSMomentumBearish ? bearishColor : color.gray
|
|
|
|
//
|
|
// RSI ...
|
|
MPSRsi = ta.rsi(MPSSrc, MPSLen)
|
|
MPSRsiColor = MPSRsi <= MPSLowerR ? bullishColor : MPSRsi >= MPSUpperR ? bearishColor : #da00ff
|
|
MPSRsiScale = (MPSRsi + MPSRsiApart) * MPSNi / MPSScale
|
|
|
|
//
|
|
MPSB1s = (MPSRsiApart + MPSUpperR) * MPSNi/MPSScale
|
|
MPSBm = (MPSRsiApart + MPSMiddleR) * MPSNi/MPSScale
|
|
MPSB0s = (MPSRsiApart + MPSLowerR) * MPSNi/MPSScale
|
|
|
|
//
|
|
// RSI DIVERGENCE ...
|
|
MPSSrcSlow = close
|
|
MPSSrcFast = close
|
|
|
|
//
|
|
MPSUpFast = ta.rma(math.max(ta.change(MPSSrcFast), 0), MPSLenFast)
|
|
MPSDownFast = ta.rma(-math.min(ta.change(MPSSrcFast), 0), MPSLenFast)
|
|
MPSRsiFast = MPSDownFast == 0 ? 100 : MPSUpFast == 0 ? 0 : 100 - (100 / (1 + MPSUpFast / MPSDownFast))
|
|
|
|
//
|
|
MPSUpSlow = ta.rma(math.max(ta.change(MPSSrcSlow), 0), MPSLenSlow)
|
|
MPSDownSlow = ta.rma(-math.min(ta.change(MPSSrcSlow), 0), MPSLenSlow)
|
|
MPSRsiSlow = MPSDownSlow == 0 ? 100 : MPSUpSlow == 0 ? 0 : 100 - (100 / (1 + MPSUpSlow / MPSDownSlow))
|
|
|
|
//
|
|
MPSDivergence = MPSRsiFast - MPSRsiSlow
|
|
MPSDivergenceScale = MPSDivergence * (MPSNi / MPSScale)
|
|
|
|
//
|
|
MPSDivergenceColor = MPSDivergence > 0 ? bullishColor : bearishColor
|
|
//
|
|
// END Calculations ....
|
|
//
|
|
|
|
//
|
|
// START Plots ....
|
|
//
|
|
//
|
|
// Momentum ...
|
|
plot(MPSShowMomentum ? MPSSz : na, title = "Squeeze Momentum", color = MPSClr, style = plot.style_area)
|
|
|
|
//
|
|
// RSI ...
|
|
plot(MPSShowRsi ? MPSRsiScale : na, "RSI", color = MPSRsiColor)
|
|
|
|
//
|
|
// Divergence ...
|
|
plot(MPSShowRsiDivergence ? MPSDivergenceScale + (MPSFarRSI * MPSNi / MPSScale) : na, "RSI Divergence", color = MPSDivergenceColor)
|
|
|
|
//
|
|
// END Plots ....
|
|
//
|
|
|
|
//
|
|
// START Alerts ...
|
|
//
|
|
//
|
|
// END Alerts ...
|
|
//
|
|
|
|
//////////////////////////////////////////////////////
|
|
// TODOS:
|
|
// -------
|
|
// - []
|
|
//////////////////////////////////////////////////////
|