xmd79

Pivot Point Oscillator by Algotrdr with custom input

Nov 17th, 2021
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.35 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. // © algotrdr_
  3.  
  4. //@version=5
  5.  
  6. indicator('Pivot Point Oscillator by Algotrdr', shorttitle='Pivot Point Oscillator by Algotrdr')
  7.  
  8. Length = input.int(20, minval=1)
  9. pivchoice = input.string(title='Pivot Timeframe', defval='Daily', options=['Daily', 'Weekly', 'Monthly', 'Quarterly', 'Yearly'])
  10.  
  11. inp = input(close)
  12.  
  13. f_secureSecurity(_symbol, _res, _src) =>
  14. request.security(_symbol, _res, _src[1], lookahead=barmerge.lookahead_on)
  15. lastclose = pivchoice == 'Daily' ? f_secureSecurity(syminfo.tickerid, 'D', inp) : pivchoice == 'Weekly' ? f_secureSecurity(syminfo.tickerid, 'W', inp) : pivchoice == 'Monthly' ? f_secureSecurity(syminfo.tickerid, 'M', inp) : pivchoice == 'Yearly' ? f_secureSecurity(syminfo.tickerid, '12M', inp) : pivchoice == 'Quarterly' ? f_secureSecurity(syminfo.tickerid, '3M', inp) : na
  16. lastopen = pivchoice == 'Daily' ? f_secureSecurity(syminfo.tickerid, 'D', open) : pivchoice == 'Weekly' ? f_secureSecurity(syminfo.tickerid, 'W', open) : pivchoice == 'Monthly' ? f_secureSecurity(syminfo.tickerid, 'M', open) : pivchoice == 'Yearly' ? f_secureSecurity(syminfo.tickerid, '12M', open) : pivchoice == 'Quarterly' ? f_secureSecurity(syminfo.tickerid, '3M', open) : na
  17. lasthigh = pivchoice == 'Daily' ? f_secureSecurity(syminfo.tickerid, 'D', high) : pivchoice == 'Weekly' ? f_secureSecurity(syminfo.tickerid, 'W', high) : pivchoice == 'Monthly' ? f_secureSecurity(syminfo.tickerid, 'M', high) : pivchoice == 'Yearly' ? f_secureSecurity(syminfo.tickerid, '12M', high) : pivchoice == 'Quarterly' ? f_secureSecurity(syminfo.tickerid, '3M', high) : na
  18. lastlow = pivchoice == 'Daily' ? f_secureSecurity(syminfo.tickerid, 'D', low) : pivchoice == 'Weekly' ? f_secureSecurity(syminfo.tickerid, 'W', low) : pivchoice == 'Monthly' ? f_secureSecurity(syminfo.tickerid, 'M', low) : pivchoice == 'Yearly' ? f_secureSecurity(syminfo.tickerid, '12M', low) : pivchoice == 'Quarterly' ? f_secureSecurity(syminfo.tickerid, '3M', low) : na
  19.  
  20. pivbase = (lasthigh + lastlow + lastclose) / 3
  21. HL = lasthigh - lastlow
  22.  
  23. TR5 = pivbase * 4 + lasthigh - 4 * lastlow
  24. TR4 = pivbase * 3 + lasthigh - 3 * lastlow
  25. TR3 = pivbase * 2 + lasthigh - 2 * lastlow
  26. TR2 = pivbase + 1 * (lasthigh - lastlow)
  27. TR1 = pivbase * 2 - lastlow
  28. TS1 = pivbase * 2 - lasthigh
  29. TS2 = pivbase - 1 * (lasthigh - lastlow)
  30. TS3 = pivbase * 2 - (2 * lasthigh - lastlow)
  31. TS4 = pivbase * 3 - (3 * lasthigh - lastlow)
  32. TS5 = pivbase * 4 - (4 * lasthigh - lastlow)
  33.  
  34. R5 = pivbase + HL * 2.618
  35. R4 = pivbase + HL * 1.618
  36. R3 = pivbase + HL * 1.000
  37. R2 = pivbase + HL * 0.618
  38. R1 = pivbase + HL * 0.382
  39. S1 = pivbase - HL * 0.382
  40. S2 = pivbase - HL * 0.618
  41. S3 = pivbase - HL * 1.000
  42. S4 = pivbase - HL * 1.618
  43. S5 = pivbase - HL * 2.618
  44.  
  45. woodiebase = (lasthigh + lastlow + lastopen * 2) / 4
  46.  
  47. WR3 = lasthigh + 2 * (woodiebase - lastlow)
  48. WR2 = woodiebase + 1 * HL
  49. WR1 = woodiebase * 2 - lastlow
  50. WS1 = woodiebase * 2 - lasthigh
  51. WS2 = woodiebase - 1 * HL
  52. WS3 = lastlow - 2 * (lasthigh - woodiebase)
  53. WS4 = WS3 - HL
  54. WR4 = WR3 + HL
  55.  
  56. longmoments = open < R1 and inp > R1 or open < R2 and inp > R2 or open < R3 and inp > R3 or open < R4 and inp > R4 or open < R5 and inp > R5 or open < pivbase and inp > pivbase or open < S1 and inp > S1 or open < S2 and inp > S2 or open < S3 and inp > S3 or open < S4 and inp > S4 or open < S5 and inp > S5
  57. shortmoments = open > R1 and inp < R1 or open > R2 and inp < R2 or open > R3 and inp < R3 or open > R4 and inp < R4 or open > R5 and inp < R5 or open > pivbase and inp < pivbase or open > S1 and inp < S1 or open > S2 and inp < S2 or open > S3 and inp < S3 or open > S4 and inp < S4 or open > S5 and inp < S5
  58.  
  59. Tlongmoments = open < TR1 and inp > TR1 or open < TR2 and inp > TR2 or open < TR3 and inp > TR3 or open < TR4 and inp > TR4 or open < TR5 and inp > TR5 or open < pivbase and inp > pivbase or open < TS1 and inp > TS1 or open < TS2 and inp > TS2 or open < TS3 and inp > TS3 or open < TS4 and inp > TS4 or open < TS5 and inp > TS5
  60. Tshortmoments = open > TR1 and inp < TR1 or open > TR2 and inp < TR2 or open > TR3 and inp < TR3 or open > TR4 and inp < TR4 or open > TR5 and inp < TR5 or open > pivbase and inp < pivbase or open > TS1 and inp < TS1 or open > TS2 and inp < TS2 or open > TS3 and inp < TS3 or open > TS4 and inp < TS4 or open > TS5 and inp < TS5
  61.  
  62. Wlongmoments = open < WR1 and inp > WR1 or open < WR2 and inp > WR2 or open < WR3 and inp > WR3 or open < pivbase and inp > pivbase or open < WS1 and inp > WS1 or open < WS2 and inp > WS2 or open < WS3 and inp > WS3
  63. Wshortmoments = open > WR1 and inp < WR1 or open > WR2 and inp < WR2 or open > WR3 and inp < WR3 or open > pivbase and inp < pivbase or open > WS1 and inp < WS1 or open > WS2 and inp < WS2 or open > WS3 and inp < WS3
  64.  
  65. float FL = 0.0
  66. FL := longmoments ? 1 : 0
  67. float FS = 0.0
  68. FS := shortmoments ? 1 : 0
  69.  
  70. float TL = 0.0
  71. TL := Tlongmoments ? 1 : 0
  72. float TS = 0.0
  73. TS := Tshortmoments ? 1 : 0
  74.  
  75. float WL = 0.0
  76. WL := Wlongmoments ? 1 : 0
  77. float WS = 0.0
  78. WS := Wshortmoments ? 1 : 0
  79.  
  80. x = FL + TL + WL
  81. x2 = FS + TS + WS
  82. ema = ta.ema(math.sum(x, Length), Length) - ta.ema(math.sum(x2, Length), Length)
  83.  
  84. hline(0)
  85.  
  86. colorset = ema >= 0 and ema > ema[1] ? #388e3c : ema >= 0 and ema < ema[1] ? #a5d6a7 : ema < 0 and ema < ema[1] ? #d32f2f : ema < 0 and ema > ema[1] ? #ef9a9a : na
  87.  
  88. plot(ema, style=plot.style_columns, color=colorset)
  89.  
  90.  
  91.  
Advertisement
Add Comment
Please, Sign In to add comment