xmd79

Pi - Intraday High-Low Predictor

May 20th, 2023
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.94 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. // Β© Keanu_ritz
  3. //@version=5
  4. //==================================================================================================================================================================================================================//
  5. indicator("Pi - Intraday High-Low Predictor", overlay=true)
  6. //==================================================================================================================================================================================================================//
  7.  
  8. //===========================π’¦π‘’π’Άπ“ƒπ“Š_𝑅𝒾𝒯𝓏 Pi - Intraday High-Low Predictor Code Start - Keanu_RiTz{===========================//
  9.  
  10. // ---- Table Settings Start {----//
  11.  
  12. ShowpTable = input(title="Show Pi predicted High/Low Levels in a Table", defval=true , group="Pi - Intraday High-Low Predictor")
  13. max = 120 //Maximum Length
  14. min = 10 //Minimum Length
  15. dash_loc = input.session("Top Right","Table Location" ,options=["Top Right","Bottom Right","Top Left","Bottom Left", "Middle Right","Bottom Center"] , group="Pi - Intraday High-Low Predictor")
  16. text_size = input.session('Normal',"Table Size" ,options=["Tiny","Small","Normal","Large"] , group="Pi - Intraday High-Low Predictor")
  17. bg_col = input.color(color.new(color.blue,90),"Table Background Color", group="Pi - Intraday High-Low Predictor")
  18. txt_col = input.color(color.new(color.white,45),"Table Text Color", group="Pi - Intraday High-Low Predictor")
  19.  
  20. // ---- Table Settings End ----}//
  21.  
  22. showDH = input(true, title='Show Predicted-High from Day-Low', group='Pi - Intraday High-Low Predictor')
  23. showDL = input(true, title='Show Predicted-Low from Day-High', group='Pi - Intraday High-Low Predictor')
  24. ORtf = input.session(title = "Opening Range period", defval='5', options= ['5','10','15','30','45','60','75','90','120','240'], group='Pi - Intraday High-Low Predictor')
  25. showHDHLR = input(true, title='Show Historical Predicted High-Low Range', group='Pi - Intraday High-Low Predictor')
  26. FillsHL = input(true, title='Fill Small range Predicted High-Low', group='Pi - Intraday High-Low Predictor')
  27. FilllHL = input(true, title='Fill Range Predicted High-Low', group='Pi - Intraday High-Low Predictor')
  28. FillLHL = input(true, title='Fill Large range Predicted High-Low', group='Pi - Intraday High-Low Predictor')
  29. HlvlColor = input.color(color.new(#78fa04,45),"Color for High Levels", group="Pi - Intraday High-Low Predictor")
  30. LlvlColor = input.color(color.new(#fa2f04,45),"Color for Low Levels", group="Pi - Intraday High-Low Predictor")
  31. HHlvlColor = input.color(color.new(#78fa04,75),"Color for Historical High Levels", group="Pi - Intraday High-Low Predictor")
  32. HLlvlColor = input.color(color.new(#fa2f04,75),"Color for Historical Low Levels", group="Pi - Intraday High-Low Predictor")
  33. HTxtColor = input.color(color.new(#78fa04,35),"Color for High Levels Text", group="Pi - Intraday High-Low Predictor")
  34. LTxtColor = input.color(color.new(#fa2f04,35),"Color for Low Levels Text", group="Pi - Intraday High-Low Predictor")
  35. phlline_style = input.string("Dotted", options=["Dotted", "Dashed" , "Solid"], title="Line Style", group="Pi - Intraday High-Low Predictor")
  36. phllabel_size = input.string("small", options=["auto", "tiny", "small", "normal", "large", "huge"], title="Label size", group="Pi - Intraday High-Low Predictor")
  37. phll_size = phllabel_size == "auto" ? size.auto : phllabel_size == "tiny" ? size.tiny : phllabel_size == "small" ? size.small : phllabel_size == "normal" ? size.normal : phllabel_size == "large" ? size.large : size.huge
  38. phlposition_labels = input.string("Left", "Labels Position", options=["Left", "Right"], group="Pi - Intraday High-Low Predictor")
  39. [Dopen, Dclose] = request.security(syminfo.tickerid, 'D', [time, time_close], lookahead=barmerge.lookahead_on)
  40. [dhigh, dlow] = request.security(syminfo.tickerid, 'D', [high, low], lookahead=barmerge.lookahead_on)
  41. var phllstyle = ""
  42. var phll_pos = 0
  43.  
  44. if phlline_style == "Dotted"
  45. phllstyle := line.style_dotted
  46. else if phlline_style == "Dashed"
  47. phllstyle := line.style_dashed
  48. else if phlline_style == "Solid"
  49. phllstyle := line.style_solid
  50.  
  51. if phlposition_labels == "Left"
  52. phll_pos := Dopen
  53. else if phlposition_labels == "Right"
  54. phll_pos := Dclose
  55.  
  56. var float ORHigh = 0.00
  57. var float ORLow = 0.00
  58. var float ORange = 0.00
  59. var float DsRange = 0.00
  60. var float DRange = 0.00
  61. var float DLRange = 0.00
  62. var float DsrHigh = 0.00
  63. var float DrHigh = 0.00
  64. var float DLrHigh = 0.00
  65. var float DsrLow = 0.00
  66. var float DrLow = 0.00
  67. var float DLrLow = 0.00
  68.  
  69. is_Newbar(res) => ta.change(time(res)) != 0
  70. getBarmergeSeries(tickerid,exp, timeFrame) => request.security(tickerid, timeFrame, exp, barmerge.gaps_off, barmerge.lookahead_on)
  71. _High = getBarmergeSeries(syminfo.tickerid, ta.valuewhen(is_Newbar('D'), high, 0), ORtf)
  72. _Low = getBarmergeSeries(syminfo.tickerid, ta.valuewhen(is_Newbar('D'), low, 0), ORtf)
  73. ORHigh := _High
  74. ORLow := _Low
  75. ORange := ORHigh - ORLow
  76. DRange := ORange * 3.14
  77. DsRange := DRange / 2
  78. DLRange := DRange + DsRange
  79. DsrHigh := dlow + DsRange
  80. DrHigh := dlow + DRange
  81. DLrHigh := dlow + DLRange
  82. DsrLow := dhigh - DsRange
  83. DrLow := dhigh - DRange
  84. DLrLow := dhigh - DLRange
  85.  
  86. if showDH and timeframe.isintraday
  87. _piDsrHigh = line.new(Dopen, DsrHigh, Dclose, DsrHigh, xloc.bar_time, color=HlvlColor, style=phllstyle, width=2)
  88. line.delete(_piDsrHigh[1])
  89. l_DsrHigh = label.new(phll_pos, DsrHigh, text="Small Range - High ["+str.tostring(DsrHigh, format.mintick)+"]", xloc=xloc.bar_time, textcolor=HTxtColor, style=label.style_none, size=phll_size)
  90. label.delete(l_DsrHigh[1])
  91. _piDrHigh = line.new(Dopen, DrHigh, Dclose, DrHigh, xloc.bar_time, color=HlvlColor, style=phllstyle, width=2)
  92. line.delete(_piDrHigh[1])
  93. l_DrHigh = label.new(phll_pos, DrHigh, text="Range - High ["+str.tostring(DrHigh, format.mintick)+"]", xloc=xloc.bar_time, textcolor=HTxtColor, style=label.style_none, size=phll_size)
  94. label.delete(l_DrHigh[1])
  95. _piDLrHigh = line.new(Dopen, DLrHigh, Dclose, DLrHigh, xloc.bar_time, color=HlvlColor, style=phllstyle, width=2)
  96. line.delete(_piDLrHigh[1])
  97. l_DLrHigh = label.new(phll_pos, DLrHigh, text="Large Range - High ["+str.tostring(DLrHigh, format.mintick)+"]", xloc=xloc.bar_time, textcolor=HTxtColor, style=label.style_none, size=phll_size)
  98. label.delete(l_DLrHigh[1])
  99.  
  100. if showDL and timeframe.isintraday
  101. _DsrLow = line.new(Dopen, DsrLow, Dclose, DsrLow, xloc.bar_time, color=LlvlColor, style=phllstyle, width=2)
  102. line.delete(_DsrLow[1])
  103. l_DsrLow = label.new(phll_pos, DsrLow, text="Small Range - Low ["+str.tostring(DsrLow, format.mintick)+"]", xloc=xloc.bar_time, textcolor=LTxtColor, style=label.style_none, size=phll_size)
  104. label.delete(l_DsrLow[1])
  105. _DrLow = line.new(Dopen, DrLow, Dclose, DrLow, xloc.bar_time, color=LlvlColor, style=phllstyle, width=2)
  106. line.delete(_DrLow[1])
  107. l_DrLow = label.new(phll_pos, DrLow, text="Range - Low ["+str.tostring(DrLow, format.mintick)+"]", xloc=xloc.bar_time, textcolor=LTxtColor, style=label.style_none, size=phll_size)
  108. label.delete(l_DrLow[1])
  109. _DLrLow = line.new(Dopen, DLrLow, Dclose, DLrLow, xloc.bar_time, color=LlvlColor, style=phllstyle, width=2)
  110. line.delete(_DLrLow[1])
  111. l_DLrLow = label.new(phll_pos, DLrLow, text="Large Range - Low ["+str.tostring(DLrLow, format.mintick)+"]", xloc=xloc.bar_time, textcolor=LTxtColor, style=label.style_none, size=phll_size)
  112. label.delete(l_DLrLow[1])
  113.  
  114. pDsrHigh = plot(showDH and showHDHLR and timeframe.isintraday ? DsrHigh : na, title='Small Range - Predicted High', color=HHlvlColor, style=plot.style_circles, linewidth=1)
  115. pDrHigh = plot(showDH and showHDHLR and timeframe.isintraday ? DrHigh : na, title='Range - Predicted High', color=HHlvlColor, style=plot.style_circles, linewidth=1)
  116. pDLrHigh = plot(showDH and showHDHLR and timeframe.isintraday ? DLrHigh : na, title='Large Range - Predicted High', color=HHlvlColor, style=plot.style_circles, linewidth=1)
  117. pDsrLow = plot(showDL and showHDHLR and timeframe.isintraday ? DsrLow : na, title='Small Range - Predicted Low', color=HLlvlColor, style=plot.style_circles, linewidth=1)
  118. pDrLow = plot(showDL and showHDHLR and timeframe.isintraday ? DrLow : na, title='Range - Predicted Low', color=HLlvlColor, style=plot.style_circles, linewidth=1)
  119. pDLrLow = plot(showDL and showHDHLR and timeframe.isintraday ? DLrLow : na, title='Large Range - Predicted Low', color=HLlvlColor, style=plot.style_circles, linewidth=1)
  120. fill(pDsrHigh, pDsrLow, color=FillsHL ? color.new(color.white,97) : na)
  121. fill(pDrHigh, pDrLow, color=FilllHL ? color.new(color.white,97) : na)
  122. fill(pDLrHigh, pDLrLow, color=FillLHL ? color.new(color.white,97) : na)
  123.  
  124. //-------------- Table code Start {-------------------//
  125.  
  126. //---- Table Position & Size code start {----//
  127. var ptable_position = dash_loc == 'Top Left' ? position.top_left :
  128. dash_loc == 'Bottom Left' ? position.bottom_left :
  129. dash_loc == 'Middle Right' ? position.middle_right :
  130. dash_loc == 'Bottom Center' ? position.bottom_center :
  131. dash_loc == 'Top Right' ? position.top_right : position.bottom_right
  132.  
  133. var ptable_text_size = text_size == 'Tiny' ? size.tiny :
  134. text_size == 'Small' ? size.small :
  135. text_size == 'Normal' ? size.normal : size.large
  136.  
  137. var pt = table.new(ptable_position,14,math.abs(max-min)+2,
  138. frame_color=color.new(#000000,0),
  139. frame_width=1,
  140. border_color=color.new(#000000,0),
  141. border_width=1)
  142. //---- Table Position & Size code end ----}//
  143.  
  144. if ShowpTable and (barstate.islast) and timeframe.isintraday
  145. table.cell(pt,1,0,'Intraday High-Low',text_color=txt_col,text_size=ptable_text_size,bgcolor=bg_col)
  146. table.cell(pt,2,0,'Predictor using Pi',text_color=txt_col,text_size=ptable_text_size,bgcolor=bg_col)
  147. table.cell(pt,1,1,ticker.standard(syminfo.ticker),text_color=txt_col,text_size=ptable_text_size,bgcolor=bg_col)
  148. table.cell(pt,2,1,'Values',text_color=txt_col,text_size=ptable_text_size,bgcolor=bg_col)
  149. table.cell(pt,1,2, "1st "+str.tostring(ORtf)+" Minutes Range",text_color=txt_col,text_size=ptable_text_size,bgcolor=bg_col)
  150. table.cell(pt,2,2, str.tostring(ORange, format.mintick),text_color=txt_col,text_size=ptable_text_size, bgcolor=bg_col)
  151. table.cell(pt,1,3, 'Small range High',text_color=txt_col,text_size=ptable_text_size, bgcolor=bg_col)
  152. table.cell(pt,2,3, str.tostring(DsrHigh, format.mintick),text_color=txt_col,text_size=ptable_text_size, bgcolor=bg_col)
  153. table.cell(pt,1,4, 'Range High',text_color=txt_col,text_size=ptable_text_size, bgcolor=bg_col)
  154. table.cell(pt,2,4, str.tostring(DrHigh, format.mintick),text_color=txt_col,text_size=ptable_text_size, bgcolor=bg_col)
  155. table.cell(pt,1,5, 'Large range High',text_color=txt_col,text_size=ptable_text_size, bgcolor=bg_col)
  156. table.cell(pt,2,5, str.tostring(DLrHigh, format.mintick),text_color=txt_col,text_size=ptable_text_size, bgcolor=bg_col)
  157. table.cell(pt,1,6, 'Small range Low',text_color=txt_col,text_size=ptable_text_size, bgcolor=bg_col)
  158. table.cell(pt,2,6, str.tostring(DsrLow, format.mintick),text_color=txt_col,text_size=ptable_text_size, bgcolor=bg_col)
  159. table.cell(pt,1,7, 'Range Low',text_color=txt_col,text_size=ptable_text_size, bgcolor=bg_col)
  160. table.cell(pt,2,7, str.tostring(DrLow, format.mintick),text_color=txt_col,text_size=ptable_text_size, bgcolor=bg_col)
  161. table.cell(pt,1,8, 'Large range Low',text_color=txt_col,text_size=ptable_text_size, bgcolor=bg_col)
  162. table.cell(pt,2,8, str.tostring(DLrLow, format.mintick),text_color=txt_col,text_size=ptable_text_size, bgcolor=bg_col)
  163.  
  164. //-------------- Table code end -------------------}//
  165.  
  166. //===========================π’¦π‘’π’Άπ“ƒπ“Š_𝑅𝒾𝒯𝓏 Pi - Intraday High-Low Predictor Code End - Keanu_RiTz===========================}//
  167. //==================================================================================================================================================================================================================//
Advertisement
Add Comment
Please, Sign In to add comment