xmd79

Pivot Point Oscillator by Algotrdr

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