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
United States
United Kingdom
India
Deutschland
España
France
Việt Nam
Italia
Polska
Brasil
Россия
Türkiye
Indonesia
Malaysia
日本
한국
简体
繁體
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 Support Priority Support Report Issue Ideas Published Followers Following Private Messages Chat Sign Out