This is the part 1 of Rain On Me PRO. It follow my two other indicators “Rain On Me” and “Rain On Me V2”. This version is called “PRO” because it is less “user-friendly” than my two previous versions. But the indicator load more faster, and it’s cleaner than ever! This indicator is separated into 3 parts. You can find all parts here in the “free indicators” menu or into my Tradingview profile in the « Scripts » section. Once the 3 parts together, the indicator is ready.
Rain On Me PRO 1/3 in action on Nasdaq Index.

Here is the complete list of indicators present in this indicator :
- ATR with alerts (buy and sell signals)
- Efficient Doji detection system
- Multiple Divergence Type (MACD, Volume, RSI, CCI)
- Efficient Bullish and Bearish Engulfing Candle detection system with alerts
- 3 Moving Averages with alerts and “cross label displaying” for MA1 and MA2 (Multiple type of MA Filter)
- MA Bias Forecasting with 2 sources type available (“Same as MA” or “Linear Regression”)
- RSI Filter bar coloring with configurable OB/OS factor
All indicators have their original default settings. You need to be able to readjust them depending on the market instrument you want to analyze. You have the possibility to put alerts which will notify you when an indicator gives a new signal. When placing an alert, be sure to choose the “once per bar” option each time you place an alert.
Or copy / paste the source code into your pine editor :
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © RickSimpson //@version=4 study(title="Rain On Me PRO 1/3", shorttitle='ROM PRO 1/3', overlay=true, max_bars_back=300) //Inputs showatr = input(defval=true, title="Show ATR?") showdoji = input(defval=false, title="Show Doji?") showeng = input(defval=false, title="Show Engulfing Candles?") showpullback = input(defval=false, title="Show Reversal Candles?") showdivs = input(defval=true, title="Show Divergences?") showmacross = input(defval=false, title="Show MA1 and MA2 Cross?") showrsifilter = input(defval=false, title="Show RSI Filter Bar Color?") //ATR //Inputs atrper = input(defval=14, title="ATR Period", minval=1) atrmult = input(defval=2, title="ATR Multiplier", minval=0.5, maxval=100, step=0.1) atrlookahead = input(defval=false, title="Show Only Confirmed ATR Signals?") showatrsltp = input(defval=false, title="Show ATR Take Profit 1?") atrtakeper = input(defval=1, title='ATR TP 1 (%)', type=input.float, minval=0, maxval=100, step=0.1) / 100 showatrtp2 = input(defval=false, title="Show ATR Take Profit 2?") atrtakeper2 = input(defval=2, title='ATR TP 2 (%)', type=input.float, minval=0, maxval=100, step=0.1) / 100 showatrtp3 = input(defval=false, title="Show ATR Take Profit 3?") atrtakeper3 = input(defval=3, title='ATR TP 3 (%)', type=input.float, minval=0, maxval=100, step=0.1) / 100 //Calculation natr = atr(atrper) nloss = atrmult * natr atrsrc = open > close ? low : high natrtrailingstop = 0.0 natrtrailingstop := iff(atrsrc > nz(natrtrailingstop[1], 0) and atrsrc[1] > nz(natrtrailingstop[1], 0), max(nz(natrtrailingstop[1]), atrsrc - nloss), iff(atrsrc < nz(natrtrailingstop[1], 0) and atrsrc[1] < nz(natrtrailingstop[1], 0), min(nz(natrtrailingstop[1]), atrsrc + nloss), iff(atrsrc > nz(natrtrailingstop[1], 0), atrsrc - nloss, atrsrc + nloss))) pos = 0 pos := iff(atrsrc[1] < nz(natrtrailingstop[1], 0) and atrsrc > nz(natrtrailingstop[1], 0), 1, iff(atrsrc[1] > nz(natrtrailingstop[1], 0) and atrsrc < nz(natrtrailingstop[1], 0), -1, nz(pos[1], 0))) //Settings atrma = ema(atrsrc, 1) atrabove = crossover(atrma, natrtrailingstop) atrbelow = crossover(natrtrailingstop, atrma) atrsell = atrsrc < natrtrailingstop and atrbelow atrbuy = atrsrc > natrtrailingstop and atrabove atrselld = atrlookahead ? atrsell[1] : atrsell atrbuyd = atrlookahead ? atrbuy[1] : atrbuy //ATR TP Calculation atrstopper = 100 / 100 atrls = 0 atrllast = atrbuyd and (nz(atrls[1]) == 0 or nz(atrls[1]) == -1) atrslast = atrselld and (nz(atrls[1]) == 0 or nz(atrls[1]) == 1) atrls := atrllast ? 1 : atrslast ? -1 : atrls[1] atrlprice = valuewhen(atrllast, close, 0) atrsprice = valuewhen(atrslast, close, 0) atrlstop = atrlprice * (1 - atrstopper) atrsstop = atrsprice * (1 + atrstopper) atrltake = atrlprice * (1 + atrtakeper) atrstake = atrsprice * (1 - atrtakeper) atrlbar1 = barssince(atrllast) atrlbar2 = atrlbar1 >= 1 ? true : false atrsbar1 = barssince(atrslast) atrsbar2 = atrsbar1 >= 1 ? true : false atrlslh = atrls == 1 and atrlbar2 and low < atrlstop atrsslh = atrls == -1 and atrsbar2 and high > atrsstop atrltph = atrls == 1 and atrlbar2 and high > atrltake atrstph = atrls == -1 and atrsbar2 and low < atrstake atrls := (atrls == 1 or atrls == 0) and atrlbar2 and (atrlslh or atrltph) ? 0 : (atrls == -1 or atrls == 0) and atrsbar2 and (atrsslh or atrstph) ? 0 : atrls atrls_2 = 0 atrllast_2 = atrbuyd and (nz(atrls_2[1]) == 0 or nz(atrls_2[1]) == -1) atrslast2 = atrselld and (nz(atrls_2[1]) == 0 or nz(atrls_2[1]) == 1) atrls_2 := atrllast_2 ? 1 : atrslast2 ? -1 : atrls_2[1] atrlprice2 = valuewhen(atrllast_2, close, 0) atrsprice2 = valuewhen(atrslast2, close, 0) atrls_2top = atrlprice2 * (1 - atrstopper) atrsstop2 = atrsprice2 * (1 + atrstopper) atrltake2 = atrlprice2 * (1 + atrtakeper2) atrstake2 = atrsprice2 * (1 - atrtakeper2) atrlbar1_2 = barssince(atrllast_2) atrlbar2_2 = atrlbar1_2 >= 1 ? true : false atrsbar1_2 = barssince(atrslast2) atrsbar2_2 = atrsbar1_2 >= 1 ? true : false atrls_2lh_2 = atrls_2 == 1 and atrlbar2_2 and low < atrls_2top atrsslh_2 = atrls_2 == -1 and atrsbar2_2 and high > atrsstop2 atrltph_2 = atrls_2 == 1 and atrlbar2_2 and high > atrltake2 atrstph_2 = atrls_2 == -1 and atrsbar2_2 and low < atrstake2 atrls_2 := (atrls_2 == 1 or atrls_2 == 0) and atrlbar2_2 and (atrls_2lh_2 or atrltph_2) ? 0 : (atrls_2 == -1 or atrls_2 == 0) and atrsbar2_2 and (atrsslh_2 or atrstph_2) ? 0 : atrls_2 atrls_3 = 0 atrllast_3 = atrbuyd and (nz(atrls_3[1]) == 0 or nz(atrls_3[1]) == -1) atrslast3 = atrselld and (nz(atrls_3[1]) == 0 or nz(atrls_3[1]) == 1) atrls_3 := atrllast_3 ? 1 : atrslast3 ? -1 : atrls_3[1] atrlprice3 = valuewhen(atrllast_3, close, 0) atrsprice3 = valuewhen(atrslast3, close, 0) atrls_3top = atrlprice3 * (1 - atrstopper) atrsstop3 = atrsprice3 * (1 + atrstopper) atrltake3 = atrlprice3 * (1 + atrtakeper3) atrstake3 = atrsprice3 * (1 - atrtakeper3) atrlbar1_3 = barssince(atrllast_3) atrlbar2_3 = atrlbar1_3 >= 1 ? true : false atrsbar1_3 = barssince(atrslast3) atrsbar2_3 = atrsbar1_3 >= 1 ? true : false atrls_3lh_3 = atrls_3 == 1 and atrlbar2_3 and low < atrls_3top atrsslh_3 = atrls_3 == -1 and atrsbar2_3 and high > atrsstop3 atrltph_3 = atrls_3 == 1 and atrlbar2_3 and high > atrltake3 atrstph_3 = atrls_3 == -1 and atrsbar2_3 and low < atrstake3 atrls_3 := (atrls_3 == 1 or atrls_3 == 0) and atrlbar2_3 and (atrls_3lh_3 or atrltph_3) ? 0 : (atrls_3 == -1 or atrls_3 == 0) and atrsbar2_3 and (atrsslh_3 or atrstph_3) ? 0 : atrls_3 //Plotting plotshape(showatr ? atrselld : na, title="ATR Sell", style=shape.labeldown, location=location.abovebar, size=size.tiny, text="atr", textcolor=color.white, color=color.red, transp=0) plotshape(showatr ? atrbuyd : na, title="ATR Buy", style=shape.labelup, location=location.belowbar, size=size.tiny, text="atr", textcolor=color.white, color=color.green, transp=0) plotshape(showatrsltp ? atrstph : na, style=shape.labelup, location=location.belowbar, color=color.yellow, size=size.tiny, title="ATR Sell TP", text="TP 1", textcolor=color.black) plotshape(showatrsltp ? atrltph : na, style=shape.labeldown, location=location.abovebar, color=color.yellow, size=size.tiny, title="ATR Buy TP", text="TP 1", textcolor=color.black) plotshape(showatrtp2 ? atrstph_2 : na, style=shape.labelup, location=location.belowbar, color=color.yellow, size=size.tiny, title="ATR Sell TP 2", text="TP 2", textcolor=color.black) plotshape(showatrtp2 ? atrltph_2 : na, style=shape.labeldown, location=location.abovebar, color=color.yellow, size=size.tiny, title="ATR Buy TP 2", text="TP 2", textcolor=color.black) plotshape(showatrtp3 ? atrstph_3 : na, style=shape.labelup, location=location.belowbar, color=color.yellow, size=size.tiny, title="ATR Sell TP 3", text="TP 3", textcolor=color.black) plotshape(showatrtp3 ? atrltph_3 : na, style=shape.labeldown, location=location.abovebar, color=color.yellow, size=size.tiny, title="ATR Buy TP 3", text="TP 3", textcolor=color.black) //Alerts alertcondition(atrselld, title="ATR Sell", message='ATR Sell') alertcondition(atrbuyd, title="ATR Buy", message='ATR Buy') alertcondition(atrstph, title="ATR Sell Take Profit 1", message='ATR Sell Take Profit 1') alertcondition(atrltph, title="ATR Buy Take Profit 1", message='ATR Buy Take Profit 1') alertcondition(atrstph_2, title="ATR Sell Take Profit 2", message='ATR Sell Take Profit 2') alertcondition(atrltph_2, title="ATR Buy Take Profit 2", message='ATR Buy Take Profit 2') alertcondition(atrstph_3, title="ATR Sell Take Profit 3", message='ATR Sell Take Profit 3') alertcondition(atrltph_3, title="ATR Buy Take Profit 3", message='ATR Buy Take Profit 3') //Doji //Settings dojidelta = close - open dojigp = open - close[1] dojiup = dojidelta >= 0 dojihigh = dojiup ? high - close : high - open dojilow = dojiup ? open - low : close - low //Calculation cfdojidelta = dojidelta < 0 ? -dojidelta : dojidelta dojiavg = (cfdojidelta + cfdojidelta[1] + cfdojidelta[2] + cfdojidelta[3] + cfdojidelta[4] + cfdojidelta[5] + cfdojidelta[6] + cfdojidelta[7] + cfdojidelta[8] + cfdojidelta[9]) / 10 iupdojim1 = dojidelta * 10 < cfdojidelta and high - low > cfdojidelta * 10 and dojidelta[1] < 0 dndojim1 = dojidelta * 10 < cfdojidelta and high - low > cfdojidelta * 10 and dojidelta[1] > 0 updojim2 = dojidelta * 10 < cfdojidelta and dojilow * 10 < cfdojidelta and dojihigh > cfdojidelta * 5 and dojidelta[1] < 0 dndojim2 = dojidelta * 10 < cfdojidelta and dojihigh * 10 < cfdojidelta and dojilow > cfdojidelta * 5 and dojidelta[1] > 0 //Plotting plotshape(showdoji ? dndojim1 : na, text="doji", style=shape.triangledown, location=location.abovebar, color=color.red) plotshape(showdoji ? dndojim1 : na, text="doji", style=shape.triangledown, location=location.abovebar, color=color.red) plotshape(showdoji ? iupdojim1 : na, text="doji", style=shape.triangleup, location=location.belowbar, color=color.green) plotshape(showdoji ? dndojim2 : na, text="doji", style=shape.triangledown, location=location.abovebar, color=color.red) plotshape(showdoji ? dndojim2 : na, text="doji", style=shape.triangledown, location=location.abovebar, color=color.red) plotshape(showdoji ? updojim2 : na, text="doji", style=shape.triangleup, location=location.belowbar, color=color.green) //Reversal & Engulfing Candles //Settings tsh = true pbma1 = ema(close, 13) pbma2 = ema(close, 21) pbma3 = ema(close, 34) pbma = ema(close, 89) pbr = tr pbrma = ema(pbr, 89) pbu = pbma + pbrma * 0.5 pbl = pbma - pbrma * 0.5 pbc = (pbu+ pbl) / 2 //Calculation pbtru = pbma1 > pbu and pbma2 > pbu and pbma3 > pbu pbtrd = pbma1 < pbl and pbma2 < pbl and pbma3 < pbl pullbackbull() => pbtru and close < pbu pbdflt() => pbtrd and close > pbl engu() => pbtru and close[1] < pbu and close > pbu engd() => pbtrd and close[1] > pbl and close < pbl engurend = pbma1 > pbu and pbma2 > pbu and pbma3 > pbu and close[1] < pbu and close > pbu ? 1 : 0 engdrend = pbma1 < pbl and pbma2 < pbl and pbma3 < pbl and close[1] > pbl and close < pbl ? 1 : 0 engutr = pbma1 > pbu and pbma2 > pbu and pbma3 > pbu engdtr = pbma1 < pbl and pbma2 < pbl and pbma3 < pbl engb = engurend == 1 ? engurend : 0 engs = engdrend == 1 ? engdrend : 0 pbdfl = pbdflt() barcolor(showpullback and pullbackbull() ? color.yellow : showpullback and pbdfl ? color.yellow : na) engisd = engd() barcolor(showeng and engu() ? color.aqua : showeng and engisd ? color.fuchsia : na) //Plotting plotarrow(showeng and tsh and engb ? engb : na, title="Bullish Engulfing", colorup=color.aqua, maxheight=5, minheight=10, transp=0) plotarrow(showeng and tsh and engs * -1 ? engs * -1 : na, title="Bearish Engulfing", colordown=color.fuchsia, maxheight=5, minheight=10, transp=0) plotchar(showeng and engb ? low - tr : na, title="Bullish Engulfing", char='↑', offset=0, text="bullish engulfing", textcolor=color.aqua, location=location.belowbar, color=color.aqua, transp=0) plotchar(showeng and engs ? high + tr : na, title="Bearish Engulfing", char='↑', offset=0, text="bearish engulfing", textcolor=color.fuchsia, location=location.abovebar, color=color.fuchsia, transp=0) //Alerts alertcondition(engb ? low - tr : na, title="Bullish Engulfing", message='Bullish Engulfing') alertcondition(engs ? high + tr : na, title="Bearish Engulfing", message='Bearish Engulfing') //Divergences //Inputs divtype = input(title="Divergences Type", defval='MACD', options=['MACD','VOLUME','RSI','CCI']) //Settings highdivsrc = high lowdivsrc = low macddivsrc = close macddivfast = 12 macddivslow = 26 macddivsmooth = 9 volumedivlength = 5 rsidivlength = 5 ccidivlength = 5 //Calculation f_top_fractal(_src) => _src[4] < _src[2] and _src[3] < _src[2] and _src[2] > _src[1] and _src[2] > _src[0] f_bot_fractal(_src) => _src[4] > _src[2] and _src[3] > _src[2] and _src[2] < _src[1] and _src[2] < _src[0] f_fractalize(_src) => f_bot_fractal__1 = f_bot_fractal(_src) f_top_fractal(_src) ? 1 : f_bot_fractal__1 ? -1 : 0 f_macd(_src, _fast, _slow, _smooth) => _fast_ma = sma(_src, _fast) _slow_ma = sma(_src, _slow) _macd = _fast_ma - _slow_ma _signal = ema(_macd, _smooth) _hist = _macd - _signal _hist f_volume(_smooth) => _return = sma(cum(close == high and close == low or high == low ? 0 : (2 * close - low - high) / (high - low) * volume), _smooth) _return osch = float(na) oscl = float(na) if divtype == 'MACD' osch := f_macd(macddivsrc, macddivfast, macddivslow, macddivsmooth) oscl := f_macd(macddivsrc, macddivfast, macddivslow, macddivsmooth) oscl if divtype == 'VOLUME' osch := f_volume(volumedivlength) oscl := f_volume(volumedivlength) oscl if divtype == 'RSI' osch := rsi(highdivsrc, rsidivlength) oscl := rsi(lowdivsrc, rsidivlength) if divtype == 'CCI' osch := cci(highdivsrc, ccidivlength) oscl := cci(lowdivsrc, ccidivlength) fract = f_fractalize(osch) > 0 ? osch[2] : na fracb = f_fractalize(oscl) < 0 ? oscl[2] : na hprv = valuewhen(fract, osch[2], 0)[2] hp = valuewhen(fract, high[2], 0)[2] lprv = valuewhen(fracb, oscl[2], 0)[2] lp = valuewhen(fracb, low[2], 0)[2] bearishdiv = fract and high[2] > hp and osch[2] < hprv bullishdiv = fracb and low[2] < lp and oscl[2] > lprv //Plotting plot(title="Bearish Divergence", series=(showdivs and fracb) ? low[2] : na, color=bullishdiv ? color.lime : na, linewidth=2, offset=-2) plot(title="Bullish Divergence", series=(showdivs and fract) ? high[2] : na, color=bearishdiv ? color.red : na, linewidth=2, offset=-2) //Alerts alertcondition(bearishdiv, title="Bearish Divergence", message='Bearish Divergence') alertcondition(bullishdiv, title="Bullish Divergence", message='Bullish Divergence') //Moving Average //Inputs masrcl = input(defval=close, title="MA Source") ma1period = input(defval=7, title="MA1 Period", minval=7) ma1type = input(defval="WMA", title="MA1 Type", options=["SMA","EMA","DEMA","TEMA","ZLEMA","WMA","SMMA","VAMA","VWMA","HMA","ALMA","JMA","FRAMA","Donchian","KijunSource","LSMA","Triangular","SuperSmooth","KAMA","GF","DSMA","Median","McGinley"]) ma2period = input(defval=21, title="MA2 Period", minval=7) ma2type = input(defval="WMA", title="MA2 Type", options=["SMA","EMA","DEMA","TEMA","ZLEMA","WMA","SMMA","VAMA","VWMA","HMA","ALMA","JMA","FRAMA","Donchian","KijunSource","LSMA","Triangular","SuperSmooth","KAMA","GF","DSMA","Median","McGinley"]) ma3period = input(defval=200, title="MA3 Period", minval=7) ma3type = input(defval="SMA", title="MA3 Type", options=["SMA","EMA","DEMA","TEMA","ZLEMA","WMA","SMMA","VAMA","VWMA","HMA","ALMA","JMA","FRAMA","Donchian","KijunSource","LSMA","Triangular","SuperSmooth","KAMA","GF","DSMA","Median","McGinley"]) ma1 = input(defval=true, title="Show MA1?") ma2 = input(defval=true, title="Show MA2?") ma3 = input(defval=false, title="Show MA3?") maforecasting = input(defval=false, title="Show MA Forecasting?") forecasttype = input(defval="Linear Regression", title="MA Forecast Bias", options=["MA Source", "Linear Regression"]) //Settings realtimeforecast = true lnperiod = 3 mavp = 51 maframafast = 1 maframaslow = 200 makfl = 2 maksl = 30 ma_alma_offset = 0.85 ma_alma_sigma = 6 ma_power = 1 ma_phase = 50 ma_s_maoffset = 0 ma_pn = 4 ma_percentage = 50 ma_phaseratio = ma_phase < -100 ? 0.5 : ma_phase > 100 ? 2.5 : ma_phase / 100 + 1.5 ma_beta = 0.45 * (ma1period * ma2period * ma3period - 1) / (0.45 * (ma1period * ma2period * ma3period - 1) + 2) ma_beta_s = pow(ma_beta, ma_power) get_jurik(_masrclink, _ma1period, ma_phase, ma_power) => ma_phaseratio = ma_phase < -100 ? 0.5 : ma_phase > 100 ? 2.5 : ma_phase / 100 + 1.5 ma_beta = 0.45 * (_ma1period - 1) / (0.45 * (_ma1period - 1) + 2) ma_beta_s = pow(ma_beta, ma_power) jma = 0.0 e0 = 0.0 e0 := (1 - ma_beta_s) * _masrclink + ma_beta_s * nz(e0[1]) e1 = 0.0 e1 := (_masrclink - e0) * (1 - ma_beta) + ma_beta * nz(e1[1]) e2 = 0.0 e2 := (e0 + ma_phaseratio * e1 - nz(jma[1])) * pow(1 - ma_beta_s, 2) + pow(ma_beta_s, 2) * nz(e2[1]) jma := e2 + nz(jma[1]) jma donchian(_ma1period) => avg(lowest(_ma1period), highest(_ma1period)) PI = 2 * asin(1) tau = 2 * PI S(_masrclink, _ma1period) => arg = sqrt(2) * PI / _ma1period a1 = exp(-arg) b1 = 2 * a1 * cos(arg) c2 = b1 c3 = -pow(a1, 2) c1 = 1 - c2 - c3 ssf = 0.0 ssf := c1 * (_masrclink + nz(_masrclink[1])) / 2 + c2 * nz(ssf[1]) + c3 * nz(ssf[2]) KAMA(_masrclink, _ma1period) => mom = abs(change(_masrclink, _ma1period)) volatility = sum(abs(change(_masrclink)), _ma1period) er = volatility != 0 ? mom / volatility : 0 fastma_beta_s = 0.666 slowma_beta_s = 0.0645 sc = pow(er * (fastma_beta_s - slowma_beta_s) + slowma_beta_s, 2) kama = 0.0 kama := sc * _masrclink + (1 - sc) * nz(kama[1]) VAMA(_masrclink, _ma1period) => mavol = ema(_masrclink, _ma1period) madev = _masrclink - mavol mavu = highest(madev, mavp) mavd = lowest(madev, mavp) maok = mavol + avg(mavu, mavd) FRAMA(_masrclink, _ma1period) => int maframalen = _ma1period / 2 mafe = 2.7182818284590452353602874713527 mafw = log(2 / (maframaslow +1)) / log(mafe) mafH1 = highest(high, maframalen) mafL1 = lowest(low, maframalen) mafN1 = (mafH1 - mafL1) / maframalen mafH2_ = highest(high, maframalen) mafH2 = mafH2_[maframalen] mafL2_ = lowest(low, maframalen) mafL2 = mafL2_[maframalen] mafN2 = (mafH2 - mafL2) / maframalen mafH3 = highest(high, _ma1period) mafL3 = lowest(low, _ma1period) mafN3 = (mafH3 - mafL3) / _ma1period madin0 = (log(mafN1 + mafN2) - log(mafN3)) / log(2) madin = iff(mafN1 > 0 and mafN2 > 0 and mafN3 > 0, madin0, nz(madin0[1])) madst = exp(mafw * (madin -1)) maoda = madst > 1 ? 1 : (madst < 0.01 ? 0.01 : madst) maodc = (2 -maoda) / maoda mafcalc = (((maframaslow - maframafast) * (maodc -1)) / (maframaslow -1)) + maframafast maalpha = 2 / (mafcalc +1) alpha = maalpha < 2 / (maframaslow +1) ? 2 / (maframaslow +1) : (maalpha > 1 ? 1 : maalpha) frama = 0.0 frama :=(1 - alpha) * nz(frama[1]) + alpha * _masrclink maok = frama bet = (1 - cos(2 * PI / ma1period)) / (pow(2, 1 / ma1period) - 1) alph = -bet + sqrt(pow(bet, 2) + 2 * bet) getGF(poles) => filter = 0.0 if poles == 1 filter := alph * masrcl + (1 - alph) * nz(filter[1]) if poles == 2 filter := pow(alph, 2) * masrcl + 2 * (1 - alph) * nz(filter[1]) - pow(1 - alph, 2) * nz(filter[2]) if poles == 3 filter := pow(alph, 3) * masrcl + 3 * (1 - alph) * nz(filter[1]) - 3 * pow(1 - alph, 2) * nz(filter[2]) + pow(1 - alph, 3) * nz(filter[3]) if poles == 4 filter := pow(alph, 4) * masrcl + 4 * (1 - alph) * nz(filter[1]) - 6 * pow(1 - alph, 2) * nz(filter[2]) + 4 * pow(1 - alph, 3) * nz(filter[3]) - pow(1 - alph, 4) * nz(filter[4]) filter gf = getGF(ma_pn) D(_masrclink, _ma1period) => A1 = exp(-sqrt(2) * PI) / (0.5 * _ma1period) b1 = 2 * A1 * cos(sqrt(2) * PI / (0.5 * _ma1period)) c2 = b1 c3 = - A1 * A1 c1 = 1 - c2 - c3 Zeros = _masrclink - _masrclink[2] DSMA = 0.0 ma_beta_s1 = 0.0 Filt = 0.0 Filt := c1 * (Zeros + Zeros[1]) / 2 + c2 * nz(Filt[1]) + c3 * nz(Filt[2]) RMS = stdev(Filt, _ma1period) ScaledFilt = Filt / RMS ma_beta_s1 := (abs(ScaledFilt) * 5) / _ma1period DSMA := (ma_beta_s1 * _masrclink) + (( 1 - ma_beta_s1) * nz(DSMA[1])) M(_masrclink, _ma1period)=> mg = 0.0 mg := na(mg[1]) ? ema(_masrclink, _ma1period) : mg[1] + (_masrclink - mg[1]) / (_ma1period * pow(_masrclink / mg[1], 4)) mg _ma1(_ma1type, _masrclink, _ma1period) => float result = 0 if _ma1type=="SMA" result := sma(_masrclink, _ma1period) if _ma1type=="EMA" result := ema(_masrclink, _ma1period) if _ma1type=="DEMA" EMA1=ema(_masrclink, _ma1period) EMA2=ema(EMA1, _ma1period) result := 2 * EMA1 - EMA2 if _ma1type=="TEMA" xEMA1 = ema(_masrclink, _ma1period) xEMA2 = ema(xEMA1, _ma1period) xEMA3 = ema(xEMA2, _ma1period) result := 3 * xEMA1 - 3 * xEMA2 + xEMA3 if _ma1type=="ZLEMA" lag = floor((_ma1period - 1) / 2) result := ema(_masrclink + (_masrclink - _masrclink[lag]), _ma1period) if _ma1type=="WMA" result := wma(_masrclink, _ma1period) if _ma1type=="SMMA" w = wma(_masrclink, _ma1period) result := na(w[1]) ? sma(_masrclink, _ma1period) : (w[1] * (_ma1period - 1) + _masrclink) / _ma1period if _ma1type=="VWMA" result := vwma(_masrclink, _ma1period) if _ma1type=="HMA" result := wma(2 * wma(_masrclink, _ma1period / 2) - wma(_masrclink, _ma1period), round(sqrt(_ma1period))) if _ma1type=="ALMA" result := alma(_masrclink, _ma1period, ma_alma_offset, ma_alma_sigma) if _ma1type=="JMA" result := get_jurik(_masrclink, _ma1period, ma_phase, ma_power) if _ma1type=="Donchian" result := donchian(_ma1period) if _ma1type=="KijunSource" result:=(highest(_masrclink, _ma1period) + lowest(_masrclink, _ma1period)) / 2 if _ma1type=="LSMA" result := linreg(_masrclink, _ma1period, ma_s_maoffset) if _ma1type=="Triangular" result := sma(sma(_masrclink, ceil(_ma1period / 2)), floor(_ma1period / 2) + 1) if _ma1type=="SuperSmooth" result := S(_masrclink, _ma1period) if _ma1type=="KAMA" result := KAMA(_masrclink, _ma1period) if _ma1type=="GF" result := gf if _ma1type=="DSMA" result := D(_masrclink, _ma1period) if _ma1type=="Median" result:= percentile_nearest_rank(_masrclink, _ma1period, ma_percentage) if _ma1type=="McGinley" result:= M(_masrclink, _ma1period) if _ma1type=="VAMA" result:= VAMA(_masrclink, _ma1period) if _ma1type=="FRAMA" result:= FRAMA(_masrclink, _ma1period) result get_jurik2(_masrclink, _ma2period, ma_phase, ma_power) => ma_phaseratio = ma_phase < -100 ? 0.5 : ma_phase > 100 ? 2.5 : ma_phase / 100 + 1.5 ma_bet2a = 0.45 * (_ma2period - 1) / (0.45 * (_ma2period - 1) + 2) ma_bet2a_s = pow(ma_bet2a, ma_power) jma = 0.0 e0 = 0.0 e0 := (1 - ma_bet2a_s) * _masrclink + ma_bet2a_s * nz(e0[1]) e1 = 0.0 e1 := (_masrclink - e0) * (1 - ma_bet2a) + ma_bet2a * nz(e1[1]) e2 = 0.0 e2 := (e0 + ma_phaseratio * e1 - nz(jma[1])) * pow(1 - ma_bet2a_s, 2) + pow(ma_bet2a_s, 2) * nz(e2[1]) jma := e2 + nz(jma[1]) jma donchian2(_ma2period) => avg(lowest(_ma2period), highest(_ma2period)) PI2 = 2 * asin(1) tau2 = 2 * PI2 S2(_masrclink, _ma2period) => arg = sqrt(2) * PI2 / _ma2period a1 = exp(-arg) b1 = 2 * a1 * cos(arg) c2 = b1 c3 = -pow(a1, 2) c1 = 1 - c2 - c3 ssf = 0.0 ssf := c1 * (_masrclink + nz(_masrclink[1])) / 2 + c2 * nz(ssf[1]) + c3 * nz(ssf[2]) KAMA2(_masrclink, _ma2period) => mom = abs(change(_masrclink, _ma2period)) volatility = sum(abs(change(_masrclink)), _ma2period) er = volatility != 0 ? mom / volatility : 0 fastma_bet2a_s = 0.666 slowma_bet2a_s = 0.0645 sc = pow(er * (fastma_bet2a_s - slowma_bet2a_s) + slowma_bet2a_s, 2) KAMA2 = 0.0 KAMA2 := sc * _masrclink + (1 - sc) * nz(KAMA2[1]) VAMA2(_masrclink, _ma2period) => mavol = ema(_masrclink, _ma2period) madev = _masrclink - mavol mavu = highest(madev, mavp) mavd = lowest(madev, mavp) maok = mavol + avg(mavu, mavd) FRAMA2(_masrclink, _ma2period) => int maframalen = _ma2period / 2 mafe = 2.7182818284590452353602874713527 mafw = log(2 / (maframaslow +1)) / log(mafe) mafH1 = highest(high, maframalen) mafL1 = lowest(low, maframalen) mafN1 = (mafH1 - mafL1) / maframalen mafH2_ = highest(high, maframalen) mafH2 = mafH2_[maframalen] mafL2_ = lowest(low, maframalen) mafL2 = mafL2_[maframalen] mafN2 = (mafH2 - mafL2) / maframalen mafH3 = highest(high, _ma2period) mafL3 = lowest(low, _ma2period) mafN3 = (mafH3 - mafL3) / _ma2period madin0 = (log(mafN1 + mafN2) - log(mafN3)) / log(2) madin = iff(mafN1 > 0 and mafN2 > 0 and mafN3 > 0, madin0, nz(madin0[1])) madst = exp(mafw * (madin -1)) maoda = madst > 1 ? 1 : (madst < 0.01 ? 0.01 : madst) maodc = (2 - maoda) / maoda mafcalc = (((maframaslow - maframafast) * (maodc -1)) / (maframaslow -1)) + maframafast maalpha = 2 / (mafcalc +1) alpha = maalpha < 2 / (maframaslow +1) ? 2 / (maframaslow +1) : (maalpha > 1 ? 1 : maalpha) frama = 0.0 frama :=(1 - alpha) * nz(frama[1]) + alpha * _masrclink maok = frama bet2 = (1 - cos(2 * PI2 / ma2period)) / (pow(2, 1 / ma2period) - 1) alph2 = -bet2 + sqrt(pow(bet2, 2) + 2 * bet2) getgf22(poles) => filter = 0.0 if poles == 1 filter := alph2 * masrcl + (1 - alph2) * nz(filter[1]) if poles == 2 filter := pow(alph2, 2) * masrcl + 2 * (1 - alph2) * nz(filter[1]) - pow(1 - alph2, 2) * nz(filter[2]) if poles == 3 filter := pow(alph2, 3) * masrcl + 3 * (1 - alph2) * nz(filter[1]) - 3 * pow(1 - alph2, 2) * nz(filter[2]) + pow(1 - alph2, 3) * nz(filter[3]) if poles == 4 filter := pow(alph2, 4) * masrcl + 4 * (1 - alph2) * nz(filter[1]) - 6 * pow(1 - alph2, 2) * nz(filter[2]) + 4 * pow(1 - alph2, 3) * nz(filter[3]) - pow(1 - alph2, 4) * nz(filter[4]) filter gf2 = getgf22(ma_pn) D2(_masrclink,_ma2period) => A1 = exp(-sqrt(2) * PI2) / (0.5 * _ma2period) b1 = 2 * A1 * cos(sqrt(2) * PI2 / (0.5 * _ma2period)) c2 = b1 c3 = - A1 * A1 c1 = 1 - c2 - c3 Zeros = _masrclink - _masrclink[2] DSMA = 0.0 ma_bet2a_s1 = 0.0 Filt = 0.0 Filt := c1 * ( Zeros + Zeros[1] )/2 + c2 * nz(Filt[1]) + c3 *nz(Filt[2]) RMS = stdev(Filt, _ma2period) ScaledFilt = Filt / RMS ma_bet2a_s1 := (abs(ScaledFilt) * 5) / _ma2period DSMA := (ma_bet2a_s1 * _masrclink) + (( 1 - ma_bet2a_s1 ) * nz(DSMA[1])) M2(_masrclink, _ma2period)=> mg = 0.0 mg := na(mg[1]) ? ema(_masrclink, _ma2period) : mg[1] + (_masrclink - mg[1]) / (_ma2period * pow(_masrclink/mg[1], 4)) mg _ma2(_ma2type, _masrclink, _ma2period) => float result = 0 if _ma2type=="SMA" result := sma(_masrclink, _ma2period) if _ma2type=="EMA" result := ema(_masrclink, _ma2period) if _ma2type=="DEMA" EMA1=ema(_masrclink, _ma2period) EMA2=ema(EMA1, _ma2period) result := 2 * EMA1 - EMA2 if _ma2type=="TEMA" xEMA1 = ema(_masrclink, _ma2period) xEMA2 = ema(xEMA1, _ma2period) xEMA3 = ema(xEMA2, _ma2period) result := 3 * xEMA1 - 3 * xEMA2 + xEMA3 if _ma2type=="ZLEMA" lag = floor((_ma2period - 1) / 2) result := ema(_masrclink + (_masrclink - _masrclink[lag]), _ma2period) if _ma2type=="WMA" result := wma(_masrclink, _ma2period) if _ma2type=="SMMA" w = wma(_masrclink, _ma2period) result := na(w[1]) ? sma(_masrclink, _ma2period) : (w[1] * (_ma2period - 1) + _masrclink) / _ma2period if _ma2type=="VWMA" result := vwma(_masrclink, _ma2period) if _ma2type=="HMA" result := wma(2 * wma(_masrclink, _ma2period / 2) - wma(_masrclink, _ma2period), round(sqrt(_ma2period))) if _ma2type=="ALMA" result := alma(_masrclink, _ma2period, ma_alma_offset, ma_alma_sigma) if _ma2type=="JMA" result := get_jurik2(_masrclink, _ma2period, ma_phase, ma_power) if _ma2type=="Donchian" result := donchian2(_ma2period) if _ma2type=="KijunSource" result:=(highest(_masrclink, _ma2period) + lowest(_masrclink, _ma2period))/2 if _ma2type=="LSMA" result := linreg(_masrclink, _ma2period, ma_s_maoffset) if _ma2type=="Triangular" result := sma(sma(_masrclink, ceil(_ma2period / 2)), floor(_ma2period / 2) + 1) if _ma2type=="SuperSmooth" result := S2(_masrclink, _ma2period) if _ma2type=="KAMA" result := KAMA2(_masrclink, _ma2period) if _ma2type=="GF" result := gf2 if _ma2type=="DSMA" result := D2(_masrclink, _ma2period) if _ma2type=="Median" result:= percentile_nearest_rank(_masrclink, _ma2period, ma_percentage) if _ma2type=="McGinley" result:= M2(_masrclink, _ma2period) if _ma2type=="VAMA" result:= VAMA2(_masrclink, _ma2period) if _ma2type=="FRAMA" result:= FRAMA2(_masrclink, _ma2period) result get_jurik3(_masrclink, _ma3period, ma_phase, ma_power) => ma_phaseratio = ma_phase < -100 ? 0.5 : ma_phase > 100 ? 2.5 : ma_phase / 100 + 1.5 ma_bet3a = 0.45 * (_ma3period - 1) / (0.45 * (_ma3period - 1) + 2) ma_bet3a_s = pow(ma_bet3a, ma_power) jma = 0.0 e0 = 0.0 e0 := (1 - ma_bet3a_s) * _masrclink + ma_bet3a_s * nz(e0[1]) e1 = 0.0 e1 := (_masrclink - e0) * (1 - ma_bet3a) + ma_bet3a * nz(e1[1]) e2 = 0.0 e2 := (e0 + ma_phaseratio * e1 - nz(jma[1])) * pow(1 - ma_bet3a_s, 2) + pow(ma_bet3a_s, 2) * nz(e2[1]) jma := e2 + nz(jma[1]) jma donchian3(_ma3period) => avg(lowest(_ma3period), highest(_ma3period)) PI3 = 2 * asin(1) tau3 = 2 * PI3 S3(_masrclink, _ma3period) => arg = sqrt(2) * PI3 / _ma3period a1 = exp(- arg) b1 = 2 * a1 * cos(arg) c2 = b1 c3 = -pow(a1, 2) c1 = 1 - c2 - c3 ssf = 0.0 ssf := c1 * (_masrclink + nz(_masrclink[1])) / 2 + c2 * nz(ssf[1]) + c3 * nz(ssf[2]) KAMA3(_masrclink,_ma3period) => mom = abs(change(_masrclink, _ma3period)) volatility = sum(abs(change(_masrclink)), _ma3period) er = volatility != 0 ? mom / volatility : 0 fastma_bet3a_s = 0.666 slowma_bet3a_s = 0.0645 sc = pow(er * (fastma_bet3a_s - slowma_bet3a_s) + slowma_bet3a_s, 2) KAMA3 = 0.0 KAMA3 := sc * _masrclink + (1 - sc) * nz(KAMA3[1]) VAMA3(_masrclink, _ma3period) => mavol = ema(_masrclink, _ma3period) madev = _masrclink - mavol mavu = highest(madev, mavp) mavd = lowest(madev, mavp) maok = mavol + avg(mavu, mavd) FRAMA3(_masrclink,_ma3period) => int maframalen = _ma3period / 2 mafe = 2.7182818284590452353602874713527 mafw = log(2 / (maframaslow +1)) / log(mafe) mafH1 = highest(high, maframalen) mafL1 = lowest(low, maframalen) mafN1 = (mafH1-mafL1) / maframalen mafH2_ = highest(high, maframalen) mafH2 = mafH2_[maframalen] mafL2_ = lowest(low, maframalen) mafL2 = mafL2_[maframalen] mafN2 = (mafH2 - mafL2) / maframalen mafH3 = highest(high, _ma3period) mafL3 = lowest(low, _ma3period) mafN3 = (mafH3 - mafL3) / _ma3period madin0 = (log(mafN1 + mafN2) - log(mafN3)) / log(2) madin = iff(mafN1 > 0 and mafN2 > 0 and mafN3 > 0, madin0, nz(madin0[1])) madst = exp(mafw * (madin -1)) maoda = madst > 1 ? 1 : (madst < 0.01 ? 0.01 : madst) maodc = (2 - maoda) / maoda mafcalc = (((maframaslow - maframafast) * (maodc -1)) / (maframaslow -1)) + maframafast maalpha = 2/(mafcalc +1) alpha = maalpha < 2 / (maframaslow +1) ? 2 / (maframaslow +1) : (maalpha > 1 ? 1 : maalpha) frama = 0.0 frama :=(1 - alpha) * nz(frama[1]) + alpha * _masrclink maok = frama bet3 = (1 - cos(2 * PI3 / ma3period)) / (pow(2, 1 / ma3period) - 1) alph3 = -bet3 + sqrt(pow(bet3, 2) + 2 * bet3) getgf33(poles) => filter = 0.0 if poles == 1 filter := alph3 * masrcl + (1 - alph3) * nz(filter[1]) if poles == 2 filter := pow(alph3, 2) * masrcl + 2 * (1 - alph3) * nz(filter[1]) - pow(1 - alph3, 2) * nz(filter[2]) if poles == 3 filter := pow(alph3, 3) * masrcl + 3 * (1 - alph3) * nz(filter[1]) - 3 * pow(1 - alph3, 2) * nz(filter[2]) + pow(1 - alph3, 3) * nz(filter[3]) if poles == 4 filter := pow(alph3, 4) * masrcl + 4 * (1 - alph3) * nz(filter[1]) - 6 * pow(1 - alph3, 2) * nz(filter[2]) + 4 * pow(1 - alph3, 3) * nz(filter[3]) - pow(1 - alph3, 4) * nz(filter[4]) filter gf3 = getgf33(ma_pn) D3(_masrclink, _ma3period) => A1 = exp( - sqrt(2) * PI3)/(0.5 * _ma3period) b1 = 2 * A1 * cos(sqrt(2) * PI3 / (0.5 * _ma3period)) c2 = b1 c3 = - A1 * A1 c1 = 1 - c2 - c3 Zeros = _masrclink - _masrclink[2] DSMA = 0.0 ma_bet3a_s1 = 0.0 Filt = 0.0 Filt := c1 * ( Zeros + Zeros[1] ) / 2 + c2 * nz(Filt[1]) + c3 * nz(Filt[2]) RMS = stdev(Filt, _ma3period) ScaledFilt = Filt / RMS ma_bet3a_s1 := (abs(ScaledFilt) * 5) / _ma3period DSMA := (ma_bet3a_s1 * _masrclink) + (( 1 - ma_bet3a_s1 ) * nz(DSMA[1])) M3(_masrclink, _ma3period)=> mg = 0.0 mg := na(mg[1]) ? ema(_masrclink, _ma3period) : mg[1] + (_masrclink - mg[1]) / (_ma3period * pow(_masrclink / mg[1], 4)) mg _ma3(_ma3type, _masrclink, _ma3period) => float result = 0 if _ma3type=="SMA" result := sma(_masrclink, _ma3period) if _ma3type=="EMA" result := ema(_masrclink, _ma3period) if _ma3type=="DEMA" EMA1=ema(_masrclink, _ma3period) EMA2=ema(EMA1, _ma3period) result := 2 * EMA1 - EMA2 if _ma3type=="TEMA" xEMA1 = ema(_masrclink, _ma3period) xEMA2 = ema(xEMA1, _ma3period) xEMA3 = ema(xEMA2, _ma3period) result := 3 * xEMA1 - 3 * xEMA2 + xEMA3 if _ma3type=="ZLEMA" lag = floor((_ma3period - 1) / 2) result := ema(_masrclink + (_masrclink - _masrclink[lag]), _ma3period) if _ma3type=="WMA" result := wma(_masrclink, _ma3period) if _ma3type=="SMMA" w = wma(_masrclink, _ma3period) result := na(w[1]) ? sma(_masrclink, _ma3period) : (w[1] * (_ma3period - 1) + _masrclink) / _ma3period if _ma3type=="VWMA" result := vwma(_masrclink, _ma3period) if _ma3type=="HMA" result := wma(2 * wma(_masrclink, _ma3period / 2) - wma(_masrclink, _ma3period), round(sqrt(_ma3period))) if _ma3type=="ALMA" result := alma(_masrclink, _ma3period, ma_alma_offset, ma_alma_sigma) if _ma3type=="JMA" result := get_jurik3(_masrclink, _ma3period, ma_phase, ma_power) if _ma3type=="Donchian" result := donchian3(_ma3period) if _ma3type=="KijunSource" result:=(highest(_masrclink, _ma3period) + lowest(_masrclink, _ma3period)) / 2 if _ma3type=="LSMA" result := linreg(_masrclink, _ma3period, ma_s_maoffset) if _ma3type=="Triangular" result := sma(sma(_masrclink, ceil(_ma3period / 2)), floor(_ma3period / 2) + 1) if _ma3type=="SuperSmooth" result := S3(_masrclink, _ma3period) if _ma3type=="KAMA" result := KAMA3(_masrclink, _ma3period) if _ma3type=="GF" result := gf3 if _ma3type=="DSMA" result := D3(_masrclink, _ma3period) if _ma3type=="Median" result:= percentile_nearest_rank(_masrclink, _ma3period, ma_percentage) if _ma3type=="McGinley" result:= M3(_masrclink, _ma3period) if _ma3type=="VAMA" result:= VAMA3(_masrclink, _ma3period) if _ma3type=="FRAMA" result:= FRAMA3(_masrclink, _ma3period) result forecast(_ma1type, _masrclink, _flen, _lrlen) => linreg_1 = linreg(_masrclink, _lrlen, _flen) _ma1type == "MA Source" ? _masrclink : _ma1type == "Linear Regression" ? linreg_1 : na forecast_2(_ma2type, _masrclink, _flen, _lrlen) => linreg_2 = linreg(_masrclink, _lrlen, _flen) _ma2type == "MA Source" ? _masrclink : _ma2type == "Linear Regression" ? linreg_2 : na forecast_3(_ma3type, _masrclink, _flen, _lrlen) => linreg_3 = linreg(_masrclink, _lrlen, _flen) _ma3type == "MA Source" ? _masrclink : _ma3type == "Linear Regression" ? linreg_3 : na forecast_4(_ma1type, _masrclink, _flen, _lrlen) => linreg_4 = linreg(_masrclink, _lrlen, _flen) _ma1type == "MA Source" ? _masrclink : _ma1type == "Linear Regression" ? linreg_4 : na forecast_5(_ma2type, _masrclink, _flen, _lrlen) => linreg_5 = linreg(_masrclink, _lrlen, _flen) _ma2type == "MA Source" ? _masrclink : _ma2type == "Linear Regression" ? linreg_5 : na forecast_6(_ma3type, _masrclink, _flen, _lrlen) => linreg_6 = linreg(_masrclink, _lrlen, _flen) _ma3type == "MA Source" ? _masrclink : _ma3type == "Linear Regression" ? linreg_6 : na ma1col = #3498DB ma2col = #FFA500 ma3col = #FF00FF forecastloopback = realtimeforecast ? 0 : 1 masrclink = masrcl[forecastloopback] ma1plot = _ma1(ma1type, masrclink, ma1period) ma2plot = _ma2(ma2type, masrclink, ma2period) ma3plot = _ma3(ma3type, masrclink, ma3period) macross = cross(ma1plot, ma2plot) and showmacross ? ma1plot : na forecast1 = forecast(forecasttype, masrclink, 1, lnperiod) forecast2 = forecast_2(forecasttype, masrclink, 2, lnperiod) forecast3 = forecast_3(forecasttype, masrclink, 3, lnperiod) forecast4 = forecast_4(forecasttype, masrclink, 4, lnperiod) forecast5 = forecast_5(forecasttype, masrclink, 5, lnperiod) forecast6 = forecast_6 (forecasttype, masrclink, 6, lnperiod) //Calculation ma1typep1 = _ma1(ma1type, masrclink, ma1period - 1) ma1forecast1 = ma1 ? (ma1typep1 * (ma1period - 1) + forecast1) / ma1period : na ma1typep2 = _ma1(ma1type, masrclink, ma1period - 2) ma1forecast2 = ma1 ? (ma1typep2 * (ma1period - 2) + forecast1 + forecast2) / ma1period : na ma1typep3 = _ma1(ma1type, masrclink, ma1period - 3) ma1forecast3 = ma1 ? (ma1typep3 * (ma1period - 3) + forecast1 + forecast2 + forecast3) / ma1period : na ma1typep4 = _ma2(ma2type, masrclink, ma1period - 4) ma1forecast4 = ma1 ? (ma1typep4 * (ma1period - 4) + forecast1 + forecast2 + forecast3 + forecast4) / ma1period : na ma1typep5 = _ma2(ma2type, masrclink, ma1period - 5) ma1forecast5 = ma1 ? (ma1typep5 * (ma1period - 5) + forecast1 + forecast2 + forecast3 + forecast4 + forecast5) / ma1period : na ma1typep6 = _ma2(ma2type, masrclink, ma1period - 6) ma1forecast6 = ma1 ? (ma1typep6 * (ma1period - 6) + forecast1 + forecast2 + forecast3 + forecast4 + forecast5 + forecast6) / ma1period : na ma2typep7 = _ma2(ma2type, masrclink, ma2period - 1) ma2forecast1 = ma2 ? (ma2typep7 * (ma2period - 1) + forecast1) / ma2period : na ma2typep8 = _ma2(ma2type, masrclink, ma2period - 2) ma2forecast2 = ma2 ? (ma2typep8 * (ma2period - 2) + forecast1 + forecast2) / ma2period : na ma2typep9 = _ma2(ma2type, masrclink, ma2period - 3) ma2forecast3 = ma2 ? (ma2typep9 * (ma2period - 3) + forecast1 + forecast2 + forecast3) / ma2period : na ma2typep10 = _ma2(ma2type, masrclink, ma2period - 4) ma2forecast4 = ma2 ? (ma2typep10 * (ma2period - 4) + forecast1 + forecast2 + forecast3 + forecast4) / ma2period : na ma2typep11 = _ma2(ma2type, masrclink, ma2period - 5) ma2forecast5 = ma2 ? (ma2typep11 * (ma2period - 5) + forecast1 + forecast2 + forecast3 + forecast4 + forecast5) / ma2period : na ma2typep12 = _ma2(ma2type, masrclink, ma2period - 6) ma2forecast6 = ma2 ? (ma2typep12 * (ma2period - 6) + forecast1 + forecast2 + forecast3 + forecast4 + forecast5 + forecast6) / ma2period : na ma3typep13 = _ma3(ma3type, masrclink, ma3period - 1) ma3forecast1 = ma3 ? (ma3typep13 * (ma3period - 1) + forecast1) / ma3period : na ma3typep14 = _ma3(ma3type, masrclink, ma3period - 2) ma3forecast2 = ma3 ? (ma3typep14 * (ma3period - 2) + forecast1 + forecast2) / ma3period : na ma3typep15 = _ma3(ma3type, masrclink, ma3period - 3) ma3forecast3 = ma3 ? (ma3typep15 * (ma3period - 3) + forecast1 + forecast2 + forecast3) / ma3period : na ma3typep16 = _ma3(ma3type, masrclink, ma3period - 4) ma3forecast4 = ma3 ? (ma3typep16 * (ma3period - 4) + forecast1 + forecast2 + forecast3 + forecast4) / ma3period : na ma3typep17 = _ma3(ma3type, masrclink, ma3period - 5) ma3forecast5 = ma3 ? (ma3typep17 * (ma3period - 5) + forecast1 + forecast2 + forecast3 + forecast4 + forecast5) / ma3period : na ma3typep18 = _ma3(ma3type, masrclink, ma3period - 6) ma3forecast6 = ma3 ? (ma3typep18 * (ma3period - 6) + forecast1 + forecast2 + forecast3 + forecast4 + forecast5 + forecast6) / ma3period : na //Plotting plot(ma1 ? ma1plot : na, color=ma1col, linewidth=2, offset=-1 * forecastloopback, title="MA1") plot(ma2 ? ma2plot : na, color=ma2col, linewidth=2, offset=-1 * forecastloopback, title="MA2") plot(ma3 ? ma3plot : na, color=ma3col, linewidth=2, offset=-1 * forecastloopback, title="MA3") plot(maforecasting ? ma1forecast1 : na, color=ma1col, linewidth=2, style=plot.style_circles, title="MA1 Forecast 1", offset=1 - forecastloopback, show_last=1) plot(maforecasting ? ma1forecast2 : na, color=ma1col, linewidth=2, style=plot.style_circles, title="MA1 Forecast 2", offset=2 - forecastloopback, show_last=1) plot(maforecasting ? ma1forecast3 : na, color=ma1col, linewidth=2, style=plot.style_circles, title="MA1 Forecast 3", offset=3 - forecastloopback, show_last=1) plot(maforecasting ? ma1forecast4 : na, color=ma1col, linewidth=2, style=plot.style_circles, title="MA1 Forecast 4", offset=4 - forecastloopback, show_last=1) plot(maforecasting ? ma1forecast5 : na, color=ma1col, linewidth=2, style=plot.style_circles, title="MA1 Forecast 5", offset=5 - forecastloopback, show_last=1) plot(maforecasting ? ma2forecast1 : na, color=ma2col, linewidth=2, style=plot.style_circles, title="MA2 Forecast 1", offset=1 - forecastloopback, show_last=1) plot(maforecasting ? ma2forecast2 : na, color=ma2col, linewidth=2, style=plot.style_circles, title="MA2 Forecast 2", offset=2 - forecastloopback, show_last=1) plot(maforecasting ? ma2forecast3 : na, color=ma2col, linewidth=2, style=plot.style_circles, title="MA2 Forecast 3", offset=3 - forecastloopback, show_last=1) plot(maforecasting ? ma2forecast4 : na, color=ma2col, linewidth=2, style=plot.style_circles, title="MA2 Forecast 4", offset=4 - forecastloopback, show_last=1) plot(maforecasting ? ma2forecast5 : na, color=ma2col, linewidth=2, style=plot.style_circles, title="MA2 Forecast 5", offset=5 - forecastloopback, show_last=1) plot(maforecasting ? ma3forecast1 : na, color=ma3col, linewidth=2, style=plot.style_circles, title="MA3 Forecast 1", offset=1 - forecastloopback, show_last=1) plot(maforecasting ? ma3forecast2 : na, color=ma3col, linewidth=2, style=plot.style_circles, title="MA3 Forecast 2", offset=2 - forecastloopback, show_last=1) plot(maforecasting ? ma3forecast3 : na, color=ma3col, linewidth=2, style=plot.style_circles, title="MA3 Forecast 3", offset=3 - forecastloopback, show_last=1) plot(maforecasting ? ma3forecast4 : na, color=ma3col, linewidth=2, style=plot.style_circles, title="MA3 Forecast 4", offset=4 - forecastloopback, show_last=1) plot(maforecasting ? ma3forecast5 : na, color=ma3col, linewidth=2, style=plot.style_circles, title="MA3 Forecast 5", offset=5 - forecastloopback, show_last=1) plot(macross, "MA Cross", color=color.yellow, linewidth=3, style=plot.style_cross) //Alerts alertcondition(crossover(ma1plot, ma2plot) or crossunder(ma1plot, ma2plot), title="MA1 and MA2 Cross", message='MA1 and MA2 Cross') //RSI Range Filter //Inputs rsilen = input(defval=14, title="RSI Length", type=input.integer, minval=1) rsiob = input(defval=60, title="RSI Filter Overbought Threshold") rsios = input(defval=40, title="RSI Filter Oversold Threshold") //Settings rsifilter = rsi(close, rsilen) rsifilterob = rsifilter >= rsiob ? #67ac5b : na rsifilteros = rsifilter <= rsios ? #d63964 : na rsifilter_range = rsifilter < rsiob and rsifilter > rsios ? color.new(color.gray, transp=95) : na //Bar Color barcolor(showrsifilter ? rsifilterob : na) barcolor(showrsifilter ? rsifilteros : na) barcolor(showrsifilter ? rsifilter_range : na)
The content covered on this website is NOT investment advice and I am not a financial advisor.