PineCoders

widest() error

Aug 26th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 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. // © Hero_Hedge
  3.  
  4. //@version=4
  5. study("Moving Average Cross Builder", shorttitle="MACB", overlay=true)
  6. //Add in minval and step size to get float vales for fib
  7. MA1Period = input( defval=50,title="Period of MA1", minval=0, step=1)
  8. MA1Type = input(title="MA1 Type", defval="Simple", options=["Simple", "Smoothed", "Exponential", "Double Exponential", "Triple Exponential", "Weighted", "Hull", "Volume weighted", "McGinley", "Zero lag"])
  9. MA1Source = input(title="MA1 Source", type=input.source, defval=close)
  10. MA1Resolution = input(title="MA1 Resolution", type=input.resolution, defval="")
  11. MA1Visible = input(title="Show MA1", type=input.bool, defval=true)
  12.  
  13. MA2Period = input(100, title="Period of MA2", minval=0, step=1)
  14. MA2Type = input(title="MA2 Type", defval="Simple", options=["Simple", "Smoothed", "Exponential", "Double Exponential", "Triple Exponential", "Weighted", "Hull","Volume weighted", "McGinley", "Zero lag"])
  15. MA2Source = input(title="MA2 Source", type=input.source, defval=close)
  16. MA2Resolution = input(title="MA2 Resolution", type=input.resolution, defval="")
  17. MA2Visible = input(title="Show MA2", type=input.bool, defval=false)
  18.  
  19. MA3Period = input(150, title="Period of MA3",minval=0)
  20. MA3Type = input(title="MA3 Type", defval="Simple", options=["Simple", "Smoothed", "Exponential", "Double Exponential", "Triple Exponential", "Weighted", "Hull","Volume weighted", "McGinley", "Zero lag"])
  21. MA3Source = input(title="MA3 Source", type=input.source, defval=close)
  22. MA3Resolution = input(title="MA3 Resolution", type=input.resolution, defval="")
  23. MA3Visible = input(title="Show MA3", type=input.bool, defval=false)
  24.  
  25. MA4Period = input(200, title="Period of MA4", minval=0)
  26. MA4Type = input(title="MA4 Type", defval="Simple", options=["Simple", "Smoothed", "Exponential", "Double Exponential", "Triple Exponential", "Weighted", "Hull","Volume weighted", "McGinley", "Zero lag"])
  27. MA4Source = input(title="MA4 Source", type=input.source, defval=close)
  28. MA4Resolution = input(title="MA4 Resolution", type=input.resolution, defval="")
  29. MA4Visible = input(title="Show MA4", type=input.bool, defval=false)
  30.  
  31. ma(MAType, MASource, MAPeriod) =>
  32. mg = 0.0
  33. smma = 0.0
  34. if MAType == "Simple"
  35. sma(MASource, MAPeriod)
  36. else if MAType =="Exponential"
  37. ema(MASource, MAPeriod)
  38. else if MAType == "Weighted"
  39. wma(MASource, MAPeriod)
  40. else if MAType == "Hull"
  41. hma(MASource, MAPeriod)
  42. else if MAType == "Volume weighted"
  43. vwma(MASource, MAPeriod)
  44. else if MAType == "Double Exponential"
  45. e = ema(MASource, MAPeriod)
  46. 2 * e - ema(e, MAPeriod)
  47. else if MAType == "Triple Exponential"
  48. e = ema(MASource, MAPeriod)
  49. 3 * (e - ema(e, MAPeriod)) + ema(ema(e, MAPeriod), MAPeriod) // EVERYTHING GOOD UNTIL HERE
  50. else if MAType == "Smoothed"
  51. len = input(7, minval=1, title="Length")
  52. src = input(close, title="Source")
  53. smma := na(smma[1]) ? sma(src, len) : (smma[1] * (len - 1) + src) / len
  54. else if MAType == "Zero lag" //script by HPotter
  55. xPrice = MASource
  56. nPeriod = MAPeriod
  57. xLag = (nPeriod - 1) / 2
  58. xEMAData = (xPrice + (xPrice - xPrice[xLag]))
  59. xZLEMA = ema(xEMAData, nPeriod)
  60. else if MAType == "McGinley"
  61. Mglength = MAPeriod
  62. source = MASource
  63. mg := na(mg[1]) ? ema(source, Mglength) : mg[1] + (source - mg[1]) / (Mglength * pow(source/mg[1], 4))
  64. else
  65. float(na)
  66.  
  67. MA1 = security(syminfo.tickerid, MA1Resolution, ma(MA1Type, MA1Source, MA1Period))
  68. MA2 = security(syminfo.tickerid, MA2Resolution, ma(MA2Type, MA2Source, MA2Period))
  69. MA3 = security(syminfo.tickerid, MA3Resolution, ma(MA3Type, MA3Source, MA3Period))
  70. MA4 = security(syminfo.tickerid, MA4Resolution, ma(MA4Type, MA4Source, MA4Period))
  71.  
  72. plot(MA1Visible ? MA1 : na, color=color.red, title="MA1")
  73. plot(MA2Visible ? MA2 : na, color=color.yellow, title="MA2")
  74. plot(MA3Visible ? MA3 : na, color=color.green, title="MA3")
  75. plot(MA4Visible ? MA4 : na, color=color.blue, title="MA4")
  76.  
  77.  
Add Comment
Please, Sign In to add comment