Advertisement
Guest User

Untitled

a guest
Feb 25th, 2024
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. // Loxx supertrend
  2.  
  3. RMA(x, t) =>
  4. EMA1 = x
  5. EMA1 := na(EMA1[1]) ? x : (x - nz(EMA1[1])) * (1/t) + nz(EMA1[1])
  6. EMA1
  7.  
  8. fdip(float srcloxx, int per, int speedin)=>
  9. float fmax = ta.highest(srcloxx, per)
  10. float fmin = ta.lowest(srcloxx, per)
  11. float lengthloxx = 0
  12. float diff = 0
  13. for i = 1 to per - 1
  14. diff := (nz(srcloxx[i]) - fmin) / (fmax - fmin)
  15. if i > 0
  16. lengthloxx += math.sqrt( math.pow(nz(diff[i]) - nz(diff[i + 1]), 2) + (1 / math.pow(per, 2)))
  17. float fdi = 1 + (math.log(lengthloxx) + math.log(2)) / math.log(2 * per)
  18. float traildim = 1 / (2 - fdi)
  19. float alpha = traildim / 2
  20. int speed = math.round(speedin * alpha)
  21. speed
  22.  
  23. pine_supertrend(float srcloxx, float factor, int atrPeriod) =>
  24. float atr = RMA(ta.tr(true), atrPeriod)
  25. float upperBand = srcloxx + factor * atr
  26. float lowerBand = srcloxx - factor * atr
  27. float prevLowerBand = nz(lowerBand[1])
  28. float prevUpperBand = nz(upperBand[1])
  29.  
  30. lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ? lowerBand : prevLowerBand
  31. upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ? upperBand : prevUpperBand
  32. int directionloxx = na
  33. float superTrend = na
  34. float prevSuperTrend = superTrend[1]
  35. if na(atr[1])
  36. directionloxx := 1
  37. else if prevSuperTrend == prevUpperBand
  38. directionloxx := close > upperBand ? -1 : 1
  39. else
  40. directionloxx := close < lowerBand ? 1 : -1
  41. superTrend := directionloxx == -1 ? lowerBand : upperBand
  42. [superTrend, directionloxx]
  43.  
  44. srcloxx = input.source(hl2, group = "Loxx")
  45. per = input.int(30, "Fractal Period Ingest", group = "Loxx")
  46. speed = input.int(20, "Speed", group = "Loxx")
  47.  
  48. //Loxx input
  49. multloxx5 = input.float(5 , "1st Multiplier", group = "Loxx", step=0.1) //~using the same step as supertrend and *2 to test the robustness = 0.05*2 = 0.1
  50. multloxx2 = input.float(2 , "2nd Multiplier", group = "Loxx", step=0.1) //~
  51. multloxx3 = input.float(3 , "3rd Multiplier", group = "Loxx", step=0.1) //~
  52. multloxx1825 = input.float(1.825, "4th Multiplier", group = "Loxx", step=0.1) //~
  53. adaptloxx = input.bool(true)
  54.  
  55. masterdom = fdip(srcloxx, per, speed)
  56. int lenloxx = math.floor(masterdom) < 1 ? 1 : math.floor(masterdom)
  57. lenloxx := nz(lenloxx, 1)
  58.  
  59. [supertrendloxx5, directionloxx] = pine_supertrend(srcloxx, multloxx5, adaptloxx ? lenloxx : per)
  60.  
  61. [supertrendloxx3, directionloxx3] = pine_supertrend(srcloxx, multloxx3, adaptloxx ? lenloxx : per)
  62.  
  63. [supertrendloxx2, directionloxx2] = pine_supertrend(srcloxx, multloxx2, adaptloxx ? lenloxx : per)
  64.  
  65. [supertrendloxx1825, directionloxx1825] = pine_supertrend(srcloxx, multloxx1825, adaptloxx ? lenloxx : per)
  66. // loxx_long = directionloxx == -1 and directionloxx[1] == 1
  67. // loxx_short = directionloxx == 1 and directionloxx[1] == -1
  68.  
  69. loxx_long = close > supertrendloxx5
  70. loxx_short = close < supertrendloxx5
  71.  
  72. loxx_long_2 = directionloxx2 == -1 and directionloxx2[1] == 1
  73. loxx_short_2 = directionloxx == 1 and directionloxx[1] == -1
  74.  
  75. loxx_long_3 = directionloxx3 == -1 and directionloxx3[1] == 1
  76. loxx_short_3 = close < supertrendloxx3
  77.  
  78. loxx_long_1_825 = close > supertrendloxx1825
  79. loxx_short_1_825 = close < supertrendloxx1825
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement