xmd79

Furious Pivots

Oct 8th, 2021
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.76 KB | None | 0 0
  1. //@version=4
  2. study("Furious Pivots", overlay=true, max_bars_back=1500, max_lines_count=500)
  3.  
  4. linecolor = input(title="Line color", defval = color.gray,inline="q",group="Round Numbers")
  5. linestyle = input(title="Line style", defval = line.style_dashed, options=[line.style_solid, line.style_dotted, line.style_dashed],inline="q",group="Round Numbers")
  6. linewidth = input(title="Line width", defval = 1, minval=1, maxval=4,inline="q",group="Round Numbers")
  7.  
  8. var number_of_lines_above = input(5, title="No of lines above", type=input.integer,inline="p",group="Round Numbers")
  9. var number_of_lines_below = input(5, title="No of lines below", type=input.integer,inline="p",group="Round Numbers")
  10.  
  11. var no_of_pips_between = 100 //input(100, title="No of pips in between", type=input.integer)
  12.  
  13. showPW = input(false,title="Show previous weekly high/low",inline="x",group="Pivots")
  14. PWColor = input(color.new(color.black,0),title="",inline="x",group="Pivots")
  15.  
  16. showPD = input(false,title="Show previous daily high/low",inline="y",group="Pivots")
  17. PDColor = input(color.new(color.black,0),title="",inline="y",group="Pivots")
  18.  
  19. lineWidth = input(1,title="Line width",minval=1,group="Pivots")
  20.  
  21. int DailyOpenTime = na, float DailyOpenPrice = na
  22. checkDO = time(timeframe.period, "1900-1901" + ":1234567")
  23. isDailyOpen = not na(checkDO)
  24.  
  25. DailyOpenTime := isDailyOpen ? time : nz(DailyOpenTime[1])
  26. DailyOpenPrice := isDailyOpen ? open : nz(DailyOpenPrice[1])
  27.  
  28. int weeklyOpenTime = na, float weeklyOpenPrice = na
  29. checkWO = time(timeframe.period, "1900-1901" + ":1")
  30. isWeeklyOpen = not na(checkWO)
  31.  
  32. weeklyOpenTime := isWeeklyOpen ? time : nz(weeklyOpenTime[1])
  33. weeklyOpenPrice := isWeeklyOpen ? open : nz(weeklyOpenPrice[1])
  34.  
  35. dailyOpenTime = DailyOpenTime //security(syminfo.tickerid,"D",time,lookahead=barmerge.lookahead_on)
  36. dailyOpenPrice = DailyOpenPrice //security(syminfo.tickerid,"D",open,lookahead=barmerge.lookahead_on)
  37. dailyCloseTime = (dailyOpenTime + 86400000)
  38.  
  39. prevDailyOpenTime = security(syminfo.tickerid,"D",time[1],lookahead=barmerge.lookahead_on)
  40. prevDayCloseTime = security(syminfo.tickerid,"D",time,lookahead=barmerge.lookahead_on)
  41.  
  42. prevDailyHighPrice = security(syminfo.tickerid,"D",high[1],lookahead=barmerge.lookahead_on)
  43. prevDailyLowPrice = security(syminfo.tickerid,"D",low[1],lookahead=barmerge.lookahead_on)
  44.  
  45. monthlyOpenTime = security(syminfo.tickerid,"M",time,lookahead=barmerge.lookahead_on)
  46. monthlyOpenPrice = security(syminfo.tickerid,"M",open,lookahead=barmerge.lookahead_on)
  47.  
  48. prevWeeklyOpenTime = security(syminfo.tickerid,"W",time[1],lookahead=barmerge.lookahead_on)
  49. prevWeeklyHighPrice = security(syminfo.tickerid,"W",high[1],lookahead=barmerge.lookahead_on)
  50. prevWeeklyLowPrice = security(syminfo.tickerid,"W",low[1],lookahead=barmerge.lookahead_on)
  51.  
  52. if barstate.islast
  53. if showPD
  54. prevDhLine = line.new(prevDailyOpenTime,prevDailyHighPrice,(prevDayCloseTime),prevDailyHighPrice,xloc=xloc.bar_time,color=PDColor,width=lineWidth)
  55. line.delete(prevDhLine[1])
  56. prevDlLine = line.new(prevDailyOpenTime,prevDailyLowPrice,(prevDayCloseTime),prevDailyLowPrice,xloc=xloc.bar_time,color=PDColor,width=lineWidth)
  57. line.delete(prevDlLine[1])
  58.  
  59. prevDhLabel = label.new(prevDayCloseTime,prevDailyHighPrice,"D High",xloc=xloc.bar_time,color=color.new(color.black,100),textcolor=PDColor,style=label.style_label_left)
  60. label.delete(prevDhLabel[1])
  61. prevDlLabel = label.new(prevDayCloseTime,prevDailyLowPrice,"D Low",xloc=xloc.bar_time,color=color.new(color.black,100),textcolor=PDColor,style=label.style_label_left)
  62. label.delete(prevDlLabel[1])
  63.  
  64. //Prev Week
  65. if showPW
  66. prevWhLine = line.new(prevWeeklyOpenTime,prevWeeklyHighPrice,(prevWeeklyOpenTime+518400000),prevWeeklyHighPrice,xloc=xloc.bar_time,color=PWColor,width=lineWidth)
  67. line.delete(prevWhLine[1])
  68. prevWlLine = line.new(prevWeeklyOpenTime,prevWeeklyLowPrice,(prevWeeklyOpenTime+518400000),prevWeeklyLowPrice,xloc=xloc.bar_time,color=PWColor,width=lineWidth)
  69. line.delete(prevWlLine[1])
  70.  
  71. prevWhLabel = label.new((prevWeeklyOpenTime+518400000),prevWeeklyHighPrice,"W High",xloc=xloc.bar_time,color=color.new(color.black,100),textcolor=PWColor,style=label.style_label_left)
  72. label.delete(prevWhLabel[1])
  73. prevWlLabel = label.new((prevWeeklyOpenTime+518400000),prevWeeklyLowPrice,"W Low",xloc=xloc.bar_time,color=color.new(color.black,100),textcolor=PWColor,style=label.style_label_left)
  74. label.delete(prevWlLabel[1])
  75.  
  76. var step_0 = syminfo.mintick*no_of_pips_between*2.5
  77. if barstate.islast and syminfo.type == 'forex'
  78. for counter = 0 to number_of_lines_above - 1
  79. stepUp = ceil(close / step_0) * step_0 + (counter * step_0)
  80. line.new(bar_index, stepUp, bar_index - 1, stepUp, xloc=xloc.bar_index, extend=extend.both, color=linecolor, width=linewidth, style=linestyle)
  81. for counter = 0 to number_of_lines_below - 1
  82. stepDown = floor(close / step_0) * step_0 - (counter * step_0)
  83. line.new(bar_index, stepDown, bar_index - 1, stepDown, xloc=xloc.bar_index, extend=extend.both, color=linecolor, width=linewidth, style=linestyle)
  84.  
  85. var step_1 = syminfo.ticker == 'XAUUSD' ? syminfo.mintick*no_of_pips_between*1 : syminfo.ticker == 'GOLD' ? syminfo.mintick*no_of_pips_between*1 : na
  86. if barstate.islast and (syminfo.ticker == 'XAUUSD' or syminfo.ticker == 'GOLD')
  87. //label.new(bar_index, low, text=syminfo.type, yloc=yloc.abovebar)
  88. for counter = 0 to number_of_lines_above - 1
  89. stepUp = ceil(close / step_1) * step_1 + (counter * step_1)
  90. line.new(bar_index, stepUp, bar_index - 1, stepUp, xloc=xloc.bar_index, extend=extend.both, color=linecolor, width=linewidth, style=linestyle)
  91. for counter = 0 to number_of_lines_below - 1
  92. stepDown = floor(close / step_1) * step_1 - (counter * step_1)
  93. line.new(bar_index, stepDown, bar_index - 1, stepDown, xloc=xloc.bar_index, extend=extend.both, color=linecolor, width=linewidth, style=linestyle)
  94.  
  95. var step_2 = syminfo.ticker == 'BTCUSD' ? syminfo.mintick*no_of_pips_between*500 : syminfo.ticker == 'BTCUSDT' ? syminfo.mintick*no_of_pips_between*500 : na
  96. if barstate.islast and (syminfo.ticker == 'BTCUSD' or syminfo.ticker == 'BTCUSDT')
  97. for counter = 0 to number_of_lines_above - 1
  98. stepUp = ceil(close / step_2) * step_2 + (counter * step_2)
  99. line.new(bar_index, stepUp, bar_index - 1, stepUp, xloc=xloc.bar_index, extend=extend.both, color=linecolor, width=linewidth, style=linestyle)
  100. for counter = 0 to number_of_lines_below - 1
  101. stepDown = floor(close / step_2) * step_2 - (counter * step_2)
  102. line.new(bar_index, stepDown, bar_index - 1, stepDown, xloc=xloc.bar_index, extend=extend.both, color=linecolor, width=linewidth, style=linestyle)
  103.  
  104. var step_3 = syminfo.ticker == 'NAS100USD' ? syminfo.mintick*no_of_pips_between*1 : na
  105. if barstate.islast and syminfo.ticker == 'NAS100USD'
  106. for counter = 0 to number_of_lines_above - 1
  107. stepUp = ceil(close / step_3) * step_3 + (counter * step_3)
  108. line.new(bar_index, stepUp, bar_index - 1, stepUp, xloc=xloc.bar_index, extend=extend.both, color=linecolor, width=linewidth, style=linestyle)
  109. for counter = 0 to number_of_lines_below - 1
  110. stepDown = floor(close / step_3) * step_3 - (counter * step_3)
  111. line.new(bar_index, stepDown, bar_index - 1, stepDown, xloc=xloc.bar_index, extend=extend.both, color=linecolor, width=linewidth, style=linestyle)
  112.  
  113. var step_4 = syminfo.ticker == 'US30' ? syminfo.mintick*no_of_pips_between*0.5 : na
  114. if barstate.islast and syminfo.ticker == 'US30'
  115. for counter = 0 to number_of_lines_above - 1
  116. stepUp = ceil(close / step_4) * step_4 + (counter * step_4)
  117. line.new(bar_index, stepUp, bar_index - 1, stepUp, xloc=xloc.bar_index, extend=extend.both, color=linecolor, width=linewidth, style=linestyle)
  118. for counter = 0 to number_of_lines_below - 1
  119. stepDown = floor(close / step_4) * step_4 - (counter * step_4)
  120. line.new(bar_index, stepDown, bar_index - 1, stepDown, xloc=xloc.bar_index, extend=extend.both, color=linecolor, width=linewidth, style=linestyle)
  121.  
  122. var step_5 = syminfo.ticker == 'XRPUSDT' ? syminfo.mintick*no_of_pips_between*1 : na
  123. if barstate.islast and syminfo.ticker == 'XRPUSDT'
  124. for counter = 0 to number_of_lines_above - 1
  125. stepUp = ceil(close / step_5) * step_5 + (counter * step_5)
  126. line.new(bar_index, stepUp, bar_index - 1, stepUp, xloc=xloc.bar_index, extend=extend.both, color=linecolor, width=linewidth, style=linestyle)
  127. for counter = 0 to number_of_lines_below - 1
  128. stepDown = floor(close / step_5) * step_5 - (counter * step_5)
  129. line.new(bar_index, stepDown, bar_index - 1, stepDown, xloc=xloc.bar_index, extend=extend.both, color=linecolor, width=linewidth, style=linestyle)
  130.  
  131.  
  132.  
Advertisement
Add Comment
Please, Sign In to add comment