Advertisement
xmd79

My indicator - moac123

Jan 13th, 2023
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // Β© VenkatNarayanan
  3.  
  4. //@version=5
  5. indicator('My indicator - moac123', overlay=true)
  6.  
  7. haTicker = ticker.heikinashi(syminfo.tickerid)
  8. haClose = request.security(haTicker, timeframe.period, close)
  9. haOpen = request.security(haTicker, timeframe.period, open)
  10. haHigh = request.security(haTicker, timeframe.period, high)
  11. haLow = request.security(haTicker, timeframe.period, low)
  12.  
  13. //MACD
  14. fast_length = input(title="Fast Length", defval=12, group="MACD")
  15. slow_length = input(title="Slow Length", defval=26, group="MACD")
  16. src = haClose
  17. signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9, group="MACD")
  18. sma_source = input.string(title="Oscillator MA Type", defval="EMA", options=["SMA", "EMA"], group="MACD")
  19. sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"], group="MACD")
  20.  
  21. fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
  22. slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)
  23. macd = fast_ma - slow_ma
  24. signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
  25. hist = macd - signal
  26.  
  27. //SMMA
  28. smmalen = input.int(7, minval=1, title="SMMA Length", group="SMMA")
  29. smmasrc = input(close, title="SMMA Source", group="SMMA")
  30. smma = 0.0
  31. _sma = ta.sma(smmasrc, smmalen)
  32. smma := na(smma[1]) ? _sma : (smma[1] * (smmalen - 1) + smmasrc) / smmalen
  33. plot(smma, title="SMMA", color=color.blue, linewidth=1)
  34.  
  35. //LSMA
  36. lsmalength = input(title="LSMA Length", defval=25, group="LSMA")
  37. lsmaoffset = input(title="LSMA Offset", defval=0, group="LSMA")
  38. lsmasrc = input(close, title="LSMA Source", group="LSMA")
  39. lsma = ta.linreg(lsmasrc, lsmalength, lsmaoffset)
  40. plot(lsma, title="LSMA", color=color.yellow, linewidth=1)
  41.  
  42.  
  43. //Calculation Resistance and Support using MACD Cross
  44. lookback = input(title='Candle Lookback', defval=11, group="Support & Resistance")
  45. var previoushigh = float(na)
  46. var previouslow = float(na)
  47. lookbackhigh = ta.highest(haHigh, lookback)
  48. if ta.crossunder(macd,signal)
  49. previoushigh := lookbackhigh
  50.  
  51.  
  52. lookbacklow = ta.lowest(low, lookback)
  53. if ta.crossunder(signal,macd)
  54. previouslow := lookbacklow
  55.  
  56. lookbackavg = math.avg(previoushigh, previouslow)
  57. plot(previoushigh, title="Resistance", color=color.red, linewidth=2)
  58. plot(previouslow, title="Support", color=color.green, linewidth=2)
  59. plot(lookbackavg, title='Average Resistance and Support', color=color.new(color.orange, 0), linewidth=2)
  60.  
  61.  
  62. // signal plotting
  63. isGreenCandle = (close > open)
  64.  
  65.  
  66.  
  67. isLong = false // A flag for going LONG
  68. isLong := nz(isLong[1]) // Get the previous value of it
  69.  
  70. isShort = false // A flag for going SHORT
  71. isShort := nz(isShort[1]) // Get the previous value of it
  72.  
  73. if (isLong and close[0] < lookbackavg)
  74. isLong = false
  75.  
  76. if (isShort and close[0] > lookbackavg)
  77. isShort = false
  78.  
  79. longConditions = close[0] > lookbackavg and lsma > lookbackavg and lsma > smma and not isLong and isGreenCandle and close[0] > lsma and close[0] < previoushigh
  80. if (longConditions)
  81. isLong := true
  82. isShort := false
  83.  
  84. shortConditions = close[0] < lookbackavg and lsma < lookbackavg and lsma < smma and not isShort and not isGreenCandle and close[0] < lsma and close[0] > previouslow
  85. if (shortConditions)
  86. isLong := false
  87. isShort := true
  88.  
  89.  
  90.  
  91. plotshape(longConditions, style=shape.triangleup,text='LONG',
  92. color=color.green, title='Long')
  93.  
  94.  
  95. plotshape(shortConditions, style=shape.triangledown,text='SHORT',
  96. color=color.red, title='Short')
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement