Indicator · Pine Script v5 · On the chart

Economic Calendar [DojiEmoji]

by kevinhhl· code credited to DojiEmoji

This indicator plots scheduled macroeconomic calendar events directly onto the price chart using vertical lines.

View on GitHub

GitHub stars4on the repository
Pine versionv5runs as is
Lines of code162
Settings29inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago6 Oct 2023

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

162 lines of Pine Script v5 from Scripts/Economic Calendar.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Economic Calendar.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DojiEmoji


//@version=5
indicator("Economic Calendar [DojiEmoji]", overlay=true, max_lines_count=500, max_labels_count=500)

// Obtain source data:
//   ie. Step 1: By obtaining from: https://www.fxstreet.com/economic-calendar
//       Step 2: Using external tools (ie Excel, Python, etc.) to create a line of text that resembles 
//               calendar events.
// 

// This script uses the following standardized format:
//
//     Format = <timezone>;<date1>;<date2>; ... etc, up to the last event on <date_n>
//               Where: 'date' is expressed as: YYYY,MM,DD,hh,mm,ss
//

// -----------------------
// Settings:
// -----------------------
// {
var bool show_table = input.bool(true, title="Show table displaying legend for colors")
var string str_table_position = input.string(position.bottom_right, options=[position.bottom_right, position.top_right, position.bottom_left], title="Location of table")
var color bgcolor_table = input.color(color.new(color.black,90), title="Background", inline="ln1")
var string font_size = input.string(size.small, inline="ln1", title="Font size", options=[size.tiny, size.small, size.normal, size.large, size.huge])

var string GROUP_CAT1    = "--------------- Category 1 ---------------"
var string name_cat1     = input.string("Fed", title="", inline="ln1", group=GROUP_CAT1)
var bool show_cat_1      = input.bool(true, title="Show category:", inline="ln1", group=GROUP_CAT1)
var color linecolor_cat1 = input.color(color.new(color.red,50), title="", inline="ln2", group=GROUP_CAT1)
var string str_input_1   = input.text_area(title="Source Data, Category 1:", group=GROUP_CAT1, 
 tooltip="Pasted From external tools (ie. Spreadsheet). A template has been provided in the blog post associated with this script).",
 defval="GMT;2022,9,8,13,10,0;2022,9,21,18,0,0;2022,9,21,18,0,0;2022,9,21,18,0,0;2022,9,21,18,30,0;2022,9,23,18,0,0;2022,9,27,11,30,0;2022,9,28,14,15,0;2022,10,12,18,0,0;2022,11,2,18,0,0;2022,11,2,18,0,0;2022,11,2,18,30,0;2022,11,23,19,0,0;2022,11,30,18,30,0;2022,12,14,19,0,0;2022,12,14,19,0,0;2022,12,14,19,0,0;2022,12,14,19,30,0;2023,1,4,19,0,0;2023,1,10,14,0,0;2023,2,1,19,0,0;2023,2,1,19,0,0;2023,2,1,19,30,0;2023,2,7,17,40,0;2023,2,15,19,0,0;2023,3,22,18,0,0;2023,3,22,18,0,0;2023,3,22,18,0,0;2023,3,22,18,30,0;2023,4,5,18,0,0;2023,5,3,18,0,0;2023,5,3,18,0,0;2023,5,3,18,30,0;2023,5,24,18,0,0;2023,6,14,18,0,0;2023,6,14,18,0,0;2023,6,14,18,0,0;2023,6,14,18,30,0;2023,7,5,18,0,0;2023,7,26,18,0,0;2023,7,26,18,0,0;2023,7,26,18,30,0;2023,8,16,18,0,0;")
var int linewidth_cat1   = input.int(2, title="Width", minval=1, maxval=5, inline="ln2", group=GROUP_CAT1)

var string GROUP_CAT2    = "--------------- Category 2 ---------------"
var string name_cat2     = input.string("PMI", title="", inline="ln1", group=GROUP_CAT2)
var bool show_cat_2      = input.bool(true, title="Show category:", inline="ln1", group=GROUP_CAT2)
var color linecolor_cat2 = input.color(color.new(color.blue,50), title="", inline="ln2", group=GROUP_CAT2)
var string str_input_2   = input.text_area(title="Source Data, Category 2:", group=GROUP_CAT2, 
 tooltip="Pasted From external tools (ie. Spreadsheet). A template has been provided in the blog post associated with this script).", 
 defval="GMT;2022,9,1,14,0,0;2022,9,6,14,0,0;2022,10,3,14,0,0;2022,10,5,14,0,0;2022,11,1,14,0,0;2022,11,3,14,0,0;2022,12,1,15,0,0;2022,12,5,15,0,0;2023,1,4,15,0,0;2023,1,6,15,0,0;2023,2,1,15,0,0;2023,2,3,15,0,0;2023,3,1,15,0,0;2023,3,3,15,0,0;2023,4,3,14,0,0;2023,4,5,14,0,0;2023,5,1,14,0,0;2023,5,3,14,0,0;2023,6,1,14,0,0;2023,6,5,14,0,0;2023,7,3,14,0,0;2023,7,5,14,0,0;2023,8,1,14,0,0;2023,8,3,14,0,0;")
var int linewidth_cat2   = input.int(2, title="Width", minval=1, maxval=5, inline="ln2", group=GROUP_CAT2)

var string GROUP_CAT3    = "--------------- Category 3 ---------------"
var string name_cat3     = input.string("Retail Sales", title="", inline="ln1", group=GROUP_CAT3)
var bool show_cat_3      = input.bool(true, title="Show category:", inline="ln1", group=GROUP_CAT3)
var color linecolor_cat3 = input.color(color.new(color.orange,50), title="", inline="ln2", group=GROUP_CAT3)
var string str_input_3   = input.text_area(title="Source Data, Category 3:", group=GROUP_CAT3, 
 tooltip="Pasted From external tools (ie. Spreadsheet). A template has been provided in the blog post associated with this script).", 
 defval="GMT;2022,9,15,12,30,0;2022,9,15,12,30,0;2022,10,14,12,30,0;2022,10,14,12,30,0;2022,11,16,13,30,0;2022,11,16,13,30,0;2022,12,15,13,30,0;2022,12,15,13,30,0;2023,1,18,13,30,0;2023,1,18,13,30,0;2023,2,15,13,30,0;2023,2,15,13,30,0;2023,3,15,12,30,0;2023,3,15,12,30,0;2023,4,14,12,30,0;2023,4,14,12,30,0;2023,5,16,12,30,0;2023,5,16,12,30,0;2023,6,15,12,30,0;2023,6,15,12,30,0;2023,7,18,12,30,0;2023,7,18,12,30,0;2023,8,15,12,30,0;2023,8,15,12,30,0;")
var int linewidth_cat3   = input.int(2, title="Width", minval=1, maxval=5, inline="ln2", group=GROUP_CAT3)

var string GROUP_CAT4    = "--------------- Category 4 ---------------"
var string name_cat4     = input.string("CPI", title="", inline="ln1", group=GROUP_CAT4)
var bool show_cat_4      = input.bool(true, title="Show category:", inline="ln1", group=GROUP_CAT4)
var color linecolor_cat4 = input.color(color.new(color.green,50), title="", inline="ln2", group=GROUP_CAT4)
var string str_input_4   = input.text_area(title="Source Data, Category 4:", group=GROUP_CAT4, 
 tooltip="Pasted From external tools (ie. Spreadsheet). A template has been provided in the blog post associated with this script).", 
 defval="GMT;2022,9,13,12,30,0;2022,9,13,12,30,0;2022,10,13,12,30,0;2022,10,13,12,30,0;2022,11,10,13,30,0;2022,11,10,13,30,0;2022,12,13,13,30,0;2022,12,13,13,30,0;2023,1,12,13,30,0;2023,1,12,13,30,0;2023,2,14,13,30,0;2023,2,14,13,30,0;2023,3,14,12,30,0;2023,3,14,12,30,0;2023,4,12,12,30,0;2023,4,12,12,30,0;2023,5,10,12,30,0;2023,5,10,12,30,0;2023,6,13,12,30,0;2023,6,13,12,30,0;2023,7,12,12,30,0;2023,7,12,12,30,0;2023,8,10,12,30,0;2023,8,10,12,30,0;")
var int linewidth_cat4   = input.int(2, title="Width", minval=1, maxval=5, inline="ln2", group=GROUP_CAT4)

var string GROUP_CAT5    = "--------------- Category 5 ---------------"
var string name_cat5     = input.string("Others", title="", inline="ln1", group=GROUP_CAT5)
var bool show_cat_5      = input.bool(true, title="Show category:", inline="ln1", group=GROUP_CAT5)
var color linecolor_cat5 = input.color(color.new(color.teal,50), title="", inline="ln2", group=GROUP_CAT5)
var string str_input_5   = input.text_area(title="Source Data, Category 5:", group=GROUP_CAT5, 
 tooltip="Pasted From external tools (ie. Spreadsheet). A template has been provided in the blog post associated with this script).", 
 defval="GMT;2022,9,2,12,30,0;2022,9,16,14,0,0;2022,9,21,18,0,0;2022,9,21,18,0,0;2022,9,21,18,0,0;2022,9,21,18,0,0;2022,9,21,18,0,0;2022,9,27,12,30,0;2022,9,27,12,30,0;2022,9,29,12,30,0;2022,10,5,12,15,0;2022,10,7,12,30,0;2022,10,14,14,0,0;2022,10,27,12,30,0;2022,10,27,12,30,0;2022,10,27,12,30,0;2022,11,2,12,15,0;2022,11,4,12,30,0;2022,11,11,15,0,0;2022,11,23,13,30,0;2022,11,23,13,30,0;2022,11,30,13,15,0;2022,11,30,13,30,0;2022,12,2,13,30,0;2022,12,9,15,0,0;2022,12,14,19,0,0;2022,12,14,19,0,0;2022,12,14,19,0,0;2022,12,14,19,0,0;2022,12,14,19,0,0;2022,12,22,13,30,0;2022,12,23,13,30,0;2022,12,23,13,30,0;2023,1,5,13,15,0;2023,1,6,13,30,0;2023,1,12,13,30,0;2023,1,13,15,0,0;2023,1,26,13,30,0;2023,1,26,13,30,0;2023,1,26,13,30,0;2023,2,1,13,15,0;2023,2,3,13,30,0;2023,2,10,15,0,0;2023,2,23,13,30,0;2023,2,27,13,30,0;2023,2,27,13,30,0;2023,3,1,13,15,0;2023,3,10,13,30,0;2023,3,10,15,0,0;2023,3,22,18,0,0;2023,3,22,18,0,0;2023,3,22,18,0,0;2023,3,22,18,0,0;2023,3,23,12,30,0;2023,3,24,12,30,0;2023,3,24,12,30,0;2023,4,5,12,15,0;2023,4,7,12,30,0;2023,4,14,14,0,0;2023,4,26,12,30,0;2023,4,26,12,30,0;2023,4,27,12,30,0;2023,5,3,12,15,0;2023,5,5,12,30,0;2023,5,12,14,0,0;2023,5,25,12,30,0;2023,5,26,12,30,0;2023,5,26,12,30,0;2023,6,2,12,30,0;2023,6,7,12,15,0;2023,6,9,14,0,0;2023,6,14,18,0,0;2023,6,14,18,0,0;2023,6,14,18,0,0;2023,6,14,18,0,0;2023,6,22,20,30,0;2023,6,27,12,30,0;2023,6,27,12,30,0;2023,6,27,12,30,0;2023,7,5,12,15,0;2023,7,7,12,30,0;2023,7,14,14,0,0;2023,7,27,12,30,0;2023,7,27,12,30,0;2023,7,27,12,30,0;2023,8,2,12,15,0;2023,8,4,12,30,0;2023,8,11,14,0,0;2023,8,24,12,30,0;2023,8,24,12,30,0;2023,8,24,12,30,0;")
var int linewidth_cat5   = input.int(2, title="Width", minval=1, maxval=5, inline="ln2", group=GROUP_CAT5)

// }

// @function : _adjust
//             To adjust for potential timing differences.
//             Original Unix time might cause lines to offset when chart is viewed on other timeframes (ie 12hour).
//
// Thanks to @jdehorty for pointing this out and letting me use his logic for converting.
// https://www.tradingview.com/script/HLYDwa0N-Economic-Calendar-Events-FOMC-CPI-and-more/
_adjust(int t) => 
    switch 
        timeframe.isdaily and timeframe.multiplier > 1 => t - timeframe.multiplier*86400000 // -n days
        timeframe.isweekly => t - timeframe.multiplier*604800000 // -n week(s)
        timeframe.ismonthly => t - timeframe.multiplier*2592000000 // -n month(s)
        timeframe.isminutes and timeframe.multiplier > 60 => t - timeframe.multiplier*60000 // -n minutes
        => t

// @function : get_timestamps 
// @returns array of int : Date of Events in Unix time, sorted.
get_timestamps(string str_input) =>
    
    string[] tokens = str.split(str_input,";")
    string timezone = array.get(tokens, 0)

    int[] return_arr_time = array.new_int()
    for i=1 to array.size(tokens)-1 // start from i=1; First element is reserved for 'timezone'

        string[] subtokens = str.split(array.get(tokens,i), ",")
        if array.size(subtokens) > 0
            // Parse
            int yyyy     = int(str.tonumber(array.get(subtokens, 0)))
            int mmm      = int(str.tonumber(array.get(subtokens, 1)))
            int dd       = int(str.tonumber(array.get(subtokens, 2)))
            int hh       = int(str.tonumber(array.get(subtokens, 3)))
            int mm       = int(str.tonumber(array.get(subtokens, 4)))
            int ss       = int(str.tonumber(array.get(subtokens, 5)))
            // Store
            array.push(return_arr_time, _adjust(timestamp(timezone, yyyy, mmm, dd, hh, mm, ss)))

    array.sort(return_arr_time, order.ascending)
    return_arr_time

var tbl = table.new(str_table_position, 1, 5, frame_color=na, frame_width=0, border_width=0, border_color=na)
put_table(string text_size=size.small, color bgcolor) =>
    table.cell(tbl, 0, 0, name_cat1, text_halign = text.align_left, text_color=linecolor_cat1, bgcolor = bgcolor, text_size = text_size)
    table.cell(tbl, 0, 1, name_cat2, text_halign = text.align_left, text_color=linecolor_cat2, bgcolor = bgcolor, text_size = text_size)
    table.cell(tbl, 0, 2, name_cat3, text_halign = text.align_left, text_color=linecolor_cat3, bgcolor = bgcolor, text_size = text_size)
    table.cell(tbl, 0, 3, name_cat4, text_halign = text.align_left, text_color=linecolor_cat4, bgcolor = bgcolor, text_size = text_size)
    table.cell(tbl, 0, 4, name_cat5, text_halign = text.align_left, text_color=linecolor_cat5, bgcolor = bgcolor, text_size = text_size)

// MAIN:
// {

var bool is_done = false

var string[] name_cat  = array.from(name_cat1,      name_cat2,      name_cat3,      name_cat4,      name_cat5)
var bool[] show_cat    = array.from(show_cat_1,     show_cat_2,     show_cat_3,     show_cat_4,     show_cat_5)
var string[] str_input = array.from(str_input_1,    str_input_2,    str_input_3,    str_input_4,    str_input_5)
var color[] linecolor  = array.from(linecolor_cat1, linecolor_cat2, linecolor_cat3, linecolor_cat4, linecolor_cat5)
var int[] linewidth    = array.from(linewidth_cat1, linewidth_cat2, linewidth_cat3, linewidth_cat4, linewidth_cat5)

if barstate.islast and not is_done

    for i=0 to array.size(name_cat)-1
        
        string _input = array.get(str_input, i)
        _input := str.replace_all(_input, " ", "")
            
        if array.get(show_cat, i) and _input != ""
            if _input == ""
                runtime.error(message = "Source data is empty: " + array.get(name_cat,i ))
            _timestamps = get_timestamps(_input)

            // Assert -> int[] timestamps sorted by chronological order
            
            // Due to PineScript limitations - max. 500 lines on chart
            // We should only show the most recent 
            max_lines = 100     // 100 lines for each category (total = 5 categories)

            _n = array.size(_timestamps)
            _lncol = array.get(linecolor, i) 
            _lnwidth = array.get(linewidth, i)
            for j=math.max(0, _n - max_lines) to _n-1
                t = array.get(_timestamps, j)
                line.new(t, close, t, close*1.0001, xloc.bar_time, extend.both, _lncol, width=_lnwidth)

    if show_table
        put_table(font_size, bgcolor_table)
    is_done := true
// }

Overview

Economic Calendar [DojiEmoji] categorizes events into five user-defined groups, such as central bank meetings, PMI releases, retail sales, inflation data, and other announcements. Each category parses formatted timestamp strings imported from external sources and provides individual controls for visibility, line colors, and line widths. An on-chart table displays an optional color-coded legend. The script relies on manually inputted timestamp strings and is subject to Pine Script line limits.

Details

Published by

kevinhhl on GitHub

Code credit

DojiEmoji, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Sessions & time

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Show table displaying legend for colorsbooltrueshow_table
Location of tablestringposition.bottom_rightstr_table_position
Backgroundcolorcolor.new(color.black,90)bgcolor_table
Font sizestringsize.smallfont_size
name_cat1stringFedname_cat1
Show category:booltrueshow_cat_1
linecolor_cat1colorcolor.new(color.red,50)linecolor_cat1
Source Data, Category 1:textGMT;2022,9,8,13,10,0;2022,9,21,18,0,0;2022,9,21,18,0,0;2022,str_input_1
Widthint2linewidth_cat1
name_cat2stringPMIname_cat2
Show category:booltrueshow_cat_2
linecolor_cat2colorcolor.new(color.blue,50)linecolor_cat2
Show all 29 settings
SettingTypeDefaultVariable
Source Data, Category 2:textGMT;2022,9,1,14,0,0;2022,9,6,14,0,0;2022,10,3,14,0,0;2022,10str_input_2
Widthint2linewidth_cat2
name_cat3stringRetail Salesname_cat3
Show category:booltrueshow_cat_3
linecolor_cat3colorcolor.new(color.orange,50)linecolor_cat3
Source Data, Category 3:textGMT;2022,9,15,12,30,0;2022,9,15,12,30,0;2022,10,14,12,30,0;2str_input_3
Widthint2linewidth_cat3
name_cat4stringCPIname_cat4
Show category:booltrueshow_cat_4
linecolor_cat4colorcolor.new(color.green,50)linecolor_cat4
Source Data, Category 4:textGMT;2022,9,13,12,30,0;2022,9,13,12,30,0;2022,10,13,12,30,0;2str_input_4
Widthint2linewidth_cat4
name_cat5stringOthersname_cat5
Show category:booltrueshow_cat_5
linecolor_cat5colorcolor.new(color.teal,50)linecolor_cat5
Source Data, Category 5:textGMT;2022,9,2,12,30,0;2022,9,16,14,0,0;2022,9,21,18,0,0;2022,str_input_5
Widthint2linewidth_cat5
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

948 stars

This indicator counts down to a fixed Litecoin halving timestamp in August 2019, using Greenwich Mean Time. It subtracts the current time from that stamp and formats the remaining days, hours, minutes, and seconds. The day, hour, and minute of the target are u

Indicator v4 Sessions & time
Updated 10 days ago · GPL-3.0 GitHub repository of Litecoin Halving UTC Countdown
575 stars

This indicator builds Market Profile Time Price Opportunity (TPO) structures across defined session timeframes directly on the main price chart. It visualizes the Point of Control (POC) and Value Area boundaries using dynamic box drawings. An integrated multi-

Indicator v5 Support & resistanceScreeners & dashboards
Updated 1 year ago · MPL-2.0 GitHub repository of Market Profile with Screener

This indicator identifies and plots key options expiration dates on the price chart. It calculates monthly OpEx (the third Friday of each month), quarterly OpEx (March, June, September, December), and corresponding VIX expiration dates, drawing vertical lines

Indicator v6 Sessions & time
Updated 2 months ago · MIT GitHub repository of Expiration Highlights: Opex, Quarterly Opex & VIX with Vanna/Charm
257 stars

This indicator plots auto trade signals for E-mini S&P 500 futures on the price chart. It computes an EMA200 filter along with day ETH RTH session levels and percentage-based entry zones. Signals trigger CALL or PUT cases when price crosses defined thresholds

Indicator v6 TrendSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of Auto Trade Futures ES
219 stars

This indicator plots reference levels for previous daily high and low prices directly on the price chart. It requests daily timeframe data using the security function and plots the offset values as continuous lines, displaying resistance in red and support in

Indicator v4 Support & resistanceSessions & time
Updated 5 years ago · None stated GitHub repository of 昨日高低點標示

Golden Bullet Strategy

by TradersPost
218 stars

The Golden Bullet Strategy is an overlay signal indicator based on Smart Money Concepts and time-based liquidity models. It identifies liquidity sweeps of a designated reference session range during a specified hunt window. It then confirms Market Structure Sh

Indicator v6 SMC / ICT / price actionSessions & time
Updated 3 months ago · None stated GitHub repository of Golden Bullet Strategy

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers