Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. //@version=4
  2. study("MACD", overlay=true)
  3.  
  4. // --------- Variables --------- //
  5.  
  6. var fastemaperiod = 8.3896
  7. var slowemaperiod = 17.5185
  8. var signalemaperiod = 9.0503
  9.  
  10. // Formula expressions
  11. var ex1 = (fastemaperiod-slowemaperiod)*2
  12. var ex1a = signalemaperiod+1.0
  13. var ex2 = 1.0-(2.0/ex1a)
  14. var ex3 = fastemaperiod+1.0
  15. var ex4 = slowemaperiod+1.0
  16. var ex5 = (2.0/ex1a)-1.0
  17.  
  18. // --------- Functions --------- //
  19.  
  20. floatema(pprice, pperiod) =>
  21. alpha = 2 / (pperiod + 1)
  22. ema = 0.0
  23. ema := alpha * pprice + (1 - alpha) * nz(ema[1])
  24. ema
  25.  
  26. roundmultiplier() =>
  27. int start = 1
  28. for i = 0 to 100
  29. start := (start*10)
  30. if(int(nz(syminfo.mintick*start)) == 0)
  31. continue
  32. break
  33. start
  34. var multiplier = roundmultiplier()
  35.  
  36. showpredictedprice(pprice, pcolor, pshowlabel) =>
  37. fastema = floatema(close, fastemaperiod)
  38. slowema = floatema(close, slowemaperiod)
  39. signalema = floatema((fastema - slowema), signalemaperiod)
  40.  
  41. predictedprice = (-1.0)*((1.0/(ex1*ex2))*(ex3*(ex4*(ex5*(fastema[0]*(1.0-(2.0/ex3))-(slowema[0]*(1.0-(2.0/ex4))))+(signalema[0]*ex2)))))
  42. predictedprice := (round(predictedprice*multiplier)/multiplier)
  43. predictedtime = (time + (time - time[1]))
  44. labelstyle = pprice < predictedprice ? label.style_labeldown : label.style_labelup
  45.  
  46. if(pshowlabel)
  47. _label = label.new(predictedtime, predictedprice, xloc=xloc.bar_time, text=tostring(predictedprice), textcolor=color.white, color=pcolor, style=labelstyle)
  48. label.delete(_label[1])
  49.  
  50. _line = line.new(time, pprice, predictedtime, predictedprice, xloc=xloc.bar_time, color=pcolor, width=2)
  51. line.delete(_line[1])
  52. _line
  53.  
  54. // --------- Calulations --------- //
  55.  
  56. fastema = floatema(close, fastemaperiod)
  57. slowema = floatema(close, slowemaperiod)
  58. signalema = floatema((fastema - slowema), signalemaperiod)
  59.  
  60. // Predictor calculation
  61. predictor = (-1.0)*((1.0/(ex1*ex2))*(ex3*(ex4*(ex5*(fastema[1]*(1.0-(2.0/ex3))-(slowema[1]*(1.0-(2.0/ex4))))+(signalema[1]*ex2)))))
  62.  
  63. // Predict price for the next bar
  64. showpredictedprice(predictor, color.red, true)
  65.  
  66. // --------- Plots --------- //
  67.  
  68. plot(predictor, color=color.red, transp=0, linewidth=2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement