pequet

Day Length Variations v1.0 (TradingView Anomalies)

Remove from Favorite Scripts Add to Favorite Scripts
// Created by @pequet (https://www.tradingview.com/u/pequet) May 30 2016 
// https://github.com/pequet/day-length-variations
// MIT License
//@version=2
//
// Day Length Variations
// Shown here are the variations on a day length and a week length. 
//
// The time variations observed are an effect of the Candle Thief: 
// https://www.tradingview.com/u/pequet/#published-scripts 
//

study("Day Length Variations v1.0 (TradingView Anomalies)", shorttitle="Day Length Variations v1.0")

// functions
OnePeriod() => ismonthly ? 40320*interval  
     : isweekly ? 10080*interval
     : isdaily ? 1440*interval
     : interval
OneBarTime(i) =>
    nz(time[i]-time[i+1])/60000
HowManyActualBarsAgoWas(t) => // t in minutes
    idealBar = OnePeriod()
    totalBars = t / idealBar 
    // countdown
    tLeft = t
    actualBars = 1
    for i = 1 to totalBars
        tLeft := tLeft - ((time[i-1]-time[i])/60000)
        if tLeft > 0
            actualBars := actualBars + 1 
    actualBars

// how many bars ago was 1 day (minutes)  
plot(na(time[60*24/OnePeriod()]) ? na : HowManyActualBarsAgoWas(60*24)/(60*24/OnePeriod()), color=orange, title="Day Length")
// how many bars ago was 1 week (minutes) 
plot(na(time[60*24*7/OnePeriod()]) ? na : HowManyActualBarsAgoWas(60*24*7)/(60*24*7/OnePeriod()), color=yellow, title="Week Length")

// that's it
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out