Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _ ='
- ---------------------------------------------------------
- [::::::::::::::::::::::::::] ---
- [::::[ Trade Duration ]::::] ---
- [::::::::::::::::::::::::::] version: 5 ---
- ---------------------------------------------------------
- © Indicator_Wizard '
- //@version=5
- indicator("Trade Duration", overlay = true)
- var label durationLabel = na
- i_startTime = input.time (timestamp('01 Jan 2040 00:00 +0000'),' Trade start Time', group = "📈 SettingS", confirm = true)
- duration(start_time, end_time) =>
- float totalseconds = (end_time - start_time) / 1000
- year_ = 3.154e+7
- month_ = 2.628e+6
- week_ = 604800
- day_ = 86400
- hour_ = 3600
- minute_ = 60
- result = ""
- // Calculate years
- float years_out = math.floor(totalseconds / year_)
- if years_out != 0
- result := str.format("{0} years", years_out)
- // Update totalseconds for the remaining time after calculating years
- totalseconds -= years_out * year_
- // Calculate months
- months_out = math.floor(totalseconds / month_)
- if months_out != 0
- result := str.format("{0} {1} months", result, months_out)
- // Update totalseconds for the remaining time after calculating months
- totalseconds -= months_out * month_
- // Calculate weeks
- weeks_out = math.floor(totalseconds / week_)
- if weeks_out != 0
- result := str.format("{0} {1} weeks", result, weeks_out)
- // Update totalseconds for the remaining time after calculating weeks
- totalseconds -= weeks_out * week_
- // Calculate days
- days_out = math.floor(totalseconds / day_)
- if days_out != 0
- result := str.format("{0} {1} days", result, days_out)
- // Update totalseconds for the remaining time after calculating days
- totalseconds -= days_out * day_
- // Calculate hours
- hours_out = math.floor(totalseconds / hour_)
- if hours_out != 0
- result := str.format("{0} {1} hours", result, hours_out)
- // Update totalseconds for the remaining time after calculating hours
- totalseconds -= hours_out * hour_
- // Calculate minutes
- minutes_out = math.floor(totalseconds / minute_)
- if minutes_out != 0
- result := str.format("{0} {1} minutes", result, minutes_out)
- // Update totalseconds for the remaining time after calculating minutes
- totalseconds -= minutes_out * minute_
- // Calculate seconds
- seconds_out = totalseconds
- if seconds_out != 0
- result := str.format("{0} {1} seconds", result, math.round(seconds_out))
- result
- if barstate.islast
- result = duration(i_startTime,timenow)
- durationLabel := label.new(
- bar_index, high, text = result, color = color.teal, textcolor = color.white,
- style = label.style_label_lower_right, size = size.large)
- label.delete(durationLabel[1])
Advertisement
Comments
-
- 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