pequet

Candle Thief 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/candle-thief
// MIT License
//@version=2
//
// Candle Thief
// Each notch is a missing candle from the chart.  
//

study("Candle Thief v1.0 (TradingView Anomalies)", shorttitle="Candle Thief 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 long ago was the previous candle compared to normal (only anomalies are shown)
srcTLMU = OneBarTime(0) / OnePeriod() - 1
plot(not na(time[1]) and nz(srcTLMU)!=0 ? srcTLMU : na, color=red, style=histogram, transp=0, title="Missing candles")

// alerts
alertcondition(not na(time[1]) and nz(srcTLMU)!=0, title='Candle Thief!', message='A new bar is missing from the chart.')

// 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