Advertisement
Guest User

Untitled

a guest
May 24th, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. //@version=5
  2. indicator("TOTAL MTPI", overlay = true)
  3.  
  4. // Coral Trend calculation
  5.  
  6. A = input.int(21, title="Smoothing Period")
  7. B = input.float(0.4, title="Constant D")
  8.  
  9. coralTrend(int a, float b, series float src) =>
  10. sm = a
  11. cd = b
  12. di = (sm - 1.0) / 2.0 + 1.0
  13. c1 = 2 / (di + 1.0)
  14. c2 = 1 - c1
  15. c3 = 3.0 * (cd * cd + cd * cd * cd)
  16. c4 = -3.0 * (2.0 * cd * cd + cd + cd * cd * cd)
  17. c5 = 3.0 * cd + 1.0 + cd * cd * cd + 3.0 * cd * cd
  18. var float i1 = na
  19. var float i2 = na
  20. var float i3 = na
  21. var float i4 = na
  22. var float i5 = na
  23. var float i6 = na
  24. i1 := c1 * src + c2 * nz(i1[1])
  25. i2 := c1 * i1 + c2 * nz(i2[1])
  26. i3 := c1 * i2 + c2 * nz(i3[1])
  27. i4 := c1 * i3 + c2 * nz(i4[1])
  28. i5 := c1 * i4 + c2 * nz(i5[1])
  29. i6 := c1 * i5 + c2 * nz(i6[1])
  30. bfr = -cd * cd * cd * i6 + c3 * i5 + c4 * i4 + c5 * i3
  31. coralTrend = bfr > nz(bfr[1]) ? 1 : -1
  32. coralTrend
  33.  
  34. Cheese = request.security(syminfo.tickerid, "3D", barstate.isconfirmed ? coralTrend(A, B, close) : coralTrend(A, B, close)[1])
  35.  
  36.  
  37. // Set bar color based on trends
  38. colorCh = color.white
  39.  
  40. if Cheese == 1
  41. colorCh := color.green
  42. else
  43. colorCh := color.red
  44.  
  45. barcolor(colorCh)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement