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
United States
United Kingdom
India
Deutschland
France
España
Italia
Polska
Türkiye
Россия
Brasil
Indonesia
Malaysia
Việt Nam
日本
한국
简体
繁體
Home Stock Screener Forex Signal Finder Cryptocurrency Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators Website & Broker Solutions Widgets Stock Charting Library Feature Request Blog & News FAQ Help & Wiki Twitter
Profile Profile Settings Account and Billing My Support Tickets Priority Support Contact Support Ideas Published Followers Following Private Messages Chat Sign Out