Advertisement
xmd79

Trade Duration

Jan 6th, 2024
311
1
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 1 0
  1.  
  2. _ ='
  3. ---------------------------------------------------------
  4. [::::::::::::::::::::::::::] ---
  5. [::::[ Trade Duration ]::::] ---
  6. [::::::::::::::::::::::::::] version: 5 ---
  7. ---------------------------------------------------------
  8. © Indicator_Wizard '
  9. //@version=5
  10.  
  11. indicator("Trade Duration", overlay = true)
  12.  
  13. var label durationLabel = na
  14.  
  15. i_startTime = input.time (timestamp('01 Jan 2040 00:00 +0000'),'   Trade start Time', group = "📈 SettingS", confirm = true)
  16.  
  17.  
  18. duration(start_time, end_time) =>
  19.  
  20. float totalseconds = (end_time - start_time) / 1000
  21.  
  22. year_ = 3.154e+7
  23. month_ = 2.628e+6
  24. week_ = 604800
  25. day_ = 86400
  26. hour_ = 3600
  27. minute_ = 60
  28.  
  29. result = ""
  30.  
  31. // Calculate years
  32. float years_out = math.floor(totalseconds / year_)
  33. if years_out != 0
  34. result := str.format("{0} years", years_out)
  35.  
  36. // Update totalseconds for the remaining time after calculating years
  37. totalseconds -= years_out * year_
  38.  
  39. // Calculate months
  40. months_out = math.floor(totalseconds / month_)
  41. if months_out != 0
  42. result := str.format("{0} {1} months", result, months_out)
  43.  
  44. // Update totalseconds for the remaining time after calculating months
  45. totalseconds -= months_out * month_
  46.  
  47. // Calculate weeks
  48. weeks_out = math.floor(totalseconds / week_)
  49. if weeks_out != 0
  50. result := str.format("{0} {1} weeks", result, weeks_out)
  51.  
  52. // Update totalseconds for the remaining time after calculating weeks
  53. totalseconds -= weeks_out * week_
  54.  
  55. // Calculate days
  56. days_out = math.floor(totalseconds / day_)
  57. if days_out != 0
  58. result := str.format("{0} {1} days", result, days_out)
  59.  
  60. // Update totalseconds for the remaining time after calculating days
  61. totalseconds -= days_out * day_
  62.  
  63. // Calculate hours
  64. hours_out = math.floor(totalseconds / hour_)
  65. if hours_out != 0
  66. result := str.format("{0} {1} hours", result, hours_out)
  67.  
  68. // Update totalseconds for the remaining time after calculating hours
  69. totalseconds -= hours_out * hour_
  70.  
  71. // Calculate minutes
  72. minutes_out = math.floor(totalseconds / minute_)
  73. if minutes_out != 0
  74. result := str.format("{0} {1} minutes", result, minutes_out)
  75.  
  76. // Update totalseconds for the remaining time after calculating minutes
  77. totalseconds -= minutes_out * minute_
  78.  
  79. // Calculate seconds
  80. seconds_out = totalseconds
  81. if seconds_out != 0
  82. result := str.format("{0} {1} seconds", result, math.round(seconds_out))
  83.  
  84. result
  85.  
  86. if barstate.islast
  87. result = duration(i_startTime,timenow)
  88. durationLabel := label.new(
  89. bar_index, high, text = result, color = color.teal, textcolor = color.white,
  90. style = label.style_label_lower_right, size = size.large)
  91.  
  92. label.delete(durationLabel[1])
  93.  
Advertisement
Comments
  • # text 0.12 KB | 0 0
    1. download all types of premium tradingview indicators codes available on telegram - https://t.me/tradingview_premium_indicator
Add Comment
Please, Sign In to add comment
Advertisement