Advertisement
Maurizio-Ciullo

Indicatore Daily-Weekly-Candle-Range-In-Price

Jul 25th, 2022 (edited)
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © Maurizio-Ciullo
  3.  
  4. //@version=5
  5. indicator("Indicatore Daily-Weekly-Candle-Range-In-Price", overlay=true)
  6.  
  7. //Inputs
  8. input_daily_range = input.bool(defval=true)
  9. input_weekly_range = input.bool(defval=false)
  10.  
  11. //Daily sessions and range
  12. dailySessionDataHigh = request.security(syminfo.tickerid,"D", high)
  13. dailySessionDataLow = request.security(syminfo.tickerid,"D", low)
  14. dailyRangeInPrice = dailySessionDataHigh - dailySessionDataLow
  15.  
  16. plot(input_daily_range == true ? dailySessionDataHigh : na, title="weeklySessionDataHigh", color=color.blue)
  17. plot(input_daily_range == true ? dailySessionDataLow : na, title="weeklySessionDataLow", color=color.blue)
  18. plot(input_daily_range == true ? dailyRangeInPrice : na, style=plot.style_histogram, color=color.blue)
  19.  
  20. //Weekly sessions and range
  21. weeklySessionDataHigh = request.security("","W", high)
  22. weeklySessionDataLow = request.security("","W", low)
  23. weeklyRangeInPrice = weeklySessionDataHigh - weeklySessionDataLow
  24.  
  25. plot(input_weekly_range == true ? weeklySessionDataHigh : na, title="weeklySessionDataHigh", color=color.blue)
  26. plot(input_weekly_range == true ? weeklySessionDataLow : na, title="weeklySessionDataLow", color=color.blue)
  27. plot(input_weekly_range == true ? weeklyRangeInPrice : na, style=plot.style_histogram, color=color.blue)
  28.  
  29.  
  30. label_daily_range_text = input_daily_range == true ? str.tostring(dailyRangeInPrice) : na
  31. label_daily_range = input_daily_range == true ? label.new(x=bar_index, y=na, yloc=yloc.belowbar, text=label_daily_range_text, style=label.style_label_lower_left, textcolor=color.white, size=size.normal) : na
  32.  
  33. label_weekly_range_text = input_weekly_range == true ? str.tostring(weeklyRangeInPrice) : na
  34. label_weekly_range = input_weekly_range == true ? label.new(x=bar_index, y=na, yloc=yloc.belowbar, text=label_weekly_range_text, style=label.style_label_down, textcolor=color.white, size=size.normal) : na
  35.  
  36.  
  37. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Code Below For Candle Range And Average LookBack Candles <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //
  38.  
  39. //Input Settings
  40. input_bar_range = input.bool(defval=false, tooltip = "All Label Inputs And Periodo Only Work For input_bar_range")
  41. DistanceBar = input.int(title="/", defval=15, maxval=50, minval=-50, inline="Bar Offset Settings",group="Label Distance from Bar")
  42. sizeOption = input.string("Normal", options = ["Auto", "Huge", "Large", "Normal", "Small", "Tiny"], group="Label Size")
  43. labelSize = (sizeOption == "Huge") ? size.huge :
  44.      (sizeOption == "Large") ? size.large :
  45.      (sizeOption == "Small") ? size.small :
  46.      (sizeOption == "Tiny") ? size.tiny :
  47.      (sizeOption == "Auto") ? size.auto :
  48.          size.normal
  49.  
  50. // Calcolo del range del backtest
  51. startDate = input.int(title="Start Date",
  52.      defval=17, minval=1, maxval=31, group="Periodo")
  53. startMonth = input.int(title="Start Month",
  54.      defval=08, minval=1, maxval=12, group="Periodo")
  55. startYear = input.int(title="Start Year",
  56.      defval=2000, minval=1800, maxval=2100, group="Periodo")
  57.  
  58. endDate = input.int(title="End Date",
  59.      defval=01, minval=1, maxval=31, group="Periodo")
  60. endMonth = input.int(title="End Month",
  61.      defval=01, minval=1, maxval=12, group="Periodo")
  62. endYear = input.int(title="End Year",
  63.      defval=2121, minval=1800, maxval=2150, group="Periodo")
  64.  
  65.  
  66. inDateRange = (time >= timestamp(syminfo.timezone, startYear,
  67.          startMonth, startDate, 0, 0)) and
  68.      (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
  69.  
  70. // Start Hour Range Trading Non Attivo /////////////////////
  71. //hourTrading = input(title='sessione valida di trading', defval='0600-2300:23456')
  72. //hourRangeTrading = time(timeframe.period, hourTrading)
  73.  
  74. //Label Colors
  75. colorLabel = input(title="Label Color", defval=#4169E1, inline="Color Settings",group="Label Colors")
  76. colorText = input(title="Text Color", defval=color.white, inline="Color Settings",group="Label Colors")
  77.  
  78. //Text Only or Label Up or Label Down
  79. labelType = input.string("Label Up", options =["Text Only", "Label Up"], group="Label Style")
  80. labelStyle = (labelType == "Text Only") ? label.style_none : (labelType == "Label Up") ? label.style_label_up : label.style_none
  81.  
  82. // Calculate Bar Difference
  83. inLookBack = input.int(title="lookBack", defval=7, maxval=500, minval=-500, inline="lookBack",group="lookBack")
  84.  
  85. diff = 0.0
  86. diffLookBack = 0.0
  87. if inDateRange
  88.     diff := (high[0] - low[0])
  89.     diffLookBack := math.sum(diff, inLookBack) / inLookBack
  90.  
  91. plot(diffLookBack, title="diffLookBack")
  92.  
  93. // Label to plot Difference
  94. labeltext = input_bar_range == true ? str.tostring(diff): na
  95. label_ = input_bar_range == true ? label.new(bar_index[0], low[0]-DistanceBar, text=labeltext, color=colorLabel, textcolor=colorText, style=labelStyle, size=labelSize) : na
  96.  
  97. // Label to plot High/Low Range Bars LookBack
  98. labeltext2 = input_bar_range == true ? ("range average" + " " + str.tostring(inLookBack ) + " " + "bars" + " " + str.tostring(diffLookBack)) : na
  99.  
  100. if barstate.islast
  101.     label_2 = input_bar_range == true ? label.new(bar_index[0], high[0]+DistanceBar, text=labeltext2, color=colorLabel, textcolor=colorText, style=labelStyle, size=labelSize) : na
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement