Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // Β© VenkatNarayanan
- //@version=5
- indicator('My indicator - moac123', overlay=true)
- haTicker = ticker.heikinashi(syminfo.tickerid)
- haClose = request.security(haTicker, timeframe.period, close)
- haOpen = request.security(haTicker, timeframe.period, open)
- haHigh = request.security(haTicker, timeframe.period, high)
- haLow = request.security(haTicker, timeframe.period, low)
- //MACD
- fast_length = input(title="Fast Length", defval=12, group="MACD")
- slow_length = input(title="Slow Length", defval=26, group="MACD")
- src = haClose
- signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9, group="MACD")
- sma_source = input.string(title="Oscillator MA Type", defval="EMA", options=["SMA", "EMA"], group="MACD")
- sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"], group="MACD")
- 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
- //SMMA
- smmalen = input.int(7, minval=1, title="SMMA Length", group="SMMA")
- smmasrc = input(close, title="SMMA Source", group="SMMA")
- smma = 0.0
- _sma = ta.sma(smmasrc, smmalen)
- smma := na(smma[1]) ? _sma : (smma[1] * (smmalen - 1) + smmasrc) / smmalen
- plot(smma, title="SMMA", color=color.blue, linewidth=1)
- //LSMA
- lsmalength = input(title="LSMA Length", defval=25, group="LSMA")
- lsmaoffset = input(title="LSMA Offset", defval=0, group="LSMA")
- lsmasrc = input(close, title="LSMA Source", group="LSMA")
- lsma = ta.linreg(lsmasrc, lsmalength, lsmaoffset)
- plot(lsma, title="LSMA", color=color.yellow, linewidth=1)
- //Calculation Resistance and Support using MACD Cross
- lookback = input(title='Candle Lookback', defval=11, group="Support & Resistance")
- var previoushigh = float(na)
- var previouslow = float(na)
- lookbackhigh = ta.highest(haHigh, lookback)
- if ta.crossunder(macd,signal)
- previoushigh := lookbackhigh
- lookbacklow = ta.lowest(low, lookback)
- if ta.crossunder(signal,macd)
- previouslow := lookbacklow
- lookbackavg = math.avg(previoushigh, previouslow)
- plot(previoushigh, title="Resistance", color=color.red, linewidth=2)
- plot(previouslow, title="Support", color=color.green, linewidth=2)
- plot(lookbackavg, title='Average Resistance and Support', color=color.new(color.orange, 0), linewidth=2)
- // signal plotting
- isGreenCandle = (close > open)
- isLong = false // A flag for going LONG
- isLong := nz(isLong[1]) // Get the previous value of it
- isShort = false // A flag for going SHORT
- isShort := nz(isShort[1]) // Get the previous value of it
- if (isLong and close[0] < lookbackavg)
- isLong = false
- if (isShort and close[0] > lookbackavg)
- isShort = false
- longConditions = close[0] > lookbackavg and lsma > lookbackavg and lsma > smma and not isLong and isGreenCandle and close[0] > lsma and close[0] < previoushigh
- if (longConditions)
- isLong := true
- isShort := false
- shortConditions = close[0] < lookbackavg and lsma < lookbackavg and lsma < smma and not isShort and not isGreenCandle and close[0] < lsma and close[0] > previouslow
- if (shortConditions)
- isLong := false
- isShort := true
- plotshape(longConditions, style=shape.triangleup,text='LONG',
- color=color.green, title='Long')
- plotshape(shortConditions, style=shape.triangledown,text='SHORT',
- color=color.red, title='Short')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement