SHARE
TWEET

Pig Momentum

a guest Mar 26th, 2020 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //@version=4
  2. study(title="Pig MOM", overlay=false)
  3. bgcolor(#000000c0)
  4. src = input(title="Source", type=input.source, defval=close)
  5. lambda = input(0.85, "lambda (EWMA)", step=0.01)
  6. smooth = input(true)
  7. sl = input(8, "Smooth Length")
  8. oneMinusLambda = 1.0 - lambda
  9. ss(Series, Period) => // Super Smoother Function
  10.     // period = input(8, "Super Smoother Period", input.float, minval=2.0, step=0.5)
  11.     var PI    = 2.0 * asin(1.0)
  12.     var SQRT2 = sqrt(2.0)
  13.     lam = PI * SQRT2 / Period
  14.     a1     = exp(-lam)
  15.     coeff2 = 2.0 * a1 * cos(lam)
  16.     coeff3 = - pow(a1, 2.0)
  17.     coeff1 = 1.0 - coeff2 - coeff3
  18.     filt1  = 0.0
  19.     filt1 := coeff1 * (Series + nz(Series[1])) * 0.5 + coeff2 * nz(filt1[1]) + coeff3 * nz(filt1[2])
  20.     filt1
  21.  
  22.  
  23. priorClose = nz(src[1], src) // nz() replaces na with 0.0, added ", close)" Divide by zero situation combined with #2
  24. xPrice = src - priorClose
  25. logCloseDividedPriorCLose = log(src / priorClose) // #2
  26.  
  27. d = xPrice<0.0 ? logCloseDividedPriorCLose : 0.0 // Less than: xPrice < ...
  28. v = 0.0
  29. v := lambda * nz(v[1]) + oneMinusLambda * pow(d, 2)
  30. dhv = sqrt(v)  * 100.0
  31.  
  32. u = xPrice>0.0 ? logCloseDividedPriorCLose : 0.0 // Greater than: xPrice > ...
  33. v2 = 0.0
  34. v2 := lambda * nz(v2[1]) + oneMinusLambda * pow(u, 2)
  35. uhv = sqrt(v2)  * 100.0
  36.  
  37.  
  38. v3 = 0.0
  39. v3 := lambda*nz(v3[1])+ oneMinusLambda*pow(logCloseDividedPriorCLose,2)
  40. ewma = sqrt(v3)*100
  41.  
  42.  
  43.  
  44. trur = ewma
  45. plus = uhv/ewma
  46. minus = dhv/ewma
  47.  
  48. diff = plus - minus
  49. z(a)=>
  50.     0.5*log((1+a)/(1-a))
  51. m = z(diff)
  52. mom = smooth ? ss(m,sl) : m
  53.  
  54.  
  55. color2 = if mom >= 0
  56.     color.green
  57. else
  58.     color.red
  59.  
  60. plot(mom, color=mom > nz(mom[1]) ? #00C0FFff : #FF0080ff,title="Direction",linewidth=2, transp=0)
  61. plot(mom, color=mom > 0 ? color.aqua : color.fuchsia, style = plot.style_columns,title= "Mom",transp=70)
  62. hline(0,color=color.white)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top